Skip to content

Commit 5d585c4

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

File tree

3 files changed

+173
-10
lines changed

3 files changed

+173
-10
lines changed

.github/workflows/Container.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.ref || 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+
VERSION=$(grep "^version = " package/Project.toml | cut -d'"' -f2)
63+
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
65+
- name: Get CUDA major version
66+
id: cuda
67+
run: |
68+
CUDA_MAJOR=$(echo ${{ matrix.cuda }} | cut -d'.' -f1)
69+
echo "major=${CUDA_MAJOR}" >> $GITHUB_OUTPUT
70+
71+
- name: Log in to registry
72+
uses: docker/login-action@v3
73+
with:
74+
registry: ghcr.io
75+
username: ${{ github.actor }}
76+
password: ${{ secrets.GITHUB_TOKEN }}
77+
78+
- name: Extract metadata
79+
id: meta
80+
uses: docker/metadata-action@v5
81+
with:
82+
images: ghcr.io/${{ github.repository }}
83+
tags: |
84+
type=raw,value=${{ steps.pkg.outputs.name }}-julia${{ matrix.julia }}-julia${{ steps.cuda.outputs.major }}
85+
type=raw,value=${{ steps.pkg.outputs.name }},enable=${{ matrix.default == true && (github.ref_type == 'tag' || inputs.tag != '') }}
86+
type=raw,value=latest,enable=${{ matrix.default == true && (github.ref_type == 'tag' || (inputs.tag != '' && inputs.mark_as_latest)) }}
87+
type=raw,value=dev,enable=${{ matrix.default == true && github.ref_type == 'branch' && inputs.tag == '' }}
88+
labels: |
89+
org.opencontainers.image.version=${{ steps.pkg.outputs.version }}
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v3
93+
94+
- name: Build and push image
95+
uses: docker/build-push-action@v6
96+
with:
97+
context: .
98+
push: true
99+
provenance: false # the build fetches the repo again, so provenance tracking is not useful
100+
tags: ${{ steps.meta.outputs.tags }}
101+
labels: ${{ steps.meta.outputs.labels }}
102+
build-args: |
103+
JULIA_VERSION=${{ matrix.julia }}
104+
CUDA_VERSION=${{ matrix.cuda }}
105+
PACKAGE_SPEC=CUDA#${{ steps.pkg.outputs.ref }}

Dockerfile

+59-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,59 @@
11
# example of a Docker container for CUDA.jl with a specific toolkit embedded at run time.
2+
#
3+
# supports selecting a Julia and CUDA toolkit version, as well as baking in specific
4+
# versions of the CUDA.jl package (identified by a spec recorgnized by the Pkg REPL).
5+
#
6+
# CUDA.jl and other packages are shipped in a system depot, with the user depot mounted
7+
# at `/depot`. persistency is possible by mounting a volume at this location.
8+
# running with reduced privileges (by using `--user`) is also supported.
29

3-
FROM julia:1.8-bullseye
10+
ARG JULIA_VERSION=1
11+
FROM julia:${JULIA_VERSION}
12+
13+
ARG CUDA_VERSION=12.6
14+
15+
ARG PACKAGE_SPEC=CUDA
16+
17+
LABEL org.opencontainers.image.authors="Tim Besard <[email protected]>" \
18+
org.opencontainers.image.description="A CUDA.jl container with CUDA ${CUDA_VERSION} and Julia ${JULIA_VERSION}" \
19+
org.opencontainers.image.title="CUDA.jl" \
20+
org.opencontainers.image.url="https://juliagpu.org/cuda/" \
21+
org.opencontainers.image.source="https://github.com/JuliaGPU/CUDA.jl" \
22+
org.opencontainers.image.licenses="MIT"
423

524

625
# system-wide packages
726

27+
# no trailing ':' as to ensure we don't touch anything outside this directory. without it,
28+
# Julia touches the compilecache timestamps in its shipped depot (for some reason; a bug?)
829
ENV JULIA_DEPOT_PATH=/usr/local/share/julia
930

10-
RUN julia -e 'using Pkg; Pkg.add("CUDA")'
31+
# pre-install the CUDA toolkit from an artifact. we do this separately from CUDA.jl so that
32+
# this layer can be cached independently. it also avoids double precompilation of CUDA.jl in
33+
# order to call `CUDA.set_runtime_version!`.
34+
RUN julia -e '#= configure the preference =# \
35+
env = "/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)"; \
36+
mkpath(env); \
37+
write("$env/LocalPreferences.toml", \
38+
"[CUDA_Runtime_jll]\nversion = \"'${CUDA_VERSION}'\""); \
39+
\
40+
#= install the JLL =# \
41+
using Pkg; \
42+
Pkg.add("CUDA_Runtime_jll")' && \
43+
#= demote the JLL to an [extras] dep =# \
44+
find /usr/local/share/julia/environments -name Project.toml -exec sed -i 's/deps/extras/' {} + && \
45+
#= remove nondeterminisms =# \
46+
cd /usr/local/share/julia && \
47+
rm -rf compiled registries scratchspaces logs && \
48+
find -exec touch -h -d "@0" {} + && \
49+
touch -h -d "@0" /usr/local/share
1150

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
15-
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()'
51+
# install CUDA.jl itself
52+
RUN julia -e 'using Pkg; pkg"add '${PACKAGE_SPEC}'"; \
53+
using CUDA; CUDA.precompile_runtime()' && \
54+
#= remove useless stuff =# \
55+
cd /usr/local/share/julia && \
56+
rm -rf registries scratchspaces logs
1957

2058

2159
# user environment
@@ -25,6 +63,17 @@ RUN julia -e 'using CUDA; CUDA.precompile_runtime()'
2563
# case there might not be a (writable) home directory.
2664

2765
RUN mkdir -m 0777 /depot
28-
ENV JULIA_DEPOT_PATH=/depot:/usr/local/share/julia
66+
67+
# we add the user environment from a start-up script
68+
# so that the user can mount `/depot` for persistency
69+
ENV JULIA_DEPOT_PATH=/usr/local/share/julia:
70+
COPY <<EOF /usr/local/share/julia/config/startup.jl
71+
if !isdir("/depot/environments/v$(VERSION.major).$(VERSION.minor)")
72+
mkpath("/depot/environments")
73+
cp("/usr/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)",
74+
"/depot/environments/v$(VERSION.major).$(VERSION.minor)")
75+
end
76+
pushfirst!(DEPOT_PATH, "/depot")
77+
EOF
2978

3079
WORKDIR "/workspace"

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)