|
| 1 | +name: Build and push image with SSH forwarding |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + AWS_ACCESS_KEY_ID: |
| 7 | + required: true |
| 8 | + AWS_SECRET_ACCESS_KEY: |
| 9 | + required: true |
| 10 | + CUMLPRIMS_SSH_PRIVATE_DEPLOY_KEY: |
| 11 | + required: true |
| 12 | + CUGRAPH_OPS_SSH_PRIVATE_DEPLOY_KEY: |
| 13 | + required: true |
| 14 | + inputs: |
| 15 | + file: |
| 16 | + type: string |
| 17 | + required: true |
| 18 | + node-version: |
| 19 | + type: string |
| 20 | + required: true |
| 21 | + push: |
| 22 | + default: true |
| 23 | + type: boolean |
| 24 | + required: false |
| 25 | + pull: |
| 26 | + default: true |
| 27 | + type: boolean |
| 28 | + required: false |
| 29 | + manual-build: |
| 30 | + type: boolean |
| 31 | + required: true |
| 32 | + image: |
| 33 | + default: "" |
| 34 | + type: string |
| 35 | + required: true |
| 36 | + from_: |
| 37 | + default: "" |
| 38 | + type: string |
| 39 | + required: false |
| 40 | + build: |
| 41 | + default: "" |
| 42 | + type: string |
| 43 | + required: false |
| 44 | + devel: |
| 45 | + default: "" |
| 46 | + type: string |
| 47 | + required: false |
| 48 | + build-args: |
| 49 | + default: "" |
| 50 | + type: string |
| 51 | + required: false |
| 52 | + files-to-diff: |
| 53 | + default: "" |
| 54 | + type: string |
| 55 | + required: false |
| 56 | + registry-url: |
| 57 | + type: string |
| 58 | + required: true |
| 59 | + default: ghcr.io |
| 60 | + registry-username: |
| 61 | + type: string |
| 62 | + required: true |
| 63 | + default: ${{ github.repository_owner }} |
| 64 | + registry-password: |
| 65 | + type: string |
| 66 | + required: true |
| 67 | + default: ${{ github.token }} |
| 68 | + |
| 69 | +jobs: |
| 70 | + build-and-publish-image: |
| 71 | + runs-on: [self-hosted, linux, amd64, cpu4] |
| 72 | + strategy: |
| 73 | + fail-fast: true |
| 74 | + matrix: |
| 75 | + CUDA: ["11.6.2"] |
| 76 | + LINUX: ["ubuntu20.04"] |
| 77 | + steps: |
| 78 | + - name: Dump runner context |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + echo "${{ toJSON(runner) }}"; |
| 82 | + echo "is_gha_runner=${{ !contains(runner.name, 'runners-') }}" >> $GITHUB_ENV; |
| 83 | +
|
| 84 | + - name: Set up self-hosted runner |
| 85 | + if: ${{ env.is_gha_runner != 'true' }} |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + sudo apt update && sudo apt install -y --no-install-recommends jq git-lfs |
| 89 | + sudo sed -ri "s@$HOME@${{ runner.workspace }}@g" /etc/passwd |
| 90 | + sudo chown -R $(id -u):$(id -g) "${{ runner.workspace }}" |
| 91 | + echo "HOME=${{ runner.workspace }}" >> $GITHUB_ENV |
| 92 | +
|
| 93 | + - name: Checkout |
| 94 | + uses: actions/checkout@v3 |
| 95 | + with: |
| 96 | + lfs: true |
| 97 | + fetch-depth: 0 |
| 98 | + |
| 99 | + - name: Checkout LFS |
| 100 | + shell: bash |
| 101 | + run: git lfs checkout |
| 102 | + |
| 103 | + - name: Free up disk space |
| 104 | + if: ${{ env.is_gha_runner == 'true' }} |
| 105 | + uses: ./.github/actions/free-disk-space |
| 106 | + with: |
| 107 | + tool_cache: ${{ runner.tool_cache }} |
| 108 | + |
| 109 | + - name: Get last successful main commit sha |
| 110 | + id: last_main_commit |
| 111 | + if: ${{ ! inputs.manual-build }} |
| 112 | + uses: nrwl/last-successful-commit-action@v1 |
| 113 | + with: |
| 114 | + branch: main |
| 115 | + workflow_id: "merge.pr.yml" |
| 116 | + github_token: "${{ github.token }}" |
| 117 | + |
| 118 | + - name: Check if files changed |
| 119 | + id: files_changed |
| 120 | + if: ${{ ! inputs.manual-build }} |
| 121 | + uses: tj-actions/changed-files@v23.1 |
| 122 | + with: |
| 123 | + base_sha: ${{ steps.last_main_commit.outputs.commit_hash }} |
| 124 | + files: | |
| 125 | + ${{ inputs.file }} |
| 126 | + ${{ inputs.files-to-diff }} |
| 127 | + \.github/workflows/merge\.pr\.yml |
| 128 | + \.github/workflows/build-and-push-image\.yml |
| 129 | + \.github/actions/build-and-publish-image-ssh/action\.yml |
| 130 | +
|
| 131 | + - name: Set environment variables |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | +
|
| 135 | + NODE="${{ inputs.node-version }}" |
| 136 | + PARALLEL_LEVEL="${PARALLEL_LEVEL:-4}" |
| 137 | + VERSION="$(cat lerna.json | jq -r '.version')" |
| 138 | + image_type="$(echo "${{ inputs.image }}" | cut -d'-' -f1)" |
| 139 | + image_name="$(echo "${{ inputs.image }}" | cut -d'-' -f2)" |
| 140 | + REPOSITORY="${{ inputs.registry-url }}/${{ github.repository }}" |
| 141 | + CUDA_VERSION_MAJOR="$(echo "${{ matrix.CUDA }}" | cut -d'.' -f1)" |
| 142 | + CUDA_VERSION_MINOR="$(echo "${{ matrix.CUDA }}" | cut -d'.' -f2)" |
| 143 | + CUDA_VERSION_PATCH="$(echo "${{ matrix.CUDA }}" | cut -d'.' -f3)" |
| 144 | + RAPIDS_VERSION="$(cat package.json | jq -r '.config.rapids_version')" |
| 145 | + files_changed="${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }}" |
| 146 | +
|
| 147 | + echo "NODE=$NODE" >> $GITHUB_ENV; |
| 148 | + echo "VERSION=$VERSION" >> $GITHUB_ENV; |
| 149 | + echo "image_type=$image_type >> $GITHUB_ENV; |
| 150 | + echo "image_name=$image_name >> $GITHUB_ENV; |
| 151 | + echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV; |
| 152 | + echo "files_changed=$files_changed" >> $GITHUB_ENV; |
| 153 | + echo "PARALLEL_LEVEL=$PARALLEL_LEVEL" >> $GITHUB_ENV; |
| 154 | + echo "RAPIDS_VERSION=$RAPIDS_VERSION" >> $GITHUB_ENV; |
| 155 | + echo "CUDA_VERSION_MAJOR=$CUDA_VERSION_MAJOR >> $GITHUB_ENV; |
| 156 | + echo "CUDA_VERSION_MINOR=$CUDA_VERSION_MINOR >> $GITHUB_ENV; |
| 157 | + echo "CUDA_VERSION_PATCH=$CUDA_VERSION_PATCH >> $GITHUB_ENV; |
| 158 | +
|
| 159 | + echo "BUILD_ARGS<<EOF" >> $GITHUB_ENV; |
| 160 | +
|
| 161 | + if [[ -n "${{ inputs.build-args }}" ]]; then |
| 162 | + echo -e "${{ inputs.build-args }}" >> $GITHUB_ENV; |
| 163 | + fi |
| 164 | +
|
| 165 | + if [[ "${{ inputs.image }}" == devel-main ]]; then |
| 166 | + echo "ARM64_BASE=nvidia/cuda:${{ matrix.CUDA }}-devel-${{ matrix.LINUX }}" >> $GITHUB_ENV; |
| 167 | + echo "AMD64_BASE=nvidia/cuda:${{ matrix.CUDA }}-devel-${{ matrix.LINUX }}" >> $GITHUB_ENV; |
| 168 | + elif [[ "${{ inputs.image }}" == runtime-base ]]; then |
| 169 | + echo "ARM64_BASE=nvidia/cuda:${{ matrix.CUDA }}-runtime-${{ matrix.LINUX }}" >> $GITHUB_ENV; |
| 170 | + echo "AMD64_BASE=nvidia/cuda:${{ matrix.CUDA }}-runtime-${{ matrix.LINUX }}" >> $GITHUB_ENV; |
| 171 | + fi |
| 172 | +
|
| 173 | + if [[ -n "${{ inputs.from_ }}" ]]; then |
| 174 | + from__type="$(echo "${{ inputs.from_ }}" | cut -d'-' -f1)"; |
| 175 | + from__name="$(echo "${{ inputs.from_ }}" | cut -d'-' -f2)"; |
| 176 | + from_image="${REPOSITORY}:${VERSION}-${from__type}-node${NODE}-cuda${CUDA_VERSION_MAJOR}-${{ matrix.LINUX }}-${from__name}"; |
| 177 | + echo "FROM_IMAGE=${from_image}" >> $GITHUB_ENV; |
| 178 | + fi |
| 179 | +
|
| 180 | + if [[ -n "${{ inputs.build }}" ]]; then |
| 181 | + build_type="$(echo "${{ inputs.build }}" | cut -d'-' -f1)"; |
| 182 | + build_name="$(echo "${{ inputs.build }}" | cut -d'-' -f2)"; |
| 183 | + build_image="${REPOSITORY}:${VERSION}-${build_type}-node${NODE}-cuda${CUDA_VERSION_MAJOR}-${{ matrix.LINUX }}-${build_name}"; |
| 184 | + echo "BUILD_IMAGE=${build_image}" >> $GITHUB_ENV; |
| 185 | + fi |
| 186 | +
|
| 187 | + if [[ -n "${{ inputs.devel }}" ]]; then |
| 188 | + devel_type="$(echo "${{ inputs.devel }}" | cut -d'-' -f1)"; |
| 189 | + devel_name="$(echo "${{ inputs.devel }}" | cut -d'-' -f2)"; |
| 190 | + devel_image="${REPOSITORY}:${VERSION}-${devel_type}-node${NODE}-cuda${CUDA_VERSION_MAJOR}-${{ matrix.LINUX }}-${devel_name}"; |
| 191 | + echo "DEVEL_IMAGE=${devel_image}" >> $GITHUB_ENV; |
| 192 | + fi |
| 193 | +
|
| 194 | + echo "EOF" >> $GITHUB_ENV; |
| 195 | +
|
| 196 | + echo "IMAGE_NAME=${REPOSITORY}:${VERSION}-${image_type}-node${NODE}-cuda${CUDA_VERSION_MAJOR}-${{ matrix.LINUX }}-${image_name}" >> $GITHUB_ENV; |
| 197 | +
|
| 198 | + - name: Build and push image |
| 199 | + if: ${{ inputs.manual-build || env.files_changed == 'true' }} |
| 200 | + uses: ./.github/actions/build-and-publish-image-ssh |
| 201 | + with: |
| 202 | + home: ${{ env.HOME }} |
| 203 | + pull: ${{ inputs.pull }} |
| 204 | + push: ${{ inputs.push }} |
| 205 | + file: ${{ inputs.file }} |
| 206 | + temp: ${{ runner.temp }} |
| 207 | + tags: ${{ env.IMAGE_NAME }} |
| 208 | + registry-url: ${{ inputs.registry-url }} |
| 209 | + registry-username: ${{ inputs.registry-username }} |
| 210 | + registry-password: ${{ inputs.registry-password }} |
| 211 | + AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" |
| 212 | + AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" |
| 213 | + CUMLPRIMS_SSH_PRIVATE_DEPLOY_KEY: "${{ secrets.CUMLPRIMS_SSH_PRIVATE_DEPLOY_KEY }}" |
| 214 | + CUGRAPH_OPS_SSH_PRIVATE_DEPLOY_KEY: "${{ secrets.CUGRAPH_OPS_SSH_PRIVATE_DEPLOY_KEY }}" |
| 215 | + build-args: | |
| 216 | + ${{ env.BUILD_ARGS }} |
| 217 | + "NODE_VERSION=${{ env.NODE }}" |
| 218 | + "LINUX_VERSION=${{ matrix.LINUX }}" |
| 219 | + "RAPIDS_VERSION=${{ env.RAPIDS_VERSION }}" |
0 commit comments