@@ -185,13 +185,26 @@ python_format_string(
185
185
k8s_bundle(
186
186
name="webpages",
187
187
context="kind-kind",
188
- **parametrize("default", sources=("src/k8s:webpages-template@parametrize=web ",)),
188
+ **parametrize("default", sources=("src/k8s:webpages-template@parametrize=default ",)),
189
189
**parametrize("web", sources=("src/k8s:webpages-template@parametrize=web",)),
190
190
)
191
191
` ` `
192
192
193
193
# # Docker images
194
194
195
+ Before we continue, add the docker backend :
196
+
197
+ ` ` ` toml title="pants.toml"
198
+ [GLOBAL]
199
+ backend_packages = [
200
+ ...
201
+ "pants.backend.docker",
202
+ ]
203
+
204
+ [dockerfile-parser]
205
+ use_rust_parser = true
206
+ ` ` `
207
+
195
208
To use docker images you most likely will need some templating. This is because
196
209
your docker image tags will be probably versioned.
197
210
@@ -210,11 +223,60 @@ This script will run before every pants command, so you can now use the
210
223
`VERSION` env var in the BUILD file :
211
224
212
225
` ` ` python title="src/k8s/BUILD"
226
+ ...
213
227
docker_image(
214
- name="nginx",
228
+ name="custom- nginx",
215
229
instructions=["FROM nginx"],
216
230
image_tags=[env("VERSION")],
217
231
)
218
- # TODO
232
+ python_format_string(
233
+ name="webserver-template",
234
+ source="deployment.yaml",
235
+ values={"VERSION": env("VERSION")},
236
+ )
237
+ k8s_bundle(
238
+ name="webserver",
239
+ context="kind-kind",
240
+ sources=("src/k8s:webserver-template",),
241
+ dependencies=(":custom-nginx",),
242
+ )
219
243
` ` `
220
244
245
+ Create the deployment :
246
+
247
+ ` ` ` yaml title="src/k8s/deployment.yaml"
248
+ ---
249
+ apiVersion: apps/v1
250
+ kind: Deployment
251
+ metadata:
252
+ name: webserver
253
+ namespace: web
254
+ spec:
255
+ replicas: 1
256
+ selector:
257
+ matchLabels:
258
+ app: webserver
259
+ template:
260
+ metadata:
261
+ labels:
262
+ app: webserver
263
+ spec:
264
+ containers:
265
+ - name: nginx
266
+ image: custom-nginx:{VERSION}
267
+ ` ` `
268
+
269
+ Now deploy the bundle :
270
+
271
+ ` ` ` bash
272
+ pants experimental-deploy src/k8s:webserver
273
+ ` ` `
274
+
275
+ Notice, that pants will automatically publish the image. This happens because
276
+ we've configured `dependencies=(":custom-nginx",)` field on `k8s_bundle`
277
+ target. You can disable this behaviour and publish the image manually :
278
+
279
+ ` ` ` bash
280
+ pants publish src/k8s:custom-nginx
281
+ pants experimental-deploy --no-publish-dependencies src/k8s:webserver
282
+ ` ` `
0 commit comments