Refactor CUDA build workflow to use repo Containerfile

Replace inline Dockerfile with repo Containerfile and export built
binary via build output instead of docker image copy.
This commit is contained in:
rob thijssen
2025-09-12 09:14:55 +03:00
parent 6e089208ab
commit bfeb0328cd
2 changed files with 14 additions and 60 deletions
+10 -58
View File
@@ -37,76 +37,31 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.cuda_tag }}-sm${{ matrix.sm }}-
- name: Create CI Dockerfile (containerized CUDA build)
run: |
cat > ci.Containerfile <<'DOCKERFILE'
# syntax=docker/dockerfile:1.7
ARG CUDA_TAG=12.9.0
FROM nvidia/cuda:${CUDA_TAG}-devel-ubuntu22.04 AS builder
- name: Use repo Containerfile (no inline Dockerfile)
run: echo "Building with Containerfile at repo root"
ARG SM=86
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl ca-certificates pkg-config build-essential \
libssl-dev git clang cmake && \
rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/opt/rustup \
CARGO_HOME=/opt/cargo \
PATH=/opt/cargo/bin:/usr/local/cuda/bin:${PATH}
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain stable && \
rustc --version && cargo --version
WORKDIR /src
# Build-time selection for device code arch (normalized to compute_XX / sm_XX by build.rs).
ENV CUDA_ARCH=sm_${SM}
# Copy manifests and sources
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
# Build with CUDA feature. Use BuildKit cache mounts to speed repeated builds.
RUN --mount=type=cache,target=/opt/cargo/registry \
--mount=type=cache,target=/src/target \
set -eux; \
echo "CUDA:" && nvcc --version || true; \
echo "Building miner for SM=${SM} (CUDA_ARCH=${CUDA_ARCH})"; \
cargo build -p miner-cli --features cuda --release; \
strip /src/target/release/quantus-miner || true
FROM ubuntu:22.04 AS dist
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /src/target/release/quantus-miner /usr/local/bin/quantus-miner
ENTRYPOINT ["/usr/local/bin/quantus-miner"]
DOCKERFILE
- name: Build miner in container
- name: Build miner image and export dist filesystem
env:
CUDA_TAG: ${{ matrix.cuda_tag }}
SM: ${{ matrix.sm }}
run: |
set -eux
# Build & load the image into the local docker image store
# Build the dist stage and export its filesystem to ./out
docker buildx build \
--progress=plain \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
-t quantus-miner:${CUDA_TAG}-sm${SM} \
--target dist \
--output type=local,dest=./out \
--build-arg CUDA_TAG=${CUDA_TAG} \
--build-arg SM=${SM} \
-f ci.Containerfile .
-f Containerfile .
# Move new cache into place to avoid unbounded growth
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Extract binary from image
- name: Collect binary artifact
id: extract
env:
CUDA_TAG: ${{ matrix.cuda_tag }}
@@ -115,14 +70,11 @@ jobs:
set -eux
# Short CUDA tag (e.g., 12.9 from 12.9.0)
SHORT_TAG="$(echo "${CUDA_TAG}" | sed -E 's/^([0-9]+\.[0-9]+).*/\1/')"
IMG="quantus-miner:${CUDA_TAG}-sm${SM}"
BIN="quantus-miner-cuda-${SHORT_TAG}-sm-${SM}"
cid="$(docker create "${IMG}")"
docker cp "${cid}:/usr/local/bin/quantus-miner" "./${BIN}"
docker rm "${cid}"
# Binary exported by the dist stage is under ./out/usr/local/bin
install -m 0755 ./out/usr/local/bin/quantus-miner "./${BIN}"
chmod +x "./${BIN}"
echo "bin_path=./${BIN}" >> "$GITHUB_OUTPUT"
echo "short_tag=${SHORT_TAG}" >> "$GITHUB_OUTPUT"