Skip to content

Commit

Permalink
Update dev Dockerfile and add GitHub action (NVIDIA#69)
Browse files Browse the repository at this point in the history
This PR adds a manually triggered workflow to publish useful containers
for development and CI/CD. It is anticipated that we will need to
trigger this when we update the CUDA-Q commit. (We may make this
automatic in the future, but it is intentionally just manual for now.)

---------

Signed-off-by: Ben Howe <[email protected]>
  • Loading branch information
bmhowe23 authored Feb 6, 2025
1 parent f4b4a1e commit 2d31c43
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 22 deletions.
179 changes: 179 additions & 0 deletions .github/workflows/build_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: Build dev images

on:
workflow_dispatch:
inputs:
force_rebuild:
type: boolean
required: true
description: 'Force rebuild even if image tags already exist'
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-cudaqx-dev:
name: Build CUDA-QX Dev Image
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
strategy:
matrix:
platform: [amd64, arm64]
fail-fast: false
runs-on: linux-${{ matrix.platform }}-cpu8
steps:
- name: Login to GitHub CR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Get required CUDA-Q version
id: get-cudaq-version
uses: ./.github/actions/get-cudaq-version

- name: Get additional metadata
id: get-cudaq-version-short
run: |
shortref=$(echo "${{ steps.get-cudaq-version.outputs.ref }}" | head -c8)
commit_date=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/${{ steps.get-cudaq-version.outputs.ref }}" | jq -r '.commit.committer.date' | cut -dT -f1)
echo "shortref=$shortref" >> $GITHUB_OUTPUT
echo "commit_date=$commit_date" >> $GITHUB_OUTPUT
- name: Check if image already exists
id: check-image
run: |
IMAGE_TAG="${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}"
CONTAINER_VERSION_METADATA=$(curl -s -L -H "Accept: applicat/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/orgs/NVIDIA/packages/container/cudaqx-dev/versions")
CONTAINER_TAGS=$(echo $CONTAINER_VERSION_METADATA | jq -r '.[] | .metadata.container.tags[]')
if echo "$CONTAINER_TAGS" | grep -qx "$IMAGE_TAG"; then
echo "Image tag $IMAGE_TAG already exists. Skipping build."
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Set up context for buildx
if: ${{ inputs.force_rebuild || steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
run: |
docker context create builder_context
shell: bash --noprofile --norc -euo pipefail {0}

- name: Set up buildx runner
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context
driver-opts: network=host

- name: Build dev image
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
file: ./docker/build_env/cudaqx.dev.Dockerfile
tags: |
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:latest-${{ matrix.platform }}
platforms: linux/${{ matrix.platform }}
push: true

build-cudaqx-pydev:
name: Build CUDA-QX Python Dev Image
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
platform: ['amd64', 'arm64']
fail-fast: false
runs-on: linux-${{ matrix.platform }}-cpu8
steps:
- name: Login to GitHub CR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Get required CUDA-Q version
id: get-cudaq-version
uses: ./.github/actions/get-cudaq-version

- name: Get additional metadata
id: get-cudaq-version-short
run: |
shortref=$(echo "${{ steps.get-cudaq-version.outputs.ref }}" | head -c8)
commit_date=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/${{ steps.get-cudaq-version.outputs.ref }}" | jq -r '.commit.committer.date' | cut -dT -f1)
echo "shortref=$shortref" >> $GITHUB_OUTPUT
echo "commit_date=$commit_date" >> $GITHUB_OUTPUT
- name: Check if image already exists
id: check-image
run: |
IMAGE_TAG="${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}"
CONTAINER_VERSION_METADATA=$(curl -s -L -H "Accept: applicat/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/orgs/NVIDIA/packages/container/cudaqx-dev/versions")
CONTAINER_TAGS=$(echo $CONTAINER_VERSION_METADATA | jq -r '.[] | .metadata.container.tags[]')
if echo "$CONTAINER_TAGS" | grep -qx "$IMAGE_TAG"; then
echo "Image tag $IMAGE_TAG already exists. Skipping build."
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Set up context for buildx
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
run: |
docker context create builder_context
shell: bash --noprofile --norc -euo pipefail {0}

- name: Set up buildx runner
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context
driver-opts: network=host

- name: Build pydev image
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
file: ./docker/build_env/cudaqx.wheel.Dockerfile
build-args: |
base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-${{ matrix.platform }}-cu12.0-gcc11-main
python_version=${{ matrix.python }}
tags: |
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-py${{ matrix.python }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.shortref }}-py${{ matrix.python }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:latest-py${{ matrix.python }}-${{ matrix.platform }}
platforms: linux/${{ matrix.platform }}
push: true

cleanup:
name: Cleanup
needs: [build-cudaqx-dev, build-cudaqx-pydev]
runs-on: ubuntu-latest
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
steps:
- name: Delete untagged images
uses: actions/delete-package-versions@v5
with:
package-name: cudaqx-dev
package-type: 'container'
min-versions-to-keep: 0
delete-only-untagged-versions: 'true'
22 changes: 0 additions & 22 deletions docker/build_env/Dockerfile

This file was deleted.

34 changes: 34 additions & 0 deletions docker/build_env/cudaqx.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ============================================================================ #
# Copyright (c) 2025 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

FROM ghcr.io/nvidia/cuda-quantum-devdeps:ext-cu12.0-gcc11-main

LABEL org.opencontainers.image.description="Dev tools for building and testing CUDA-QX libraries"
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/cudaqx"
LABEL org.opencontainers.image.title="cuda-qx-dev"
LABEL org.opencontainers.image.url="https://github.com/NVIDIA/cudaqx"

RUN apt-get update && apt-get install -y gfortran libblas-dev jq cuda-nvtx-12-0 \
&& python3 -m pip install cmake --user \
&& apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY .cudaq_version /cudaq_version

RUN mkdir -p /workspaces/cudaq && cd /workspaces/cudaq \
&& git init \
&& CUDAQ_REPO=$(jq -r '.cudaq.repository' /cudaq_version) \
&& CUDAQ_COMMIT=$(jq -r '.cudaq.ref' /cudaq_version) \
&& git remote add origin https://github.com/${CUDAQ_REPO} \
&& git fetch -q --depth=1 origin ${CUDAQ_COMMIT} \
&& git reset --hard FETCH_HEAD \
&& bash scripts/build_cudaq.sh -v \
&& rm -rf build

#RUN mkdir -p /workspaces/cudaqx && cd /workspaces/cudaqx \
# && ~/.local/bin/cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCUDAQ_DIR=~/.cudaq/lib/cmake/cudaq .. \
# && ninja install
32 changes: 32 additions & 0 deletions docker/build_env/cudaqx.wheel.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ============================================================================ #
# Copyright (c) 2025 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

ARG base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-amd64-cu12.0-gcc11-main
FROM ${base_image}

ARG python_version=3.10

LABEL org.opencontainers.image.description="Dev tools for building and testing CUDA-QX libraries"
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/cudaqx"
LABEL org.opencontainers.image.title="cuda-qx-dev"
LABEL org.opencontainers.image.url="https://github.com/NVIDIA/cudaqx"

RUN dnf install -y jq
RUN mkdir -p /workspaces/cudaqx
COPY .cudaq_version /workspaces/cudaqx
COPY .github/workflows/scripts/build_cudaq.sh /workspaces/cudaqx

RUN mkdir -p /workspaces/cudaqx/cudaq && cd /workspaces/cudaqx/cudaq \
&& git init \
&& CUDAQ_REPO=$(jq -r '.cudaq.repository' /workspaces/cudaqx/.cudaq_version) \
&& CUDAQ_COMMIT=$(jq -r '.cudaq.ref' /workspaces/cudaqx/.cudaq_version) \
&& git remote add origin https://github.com/${CUDAQ_REPO} \
&& git fetch -q --depth=1 origin ${CUDAQ_COMMIT} \
&& git reset --hard FETCH_HEAD \
&& bash ../build_cudaq.sh --python-version ${python_version} \
&& rm -rf build

0 comments on commit 2d31c43

Please sign in to comment.