Skip to content

Commit bb4c38a

Browse files
EtiennePerotgvisor-bot
authored andcommitted
Container images: Support "template" images and use it for cuda-tests
The `gpu/cuda-tests` and `gpu/cuda-tests-12-8` are duplicates of each other, other than the CUDA version they use. As more CUDA versions are added, this isn't a scalable pattern. This change adds support in the `Makefile` (more specifically `tools/images.mk`) for "image templates" and "image template instances". If an image directory ends in `.tmpl`, it will be ignored from the set of images that the `Makefile` recognizes. Instead, this directory can be used to instantiate other images. For example, given the following filesystem structure: ``` images/ ├─ my-little-image.tmpl/ │ └─ Dockerfile ├─ my-little-image.foo.bar → my-little-image.tmpl (symlink) └─ my-little-image.baz.qux → my-little-image.tmpl (symlink) ``` Then this will effectively create two images, `my-little-image.foo.bar` and `my-little-image.baz.qux`. It will not create a `my-little-image.tmpl` image. The behavior of the template instance images is determined by the `TEMPLATE_VERSION` build argument passed to `my-little-image.tmpl/Dockerfile`. This argument takes on the value of everything after the first `.` character of the last component of the template instance image name. For example, the image `my-little-image.foo.bar` will be built with `docker build --build-arg=TEMPLATE_VERSION=foo.bar`, whereas the `my-little-image.baz.quux` will be built with `docker build --build-arg=TEMPLATE_VERSION=baz.qux`. The `my-little-image.tmpl/Dockerfile` image definition file can use this variable to make the necessary tweaks to distinguish these two images. #codehealth PiperOrigin-RevId: 756101224
1 parent 06acafc commit bb4c38a

25 files changed

+92
-421
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ simple-tests: unit-tests # Compatibility target.
291291
.PHONY: simple-tests
292292

293293
# Images needed for GPU smoke tests.
294-
gpu-smoke-images: load-gpu_cuda-tests load-gpu_cuda-tests-12-8
294+
gpu-smoke-images: load-gpu_cuda-tests.12.2.2 load-gpu_cuda-tests-12.8.1
295295
.PHONY: gpu-smoke-images
296296

297297
gpu-smoke-tests: gpu-smoke-images $(RUNTIME_BIN)
@@ -338,7 +338,7 @@ cos-gpu-all-tests: gpu-images cos-gpu-smoke-tests $(RUNTIME_BIN)
338338
@$(call sudo,test/gpu:sniffer_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
339339
.PHONY: cos-gpu-all-tests
340340

341-
cuda-tests: load-basic_alpine load-gpu_cuda-tests $(RUNTIME_BIN)
341+
cuda-tests: load-basic_alpine load-gpu_cuda-tests.12.2.2 $(RUNTIME_BIN)
342342
@$(call install_runtime,$(RUNTIME),--nvproxy=true --nvproxy-docker=true --nvproxy-allowed-driver-capabilities=all)
343343
@$(call sudo,test/gpu:cuda_test,--runtime=$(RUNTIME) -test.v $(ARGS))
344344
.PHONY: cuda-tests

images/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,65 @@ achieved by specifying `ARCH` variable to make. For example:
6767
```
6868
$ make ARCH=aarch64 rebuild-default
6969
```
70+
71+
## Templated images
72+
73+
If an image directory ends in `.tmpl`, it will be ignored from the set of images
74+
that the `Makefile` recognizes. Instead, this directory can be used to
75+
instantiate other images.
76+
77+
For example, given the following filesystem structure:
78+
79+
```
80+
images/
81+
├─ my-little-image.tmpl/
82+
│ └─ Dockerfile
83+
├─ my-little-image.foo.bar → my-little-image.tmpl (symlink)
84+
├─ my-little-image.baz.qux → my-little-image.tmpl (symlink)
85+
└─ this README.md file
86+
```
87+
88+
Then this will effectively create two images, `my-little-image.foo.bar` and
89+
`my-little-image.baz.qux`. It will not create a `my-little-image.tmpl` image.
90+
91+
The behavior of the template instance images is determined by the
92+
`TEMPLATE_VERSION` build argument passed to `my-little-image.tmpl/Dockerfile`.
93+
This argument takes on the value of everything after the first `.` character of
94+
the last component of the template instance image name. For example, the image
95+
`my-little-image.foo.bar` will be built with `docker build
96+
--build-arg=TEMPLATE_VERSION=foo.bar`, whereas the `my-little-image.baz.quux`
97+
will be built with `docker build --build-arg=TEMPLATE_VERSION=baz.qux`. The
98+
`my-little-image.tmpl/Dockerfile` image definition file can use this variable to
99+
make the necessary tweaks to distinguish these two images.
100+
101+
Note that build arguments do not carry over `FROM` lines in `Dockerfile` unless
102+
specifically passed. For example, this will not work:
103+
104+
```dockerfile
105+
# You should put this line at the top of the file to clearly indicate
106+
# to users that don't use the `Makefile` build system that they are going
107+
# to be building an image that doesn't make sense:
108+
ARG TEMPLATE_VERSION=POPULATED_BY_BUILD_SYSTEM
109+
110+
FROM base-image:${TEMPLATE_VERSION}-alpine
111+
112+
# WRONG: TEMPLATE_VERSION will not be defined here!
113+
# This will try cloning the empty string branch.
114+
RUN git clone https://some-url --branch="${TEMPLATE_VERSION}"
115+
```
116+
117+
This will work:
118+
119+
```dockerfile
120+
ARG TEMPLATE_VERSION=POPULATED_BY_BUILD_SYSTEM
121+
122+
FROM base-image:${TEMPLATE_VERSION}-alpine
123+
124+
# CORRECT: This declares that TEMPLATE_VERSION should be inherited from the
125+
# previous build stage; the lack of value assignment means that its value
126+
# should be carried over as-is.
127+
ARG TEMPLATE_VERSION
128+
129+
# TEMPLATE_VERSION will be defined here.
130+
RUN git clone https://some-url --branch="${TEMPLATE_VERSION}"
131+
```

images/gpu/cuda-tests-12-8/Dockerfile

Lines changed: 0 additions & 49 deletions
This file was deleted.

images/gpu/cuda-tests-12-8/cuda_malloc.cu

Lines changed: 0 additions & 205 deletions
This file was deleted.

images/gpu/cuda-tests-12-8/run_cuda_test.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)