Skip to content

Commit 1114ed9

Browse files
authored
Add CI for publishing container on tagging (#641)
* Add CI for publishing container on tagging * Fixed casing in Dockerfile * Make sure correct version of CUDA installed * Improved Dockerfile * Adding a matrix to container actions
1 parent bc1561d commit 1114ed9

2 files changed

Lines changed: 109 additions & 33 deletions

File tree

.github/workflows/container.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build and Push Container Image
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build-and-push-image:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
strategy:
15+
matrix:
16+
platform: [full, cupy]
17+
mpi: [openmpi, mpich]
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v4
21+
22+
- name: Log in to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract Version from Tag
30+
id: tags
31+
run: echo version=$(echo "${{ github.ref_name }}" | cut -c 2-) >> $GITHUB_OUTPUT
32+
33+
- name: Docker Metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ghcr.io/${{ github.repository }}_${{ matrix.platform }}_${{ matrix.mpi }}
38+
tags: |
39+
type=raw,value=v0.9.0
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Build and Push Image
45+
uses: docker/build-push-action@v6
46+
with:
47+
push: true
48+
context: .
49+
tags: ${{ steps.meta.outputs.tags }}
50+
target: runtime
51+
build-args: |
52+
PLATFORM=${{ matrix.platform}}
53+
MPI=${{ matrix.mpi }}

Dockerfile

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,92 @@ ARG MPI=openmpi
55
ARG PLATFORM=cupy
66

77
# Select CUDA version
8-
ARG CUDAVERSION=12.4
8+
ARG CUDAVERSION=12.8
99

1010
# Pull from mambaforge and install XML and ssh
11-
FROM condaforge/mambaforge as base
11+
FROM condaforge/mambaforge AS base
1212
ENV DEBIAN_FRONTEND=noninteractive
1313
RUN apt-get update && apt-get install -y libxml2 ssh
1414

1515
# Pull from base image and install OpenMPI/MPICH
16-
FROM base as mpi
16+
FROM base AS mpi
1717
ARG MPI
1818
RUN mamba install -n base -c conda-forge ${MPI}
1919

20-
# Pull from MPI build install core dependencies
21-
FROM base as core
22-
COPY ./dependencies_core.yml ./dependencies.yml
23-
RUN mamba env update -n base -f dependencies.yml
20+
# Pull from MPI build and install core dependencies
21+
FROM base AS core
22+
RUN mamba install -n base -y -c conda-forge \
23+
python numpy scipy h5py pip
2424

2525
# Pull from MPI build and install full dependencies
26-
FROM mpi as full
27-
COPY ./dependencies_full.yml ./dependencies.yml
28-
RUN mamba env update -n base -f dependencies.yml
26+
FROM mpi AS full
27+
ARG MPI
28+
RUN mamba install -n base -y -c conda-forge \
29+
python numpy scipy matplotlib h5py \
30+
pyzmq mpi4py[build=*${MPI}*] packaging \
31+
pillow pyfftw pyyaml pip
2932

3033
# Pull from MPI build and install accelerate/pycuda dependencies
31-
FROM mpi as pycuda
32-
ARG CUDAVERSION
33-
COPY ./ptypy/accelerate/cuda_pycuda/dependencies.yml ./dependencies.yml
34-
COPY ./cufft/dependencies.yml ./dependencies_cufft.yml
35-
RUN mamba install cuda-version=${CUDAVERSION} && \
36-
mamba env update -n base -f dependencies.yml && \
37-
mamba env update -n base -f dependencies_cufft.yml
34+
FROM mpi AS pycuda
35+
ARG CUDAVERSION MPI
36+
RUN mamba install -n base -y -c conda-forge -c nvidia \
37+
python numpy scipy matplotlib h5py pyzmq mpi4py[build=*${MPI}*] \
38+
pillow pyfftw pyyaml compilers pip \
39+
reikna pycuda cuda-nvcc cuda-cudart-dev cuda-version=${CUDAVERSION}
3840

3941
# Pull from MPI build and install accelerate/cupy dependencies
40-
FROM mpi as cupy
41-
ARG CUDAVERSION
42-
COPY ./ptypy/accelerate/cuda_cupy/dependencies.yml ./dependencies.yml
43-
COPY ./cufft/dependencies.yml ./dependencies_cufft.yml
44-
RUN mamba install cuda-version=${CUDAVERSION} && \
45-
mamba env update -n base -f dependencies.yml && \
46-
mamba env update -n base -f dependencies_cufft.yml
42+
FROM mpi AS cupy
43+
ARG CUDAVERSION MPI
44+
RUN mamba install -n base -y -c conda-forge \
45+
python numpy scipy matplotlib h5py pyzmq mpi4py[build=*${MPI}*] \
46+
pillow pyfftw pyyaml compilers pip \
47+
cupy cuda-version=${CUDAVERSION}
48+
RUN mamba clean -y -a
4749

4850
# Pull from platform specific image and install ptypy
49-
FROM ${PLATFORM} as build
51+
FROM ${PLATFORM} AS build
5052
COPY pyproject.toml ./
5153
COPY ./templates ./templates
5254
COPY ./benchmark ./benchmark
53-
COPY ./cufft ./cufft
5455
COPY ./ptypy ./ptypy
5556
RUN pip install .
5657

57-
# For core/full build, no post processing needed
58-
FROM build as core-post
59-
FROM build as full-post
58+
# For core build, clean up conda env
59+
FROM build AS core-post
60+
RUN mamba clean -y -a
61+
62+
# For full build, clean up conda env
63+
FROM build AS full-post
64+
RUN mamba clean -y -a
6065

6166
# For pycuda build, install filtered cufft
62-
FROM build as pycuda-post
67+
FROM build AS pycuda-post
68+
ARG CUDAVERSION
69+
RUN mamba install -n base -y -c conda-forge -c nvidia \
70+
python cmake>=3.8.0 pybind11 compilers \
71+
cuda-nvcc cuda-cudart-dev libcufft-dev libcufft-static cuda-version=${CUDAVERSION}
72+
COPY ./cufft ./cufft
6373
RUN pip install ./cufft
74+
RUN mamba remove -n base -y \
75+
cmake pybind11 cuda-nvcc cuda-cudart-dev libcufft-dev libcufft-static
76+
RUN mamba clean -y -a
6477

65-
# For pycuda build, install filtered cufft
66-
FROM build as cupy-post
78+
# For cupy build, install filtered cufft
79+
FROM build AS cupy-post
80+
ARG CUDAVERSION
81+
RUN mamba install -n base -y -c conda-forge -c nvidia \
82+
python cmake>=3.8.0 pybind11 compilers \
83+
cuda-nvcc cuda-cudart-dev libcufft-dev libcufft-static cuda-version=${CUDAVERSION}
84+
COPY ./cufft ./cufft
6785
RUN pip install ./cufft
86+
RUN mamba remove -n base -y \
87+
cmake pybind11 libcufft-dev libcufft-static
88+
RUN mamba clean -y -a
6889

6990
# Platform specific runtime container
70-
FROM ${PLATFORM}-post as runtime
91+
FROM ${PLATFORM}-post AS runtime
92+
RUN useradd --user-group ptypy-user
93+
USER ptypy-user
7194

7295
# Run PtyPy run script as entrypoint
7396
ENTRYPOINT ["ptypy.cli"]

0 commit comments

Comments
 (0)