-
Notifications
You must be signed in to change notification settings - Fork 147
/
Makefile
283 lines (210 loc) · 12.7 KB
/
Makefile
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
PULL_POLICY_NEVER?=--pull-policy=never
PACK_BUILD_FLAGS?=--trust-builder
PACK_CMD?=pack
clean: clean-linux clean-windows
####################
## Linux
####################
build-linux: build-linux-bases build-linux-packages build-linux-builders build-linux-buildpacks
build-linux-bases: build-base-alpine build-base-noble
build-alpine: build-base-alpine build-builder-alpine build-buildpacks-alpine
build-noble: build-base-noble build-builder-noble build-buildpacks-noble
build-base-alpine:
@echo "> Building 'alpine' base images..."
${PACK_CMD} config experimental true
bash base-images/build.sh alpine
build-base-noble:
@echo "> Building 'noble' base images..."
${PACK_CMD} config experimental true
bash base-images/build.sh noble
build-linux-builders: build-builder-alpine build-builder-noble
build-builder-alpine: build-linux-packages build-sample-root
@echo "> Building 'alpine' builder..."
$(PACK_CMD) builder create cnbs/sample-builder:alpine --config $(SAMPLES_ROOT)/builders/alpine/builder.toml $(PULL_POLICY_NEVER)
build-builder-noble: build-linux-packages build-sample-root
@echo "> Building 'noble' builder..."
$(PACK_CMD) builder create cnbs/sample-builder:noble --config $(SAMPLES_ROOT)/builders/noble/builder.toml $(PULL_POLICY_NEVER)
build-linux-buildpacks: build-buildpacks-alpine build-buildpacks-noble
build-buildpacks-alpine: build-sample-root
@echo "> Starting local registry to store alpine builder (when builder contains extensions it must exist in a registry so that builds can use --pull-policy=always and we don't want to override the locally built builder)"
docker run -d --rm -p 5000:5000 registry:2
sleep 2
docker tag cnbs/sample-builder:alpine localhost:5000/cnbs/sample-builder:alpine
docker push localhost:5000/cnbs/sample-builder:alpine
@echo "> Creating 'hello-moon' app using 'alpine' builder..."
$(PACK_CMD) build sample-hello-moon-app:alpine -v --builder localhost:5000/cnbs/sample-builder:alpine --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world --buildpack $(SAMPLES_ROOT)/buildpacks/hello-moon --network=host
@echo "> Creating 'hello-processes' app using 'alpine' builder..."
$(PACK_CMD) build sample-hello-processes-app:alpine -v --builder localhost:5000/cnbs/sample-builder:alpine --buildpack $(SAMPLES_ROOT)/buildpacks/hello-processes --network=host
@echo "> Creating 'hello-world' app using 'alpine' builder..."
$(PACK_CMD) build sample-hello-world-app:alpine -v --builder localhost:5000/cnbs/sample-builder:alpine --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world --network=host
@echo "> Creating 'java-maven' app using 'alpine' builder..."
$(PACK_CMD) build sample-java-maven-app:alpine -v --builder localhost:5000/cnbs/sample-builder:alpine --path apps/java-maven --network=host
@echo "> Creating 'kotlin-gradle' app using 'alpine' builder..."
$(PACK_CMD) build sample-kotlin-gradle-app:alpine -v --builder localhost:5000/cnbs/sample-builder:alpine --path apps/kotlin-gradle --network=host
build-buildpacks-noble: build-sample-root
@echo "> Creating 'hello-moon' app using 'noble' builder..."
$(PACK_CMD) build sample-hello-moon-app:noble -v --builder cnbs/sample-builder:noble --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world --buildpack $(SAMPLES_ROOT)/buildpacks/hello-moon $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'hello-processes' app using 'noble' builder..."
$(PACK_CMD) build sample-hello-processes-app:noble -v --builder cnbs/sample-builder:noble --buildpack $(SAMPLES_ROOT)/buildpacks/hello-processes $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'hello-world' app using 'noble' builder..."
$(PACK_CMD) build sample-hello-world-app:noble -v --builder cnbs/sample-builder:noble --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'java-maven' app using 'noble' builder..."
$(PACK_CMD) build sample-java-maven-app:noble -v --builder cnbs/sample-builder:noble --path apps/java-maven $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'kotlin-gradle' app using 'noble' builder..."
$(PACK_CMD) build sample-kotlin-gradle-app:noble -v --builder cnbs/sample-builder:noble --path apps/kotlin-gradle $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'ruby-bundler' app using 'noble' builder..."
$(PACK_CMD) build sample-ruby-bundler-app:noble -v --builder cnbs/sample-builder:noble --path apps/ruby-bundler $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
build-linux-packages: build-sample-root
@echo "> Creating 'hello-world' buildpack package"
$(PACK_CMD) buildpack package cnbs/sample-package:hello-world --config $(SAMPLES_ROOT)/$(PACKAGES_DIR)/hello-world/package.toml $(PULL_POLICY_NEVER)
@echo "> Creating 'hello-universe' buildpack package"
$(PACK_CMD) buildpack package cnbs/sample-package:hello-universe --config $(SAMPLES_ROOT)/$(PACKAGES_DIR)/hello-universe/package.toml $(PULL_POLICY_NEVER)
deploy-linux: deploy-linux-bases deploy-linux-packages deploy-linux-builders
deploy-linux-bases:
@echo "> Deploying 'alpine' base images..."
docker push cnbs/sample-base:alpine
docker push cnbs/sample-base-run:alpine
docker push cnbs/sample-base-build:alpine
@echo "> Deploying 'noble' base images..."
docker push cnbs/sample-base:noble
docker push cnbs/sample-base-run:noble
docker push cnbs/sample-base-build:noble
deploy-linux-packages:
@echo "> Deploying linux packages..."
docker push cnbs/sample-package:hello-world
docker push cnbs/sample-package:hello-universe
deploy-linux-builders:
@echo "> Deploying 'alpine' builder..."
docker run cnbs/sample-builder:alpine ls /cnb/extensions/samples_curl || true
docker push cnbs/sample-builder:alpine
@echo "> Deploying 'noble' builder..."
docker push cnbs/sample-builder:noble
clean-linux:
@echo "> Removing 'alpine' base images..."
docker rmi cnbs/sample-base:alpine || true
docker rmi cnbs/sample-base-run:alpine || true
docker rmi cnbs/sample-base-build:alpine || true
@echo "> Removing 'noble' base images..."
docker rmi cnbs/sample-base:noble || true
docker rmi cnbs/sample-base-run:noble || true
docker rmi cnbs/sample-base-build:noble || true
@echo "> Removing builders..."
docker rmi cnbs/sample-builder:alpine || true
docker rmi cnbs/sample-builder:noble || true
@echo "> Removing 'alpine' apps..."
docker rmi sample-hello-moon-app:alpine || true
docker rmi sample-hello-processes-app:alpine || true
docker rmi sample-hello-world-app:alpine || true
docker rmi sample-java-maven-app:alpine || true
docker rmi sample-kotlin-gradle-app:alpine || true
@echo "> Removing 'noble' apps..."
docker rmi sample-hello-moon-app:noble || true
docker rmi sample-hello-processes-app:noble || true
docker rmi sample-hello-world-app:noble || true
docker rmi sample-java-maven-app:noble || true
docker rmi sample-kotlin-gradle-app:noble || true
docker rmi sample-ruby-bundler-app:noble || true
@echo "> Removing packages..."
docker rmi cnbs/sample-package:hello-world || true
docker rmi cnbs/sample-package:hello-universe || true
@echo "> Removing '.tmp'"
rm -rf .tmp
set-experimental:
@echo "> Setting experimental"
$(PACK_CMD) config experimental true
####################
## Windows
####################
build-windows-2022: build-windows-packages build-dotnet-framework-2022 build-nanoserver-2022
build-nanoserver-2022: build-base-nanoserver-2022 build-builder-nanoserver-2022 build-buildpacks-nanoserver-2022
build-dotnet-framework-2022: build-base-dotnet-framework-2022 build-builder-dotnet-framework-2022 build-buildpacks-dotnet-framework-2022
build-base-nanoserver-2022:
@echo "> Building 'nanoserver-2022' base images..."
bash base-images/build.sh nanoserver-2022
build-base-dotnet-framework-2022:
@echo "> Building 'dotnet-framework-2022' base images..."
bash base-images/build.sh dotnet-framework-2022
build-builder-nanoserver-2022: build-windows-packages
@echo "> Building 'nanoserver-2022' builder..."
$(PACK_CMD) builder create cnbs/sample-builder:nanoserver-2022 --config $(SAMPLES_ROOT)/builders/nanoserver-2022/builder.toml $(PULL_POLICY_NEVER)
build-builder-dotnet-framework-2022: build-windows-packages
@echo "> Building 'dotnet-framework-2022' builder..."
$(PACK_CMD) builder create cnbs/sample-builder:dotnet-framework-2022 --config $(SAMPLES_ROOT)/builders/dotnet-framework-2022/builder.toml $(PULL_POLICY_NEVER)
build-buildpacks-nanoserver-2022: build-sample-root
@echo "> Creating 'hello-moon-windows' app using 'nanoserver-2022' builder..."
$(PACK_CMD) build sample-hello-moon-windows-app:nanoserver-2022 -v --builder cnbs/sample-builder:nanoserver-2022 --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world-windows --buildpack $(SAMPLES_ROOT)/buildpacks/hello-moon-windows $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
@echo "> Creating 'hello-world-windows' app using 'nanoserver-2022' builder..."
$(PACK_CMD) build sample-hello-world-windows-app:nanoserver-2022 -v --builder cnbs/sample-builder:nanoserver-2022 --buildpack $(SAMPLES_ROOT)/buildpacks/hello-world-windows $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
build-buildpacks-dotnet-framework-2022: build-sample-root
@echo "> Creating 'dotnet-framework' app using 'dotnet-framework-2022' builder..."
$(PACK_CMD) build sample-dotnet-framework-app:dotnet-framework-2022 -v --builder cnbs/sample-builder:dotnet-framework-2022 --buildpack $(SAMPLES_ROOT)/buildpacks/dotnet-framework --path apps/aspnet $(PULL_POLICY_NEVER) $(PACK_BUILD_FLAGS)
build-windows-packages: build-sample-root
@echo "> Creating 'hello-world-windows' buildpack package"
$(PACK_CMD) buildpack package cnbs/sample-package:hello-world-windows --config $(SAMPLES_ROOT)/$(PACKAGES_DIR)/hello-world-windows/package.toml $(PULL_POLICY_NEVER)
@echo "> Creating 'hello-universe-windows' buildpack package"
$(PACK_CMD) buildpack package cnbs/sample-package:hello-universe-windows --config $(SAMPLES_ROOT)/$(PACKAGES_DIR)/hello-universe-windows/package.toml $(PULL_POLICY_NEVER)
deploy-windows-packages:
@echo "> Deploying windows packages..."
docker push cnbs/sample-package:hello-world-windows
docker push cnbs/sample-package:hello-universe-windows
deploy-windows-2022: deploy-windows-bases-2022 deploy-windows-builders-2022
deploy-windows-bases-2022: deploy-windows-bases-dotnet-framework-2022 deploy-windows-bases-nanoserver-2022
deploy-windows-bases-nanoserver-2022:
@echo "> Deploying 'nanoserver-2022' base images..."
docker push cnbs/sample-base:nanoserver-2022
docker push cnbs/sample-base-run:nanoserver-2022
docker push cnbs/sample-base-build:nanoserver-2022
deploy-windows-bases-dotnet-framework-2022:
@echo "> Deploying 'dotnet-framework-2022' base images..."
docker push cnbs/sample-base-run:dotnet-framework-2022
docker push cnbs/sample-base-build:dotnet-framework-2022
deploy-windows-builders-2022: deploy-windows-builders-dotnet-framework-2022 deploy-windows-builders-nanoserver-2022
deploy-windows-builders-nanoserver-2022:
@echo "> Deploying 'nanoserver-2022' builder..."
docker push cnbs/sample-builder:nanoserver-2022
deploy-windows-builders-dotnet-framework-2022:
@echo "> Deploying 'dotnet-framework-2022' builder..."
docker push cnbs/sample-builder:dotnet-framework-2022
clean-windows:
@echo "> Removing 'nanoserver-2022' base images..."
docker rmi cnbs/sample-base:nanoserver-2022 || true
docker rmi cnbs/sample-base-run:nanoserver-2022 || true
docker rmi cnbs/sample-base-build:nanoserver-2022 || true
@echo "> Removing 'dotnet-framework-2022' base images..."
docker rmi cnbs/sample-base-run:dotnet-framework-2022 || true
docker rmi cnbs/sample-base-build:dotnet-framework-2022 || true
@echo "> Removing builders..."
docker rmi cnbs/sample-builder:nanoserver-2022 || true
docker rmi cnbs/sample-builder:dotnet-framework-2022 || true
@echo "> Removing 'nanoserver-2022' apps..."
docker rmi sample-hello-moon-windows-app:nanoserver-2022 || true
docker rmi sample-hello-world-windows-app:nanoserver-2022 || true
docker rmi sample-batch-script-app:nanoserver-2022 || true
@echo "> Removing 'dotnet-framework-2022' apps..."
docker rmi sample-aspnet-app:dotnet-framework-2022 || true
@echo "> Removing packages..."
docker rmi cnbs/sample-package:hello-world-windows || true
docker rmi cnbs/sample-package:hello-universe-windows || true
@echo "> Removing '.tmp'"
rm -rf .tmp
####################
## Windows pack for any daemon OS
####################
# pack on Windows does not support directory-based buildpacks
# workaround by pivoting samples-root to tmp path with tgz-buildpacks of the same name
ifeq ($(OS),Windows_NT)
SAMPLES_ROOT:=$(shell mkdir -p .tmp && mktemp --directory -p . .tmp/samples-XXX)
PACKAGES_DIR:=packages
build-sample-root:
@mkdir -p $(SAMPLES_ROOT)/buildpacks/
@for bp_dir in ./buildpacks/*/; do \
tar -czf $(SAMPLES_ROOT)/buildpacks/$$(basename $$bp_dir) -C $$bp_dir . ; \
done
@cp -r builders $(SAMPLES_ROOT)/
@cp -r buildpacks $(SAMPLES_ROOT)/$(PACKAGES_DIR)
else
# No-op for posix pack
SAMPLES_ROOT:=.
PACKAGES_DIR:=buildpacks
build-sample-root:
endif