|
| 1 | +name: Build decoding-server image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + image_name: |
| 7 | + type: string |
| 8 | + description: GHCR image name, without a tag |
| 9 | + default: ghcr.io/nvidia/private/cudaq-decoders |
| 10 | + required: true |
| 11 | + image_tag: |
| 12 | + type: string |
| 13 | + description: Base tag; defaults to wiring-<run number>, with -cu<version> added |
| 14 | + required: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build decoding-server image (${{ matrix.platform }}, CUDA ${{ matrix.cuda_version }}) |
| 19 | + if: ${{ github.repository == 'NVIDIA/cudaqx' }} |
| 20 | + runs-on: linux-${{ matrix.platform }}-cpu8 |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + platform: [amd64, arm64] |
| 28 | + cuda_version: ['12.6', '13.0'] |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up context for buildx |
| 34 | + run: docker context create builder_context |
| 35 | + |
| 36 | + - name: Set up buildx |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + with: |
| 39 | + endpoint: builder_context |
| 40 | + version: v0.19.0 |
| 41 | + driver-opts: | |
| 42 | + network=host |
| 43 | + image=moby/buildkit:v0.19.0 |
| 44 | +
|
| 45 | + - name: Log in to GitHub CR |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ghcr.io |
| 49 | + username: ${{ github.actor }} |
| 50 | + password: ${{ github.token }} |
| 51 | + |
| 52 | + - name: Build and push image by digest |
| 53 | + id: docker-build |
| 54 | + uses: docker/build-push-action@v5 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + file: docker/decoding-server/Dockerfile |
| 58 | + platforms: linux/${{ matrix.platform }} |
| 59 | + build-args: | |
| 60 | + CUDA_VERSION=${{ matrix.cuda_version }} |
| 61 | + labels: | |
| 62 | + org.opencontainers.image.source=${{ github.repositoryUrl }} |
| 63 | + org.opencontainers.image.revision=${{ github.sha }} |
| 64 | + outputs: type=image,name=${{ inputs.image_name }},push-by-digest=true,name-canonical=true,push=true |
| 65 | + |
| 66 | + - name: Export image digest |
| 67 | + env: |
| 68 | + IMAGE_DIGEST: ${{ steps.docker-build.outputs.digest }} |
| 69 | + run: | |
| 70 | + set -euo pipefail |
| 71 | +
|
| 72 | + mkdir -p /tmp/digests |
| 73 | + touch "/tmp/digests/${IMAGE_DIGEST#sha256:}" |
| 74 | +
|
| 75 | + - name: Upload image digest |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: decoding-server-digest-cu${{ matrix.cuda_version }}-${{ matrix.platform }} |
| 79 | + path: /tmp/digests/* |
| 80 | + if-no-files-found: error |
| 81 | + retention-days: 1 |
| 82 | + |
| 83 | + publish: |
| 84 | + name: Publish decoding-server multi-platform image (CUDA ${{ matrix.cuda_version }}) |
| 85 | + needs: build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + permissions: |
| 88 | + packages: write |
| 89 | + strategy: |
| 90 | + fail-fast: false |
| 91 | + matrix: |
| 92 | + cuda_version: ['12.6', '13.0'] |
| 93 | + steps: |
| 94 | + - name: Set up buildx |
| 95 | + uses: docker/setup-buildx-action@v3 |
| 96 | + |
| 97 | + - name: Log in to GitHub CR |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + registry: ghcr.io |
| 101 | + username: ${{ github.actor }} |
| 102 | + password: ${{ github.token }} |
| 103 | + |
| 104 | + - name: Download image digests |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + path: /tmp/digests |
| 108 | + pattern: decoding-server-digest-cu${{ matrix.cuda_version }}-* |
| 109 | + merge-multiple: true |
| 110 | + |
| 111 | + - name: Create and verify multi-platform image |
| 112 | + env: |
| 113 | + IMAGE_NAME: ${{ inputs.image_name }} |
| 114 | + IMAGE_TAG: ${{ inputs.image_tag || format('wiring-{0}', github.run_number) }} |
| 115 | + CUDA_VERSION: ${{ matrix.cuda_version }} |
| 116 | + run: | |
| 117 | + set -euo pipefail |
| 118 | +
|
| 119 | + cd /tmp/digests |
| 120 | + image_ref="${IMAGE_NAME}:${IMAGE_TAG}-cu${CUDA_VERSION}" |
| 121 | + mapfile -t digests < <(find . -maxdepth 1 -type f -printf '%f\n' | sort) |
| 122 | + if [[ "${#digests[@]}" != 2 ]]; then |
| 123 | + echo "::error::Expected 2 image digests, found ${#digests[@]}" |
| 124 | + exit 1 |
| 125 | + fi |
| 126 | +
|
| 127 | + refs=() |
| 128 | + for digest in "${digests[@]}"; do |
| 129 | + refs+=("${IMAGE_NAME}@sha256:${digest}") |
| 130 | + done |
| 131 | +
|
| 132 | + docker buildx imagetools create --tag "$image_ref" "${refs[@]}" |
| 133 | +
|
| 134 | + manifest=$(docker buildx imagetools inspect --raw "$image_ref") |
| 135 | + for architecture in amd64 arm64; do |
| 136 | + jq -e \ |
| 137 | + --arg architecture "$architecture" \ |
| 138 | + '.manifests[] | select(.platform.os == "linux" and .platform.architecture == $architecture)' \ |
| 139 | + <<< "$manifest" > /dev/null |
| 140 | + done |
| 141 | +
|
| 142 | + docker buildx imagetools inspect "$image_ref" |
0 commit comments