diff --git a/.github/actions/disk/action.yml b/.github/actions/disk/action.yml new file mode 100644 index 0000000..580153c --- /dev/null +++ b/.github/actions/disk/action.yml @@ -0,0 +1,15 @@ +--- +name: free disk space +description: when rust compiling, free up some disk space + +runs: + using: composite + steps: + - name: free disk space + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # 1.3.1 + with: + android: true + dotnet: false + haskell: false + large-packages: false + swap-storage: false diff --git a/.github/workflows/cuda-builder.yml b/.github/workflows/cuda-builder.yml new file mode 100644 index 0000000..59f57be --- /dev/null +++ b/.github/workflows/cuda-builder.yml @@ -0,0 +1,77 @@ +name: CUDA Builder + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - Containerfile + +permissions: + contents: read + packages: write + +env: + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/cuda-builder + +jobs: + build-and-push: + name: cuda-builder:${{ matrix.cuda_tag }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + cuda_tag: + - 12.9.0 + - 13.0.0 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - uses: ./.github/actions/disk + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Prepare Buildx cache + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-cuda-builder-${{ matrix.cuda_tag }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-cuda-builder-${{ matrix.cuda_tag }}- + + - name: Log in to GHCR + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and (conditionally) push cuda-builder image + uses: docker/build-push-action@v5 + with: + context: . + file: Containerfile + build-args: | + CUDA_TAG=${{ matrix.cuda_tag }} + pull: true + push: ${{ github.event_name == 'push' }} + tags: | + ${{ env.IMAGE_NAME }}:${{ matrix.cuda_tag }} + labels: | + org.opencontainers.image.source=${{ github.repository }} + org.opencontainers.image.description=Pristine CUDA builder image (CUDA ${{ matrix.cuda_tag }}) + org.opencontainers.image.licenses=Apache-2.0 + org.opencontainers.image.title=cuda-builder + org.opencontainers.image.vendor=Quantus Network + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + provenance: false + + - name: Move Buildx cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..1bd0e62 --- /dev/null +++ b/Containerfile @@ -0,0 +1,37 @@ +# syntax=docker/dockerfile:1.7 + +# Pristine CUDA builder image: +# - Based on NVIDIA CUDA devel (Ubuntu 22.04) +# - Installs toolchain and Rust +# - No source copied, no build performed +# Use this image in CI to mount your workspace and build artifacts. + +ARG CUDA_TAG=12.9.0 +FROM nvcr.io/nvidia/cuda:${CUDA_TAG}-devel-ubuntu22.04 +ARG CUDA_TAG +ENV CUDA_TAG=${CUDA_TAG} + +# System dependencies for building Rust/CUDA projects +RUN apt-get update && \ + 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/* + +# Install Rust (stable, minimal profile) +ENV RUSTUP_HOME=/opt/rustup \ + CARGO_HOME=/opt/cargo \ + CUDA_HOME=/usr/local/cuda \ + CARGO_TERM_COLOR=always \ + 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 + +# Working directory for consumers (CI jobs mount source here) +WORKDIR /workspace + +# Notes: +# - CI should use this image as a base and run cargo build inside the workspace. +# - Optional environment knobs like CUDA_ARCH, MINER_CUDA_ALLOW_UNSUPPORTED_COMPILER, +# MINER_NVCC_CCBIN can be provided at runtime as needed.