forked from buildpacks/lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
173 lines (143 loc) · 5.65 KB
/
Makefile
File metadata and controls
173 lines (143 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
GOCMD?=go
GOARCH?=amd64
GOENV=GOARCH=$(GOARCH) CGO_ENABLED=0
LDFLAGS=-s -w
LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.Version=$(LIFECYCLE_VERSION)'
LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.SCMRepository=$(SCM_REPO)'
LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.SCMCommit=$(SCM_COMMIT)'
LDFLAGS+=-X 'github.com/buildpacks/lifecycle/cmd.PlatformAPI=$(PLATFORM_API)'
GOBUILD=go build $(GOFLAGS) -ldflags "$(LDFLAGS)"
GOTEST=$(GOCMD) test $(GOFLAGS)
LIFECYCLE_VERSION?=0.0.0
PLATFORM_API?=0.3
BUILDPACK_API?=0.2
SCM_REPO?=github.com/buildpacks/lifecycle
PARSED_COMMIT:=$(shell git rev-parse --short HEAD)
SCM_COMMIT?=$(PARSED_COMMIT)
BUILD_DIR?=$(PWD)/out
COMPILATION_IMAGE?=golang:1.13-alpine
define LIFECYCLE_DESCRIPTOR
[api]
platform = "$(PLATFORM_API)"
buildpack = "$(BUILDPACK_API)"
[lifecycle]
version = "$(LIFECYCLE_VERSION)"
endef
all: test build package
build: build-linux build-windows
build-linux-lifecycle: export GOOS:=linux
build-linux-lifecycle: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle
build-linux-lifecycle: GOENV:=GOARCH=$(GOARCH) CGO_ENABLED=1
build-linux-lifecycle: DOCKER_RUN=docker run --workdir=/lifecycle -v $(OUT_DIR):/out -v $(PWD):/lifecycle $(COMPILATION_IMAGE)
build-linux-lifecycle:
@echo "> Building lifecycle/lifecycle for linux..."
mkdir -p $(OUT_DIR)
$(DOCKER_RUN) sh -c 'apk add build-base && $(GOENV) $(GOBUILD) -o /out/lifecycle -a ./cmd/lifecycle'
build-linux-launcher: export GOOS:=linux
build-linux-launcher: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle
build-linux-launcher:
@echo "> Building lifecycle/launcher for linux..."
mkdir -p $(OUT_DIR)
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/launcher -a ./cmd/launcher
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 3
build-linux-symlinks: export GOOS:=linux
build-linux-symlinks: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle
build-linux-symlinks:
@echo "> Creating phase symlinks for linux..."
ln -sf lifecycle $(OUT_DIR)/detector
ln -sf lifecycle $(OUT_DIR)/analyzer
ln -sf lifecycle $(OUT_DIR)/restorer
ln -sf lifecycle $(OUT_DIR)/builder
ln -sf lifecycle $(OUT_DIR)/exporter
ln -sf lifecycle $(OUT_DIR)/rebaser
ln -sf lifecycle $(OUT_DIR)/creator
build-linux: build-linux-lifecycle build-linux-symlinks build-linux-launcher
build-windows: export GOOS:=windows
build-windows: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle
build-windows:
@echo "> Building for windows..."
mkdir -p $(OUT_DIR)
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/launcher -a ./cmd/launcher
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 3
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/lifecycle.exe -a ./cmd/lifecycle
ln -sf lifecycle.exe $(OUT_DIR)/analyzer.exe
ln -sf lifecycle.exe $(OUT_DIR)/restorer.exe
ln -sf lifecycle.exe $(OUT_DIR)/builder.exe
ln -sf lifecycle.exe $(OUT_DIR)/exporter.exe
ln -sf lifecycle.exe $(OUT_DIR)/rebaser.exe
ln -sf lifecycle.exe $(OUT_DIR)/creator.exe
build-darwin: export GOOS:=darwin
build-darwin: OUT_DIR:=$(BUILD_DIR)/$(GOOS)/lifecycle
build-darwin:
@echo "> Building for macos..."
mkdir -p $(OUT_DIR)
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/launcher -a ./cmd/launcher
test $$(du -m $(OUT_DIR)/launcher|cut -f 1) -le 3
$(GOENV) $(GOBUILD) -o $(OUT_DIR)/lifecycle -a ./cmd/lifecycle
ln -sf lifecycle $(OUT_DIR)/detector
ln -sf lifecycle $(OUT_DIR)/analyzer
ln -sf lifecycle $(OUT_DIR)/restorer
ln -sf lifecycle $(OUT_DIR)/builder
ln -sf lifecycle $(OUT_DIR)/exporter
ln -sf lifecycle $(OUT_DIR)/rebaser
install-goimports:
@echo "> Installing goimports..."
cd tools; $(GOCMD) install golang.org/x/tools/cmd/goimports
install-yj:
@echo "> Installing yj..."
cd tools; $(GOCMD) install github.com/sclevine/yj
install-mockgen:
@echo "> Installing mockgen..."
cd tools; $(GOCMD) install github.com/golang/mock/mockgen
install-golangci-lint:
@echo "> Installing golangci-lint..."
cd tools; $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint
lint: install-golangci-lint
@echo "> Linting code..."
@golangci-lint run -c golangci.yaml
generate: install-mockgen
@echo "> Generating..."
$(GOCMD) generate
$(GOCMD) generate ./launch
format: install-goimports
@echo "> Formating code..."
test -z $$(goimports -l -w -local github.com/buildpacks/lifecycle .)
verify-jq:
ifeq (, $(shell which jq))
$(error "No jq in $$PATH, please install jq")
endif
test: unit acceptance
unit: verify-jq format lint install-yj
@echo "> Running unit tests..."
$(GOTEST) -v -count=1 ./...
acceptance: format lint
@echo "> Running acceptance tests..."
$(GOTEST) -v -count=1 -tags=acceptance ./acceptance/...
acceptance-darwin: format lint
@echo "> Running acceptance tests..."
$(GOTEST) -v -count=1 -tags=acceptance ./acceptance/...
clean:
@echo "> Cleaning workspace..."
rm -rf $(BUILD_DIR)
package: package-linux package-windows
package-linux: export LIFECYCLE_DESCRIPTOR:=$(LIFECYCLE_DESCRIPTOR)
package-linux: GOOS:=linux
package-linux: GOOS_DIR:=$(BUILD_DIR)/$(GOOS)
package-linux: ARCHIVE_NAME=lifecycle-v$(LIFECYCLE_VERSION)+$(GOOS).x86-64
package-linux:
@echo "> Writing descriptor file for $(GOOS)..."
mkdir -p $(GOOS_DIR)
echo "$${LIFECYCLE_DESCRIPTOR}" > $(GOOS_DIR)/lifecycle.toml
@echo "> Packaging lifecycle for $(GOOS)..."
tar czf $(BUILD_DIR)/$(ARCHIVE_NAME).tgz -C $(GOOS_DIR) lifecycle.toml lifecycle
package-windows: export LIFECYCLE_DESCRIPTOR:=$(LIFECYCLE_DESCRIPTOR)
package-windows: GOOS:=windows
package-windows: GOOS_DIR:=$(BUILD_DIR)/$(GOOS)
package-windows: ARCHIVE_NAME=lifecycle-v$(LIFECYCLE_VERSION)+$(GOOS).x86-64
package-windows:
@echo "> Writing descriptor file for $(GOOS)..."
mkdir -p $(GOOS_DIR)
echo "$${LIFECYCLE_DESCRIPTOR}" > $(GOOS_DIR)/lifecycle.toml
@echo "> Packaging lifecycle for $(GOOS)..."
tar czf $(BUILD_DIR)/$(ARCHIVE_NAME).tgz -C $(GOOS_DIR) lifecycle.toml lifecycle
.PHONY: verify-jq