Skip to content

Commit 6f9bcaa

Browse files
committed
Update Dockerfile and add workflow to register.
[ci skip]
1 parent 830c49b commit 6f9bcaa

File tree

3 files changed

+127
-11
lines changed

3 files changed

+127
-11
lines changed

.github/workflows/Container.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Docker image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'Git ref to build instead'
8+
required: false
9+
default: ''
10+
push:
11+
tags:
12+
- 'v*'
13+
branches:
14+
- master
15+
16+
jobs:
17+
push_to_registry:
18+
name: Build Docker image - Julia ${{ matrix.julia }} - CUDA ${{ matrix.cuda }}
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
strategy:
25+
matrix:
26+
julia: ["1.10", "1.11"]
27+
cuda: ["11.8", "12.6"]
28+
include:
29+
- julia: "1.11"
30+
cuda: "12.6"
31+
default: true
32+
33+
steps:
34+
- name: Check out the repo
35+
uses: actions/checkout@v4
36+
with:
37+
ref: ${{ inputs.ref || github.ref }}
38+
39+
- name: Get package spec
40+
id: pkg
41+
run: |
42+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
43+
echo "ref=${{ github.ref_name }}" >> $GITHUB_OUTPUT
44+
echo "name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
45+
else
46+
echo "ref=${{ github.sha }}" >> $GITHUB_OUTPUT
47+
echo "name=dev" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Log in to GitHub Container Registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Extract metadata (tags, labels)
58+
id: meta
59+
uses: docker/metadata-action@v5
60+
with:
61+
images: ghcr.io/${{ github.repository }}
62+
tags: |
63+
type=raw,value=${{ steps.pkg.outputs.name }}-julia${{ matrix.julia }}-cuda${{ matrix.cuda }}
64+
type=raw,value=latest,enable=${{ matrix.default == true && github.ref_type == 'tag' }}
65+
type=raw,value=dev,enable=${{ matrix.default == true && github.ref_type == 'branch' }}
66+
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: .
71+
push: true
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
build-args: |
75+
JULIA_VERSION=${{ matrix.julia }}
76+
CUDA_VERSION=${{ matrix.cuda }}
77+
PACKAGE_SPEC=CUDA#${{ steps.pkg.outputs.ref }}

Dockerfile

+40-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
11
# example of a Docker container for CUDA.jl with a specific toolkit embedded at run time.
22

3-
FROM julia:1.8-bullseye
3+
ARG JULIA_VERSION=1
4+
FROM julia:${JULIA_VERSION}
45

6+
ARG CUDA_VERSION=12.6
57

6-
# system-wide packages
8+
ARG PACKAGE_SPEC=CUDA
9+
10+
LABEL maintainer="Tim Besard <tim.besard@gmail.com>"
11+
LABEL description="CUDA.jl container with CUDA ${CUDA_VERSION} installed for Julia ${JULIA_VERSION}"
12+
LABEL version="1.0"
713

8-
ENV JULIA_DEPOT_PATH=/usr/local/share/julia
914

10-
RUN julia -e 'using Pkg; Pkg.add("CUDA")'
15+
# system-wide packages
1116

12-
# hard-code a CUDA toolkit version
13-
RUN julia -e 'using CUDA; CUDA.set_runtime_version!(v"12.2")'
14-
# re-importing CUDA.jl below will trigger a download of the relevant artifacts
17+
# no trailing ':' as to ensure we don't touch anything outside this directory. without it,
18+
# Julia touches the compilecache timestamps in its shipped depot (for some reason; a bug?)
19+
ENV JULIA_DEPOT_PATH=/usr/local/share/julia
1520

16-
# generate the device runtime library for all known and supported devices.
17-
# this is to avoid having to do this over and over at run time.
18-
RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
21+
# pre-install the CUDA toolkit from an artifact. we do this separately from CUDA.jl so that
22+
# this layer can be cached independently. it also avoids double precompilation of CUDA.jl in
23+
# order to call `CUDA.set_runtime_version!`.
24+
RUN julia -e '#= configure the preference =# \
25+
env = "/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)"; \
26+
mkpath(env); \
27+
write("$env/LocalPreferences.toml", \
28+
"[CUDA_Runtime_jll]\nversion = \"'${CUDA_VERSION}'\""); \
29+
\
30+
#= install the JLL =# \
31+
using Pkg; \
32+
Pkg.add("CUDA_Runtime_jll")' && \
33+
#= remove nondeterminisms =# \
34+
cd /usr/local/share/julia && \
35+
rm -rf compiled registries scratchspaces logs && \
36+
find -exec touch -h -d "@0" {} + && \
37+
touch -h -d "@0" /usr/local/share
38+
39+
# install CUDA.jl itself
40+
RUN julia -e 'using Pkg; pkg"add '${PACKAGE_SPEC}'"; \
41+
using CUDA; CUDA.precompile_runtime()' && \
42+
#= remove useless stuff =# \
43+
cd /usr/local/share/julia && \
44+
rm -rf registries scratchspaces logs
1945

2046

2147
# user environment
@@ -25,6 +51,9 @@ RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
2551
# case there might not be a (writable) home directory.
2652

2753
RUN mkdir -m 0777 /depot
28-
ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia
54+
ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia:
55+
56+
# make sure the user depot is the one used by default (which requires a valid Project.toml)
57+
RUN cp -ar /usr/local/share/julia/environments /depot
2958

3059
WORKDIR "/workspace"

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ This may take a while, as it will precompile the package and download a suitable
5959
the CUDA toolkit. If your GPU is not fully supported, the above command (or any other
6060
command that initializes the toolkit) will issue a warning.
6161

62+
For quick testing, you can also use the `juliagpu/cuda.jl` container image from the GitHub
63+
Container Registry, which provides Julia, a precompiled version of CUDA.jl, and a matching
64+
CUDA toolkit:
65+
66+
```sh
67+
docker run -it --rm --gpus=all ghcr.io/juliagpu/cuda.jl:latest
68+
# `latest` refers to the latest released version, `nightly` is the current master branch.
69+
# version-qualified names are available too, e.g., `v5.5.2-julia1.11-cuda12.6`
70+
```
71+
6272
For more usage instructions and other information, please refer to [the
6373
documentation](https://juliagpu.github.io/CUDA.jl/stable/).
6474

0 commit comments

Comments
 (0)