Skip to content

Commit 7ec9719

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

File tree

3 files changed

+143
-11
lines changed

3 files changed

+143
-11
lines changed

Diff for: .github/workflows/Container.yml

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

Diff for: Dockerfile

+42-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 <[email protected]>"
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,11 @@ 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+
# TODO: do this with a startup script so that you can mount `/depot` as a volume
58+
# TODO: demote CUDA_Runtime_jll as an [extra] dep so that it doesn't show in the status
59+
RUN cp -ar /usr/local/share/julia/environments /depot
2960

3061
WORKDIR "/workspace"

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ 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
63+
image](https://github.com/JuliaGPU/CUDA.jl/pkgs/container/cuda.jl/versions) from the GitHub
64+
Container Registry, which provides Julia, a precompiled version of CUDA.jl, and a matching
65+
CUDA toolkit:
66+
67+
```sh
68+
docker run -it --rm --gpus=all ghcr.io/juliagpu/cuda.jl:latest # other tags available too
69+
```
70+
6271
For more usage instructions and other information, please refer to [the
6372
documentation](https://juliagpu.github.io/CUDA.jl/stable/).
6473

0 commit comments

Comments
 (0)