|
16 | 16 | env:
|
17 | 17 | IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
|
18 | 18 | jobs:
|
| 19 | + build-akmods: |
| 20 | + name: Build akmods package |
| 21 | + runs-on: ubuntu-22.04 |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + id-token: write |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + major_version: [37, 38] |
| 30 | + driver_version: [520, 525, 470] |
| 31 | + exclude: |
| 32 | + - driver_version: 520 |
| 33 | + major_version: 38 |
| 34 | + - driver_version: 470 |
| 35 | + major_version: 38 |
| 36 | + steps: |
| 37 | + # Checkout push-to-registry action GitHub repository |
| 38 | + - name: Checkout Push to Registry action |
| 39 | + uses: actions/checkout@v3 |
| 40 | + |
| 41 | + - name: Matrix Variables |
| 42 | + run: | |
| 43 | + REPO=${{ github.repository }} |
| 44 | + echo "IMAGE_NAME=akmods-${REPO##*/}" >> $GITHUB_ENV |
| 45 | + - name: Generate tags |
| 46 | + id: generate-tags |
| 47 | + shell: bash |
| 48 | + run: | |
| 49 | + # Generate a timestamp for creating an image version history |
| 50 | + TIMESTAMP="$(date +%Y%m%d)" |
| 51 | + VARIANT="${{ matrix.major_version }}-${{ matrix.driver_version }}" |
| 52 | +
|
| 53 | + COMMIT_TAGS=() |
| 54 | + BUILD_TAGS=() |
| 55 | +
|
| 56 | + # Have tags for tracking builds during pull request |
| 57 | + SHA_SHORT="$(git rev-parse --short HEAD)" |
| 58 | + COMMIT_TAGS+=("pr-${{ github.event.number }}-${VARIANT}") |
| 59 | + COMMIT_TAGS+=("${SHA_SHORT}-${VARIANT}") |
| 60 | +
|
| 61 | + BUILD_TAGS=("${VARIANT}" "${VARIANT}-${TIMESTAMP}") |
| 62 | +
|
| 63 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 64 | + echo "Generated the following commit tags: " |
| 65 | + for TAG in "${COMMIT_TAGS[@]}"; do |
| 66 | + echo "${TAG}" |
| 67 | + done |
| 68 | +
|
| 69 | + alias_tags=("${COMMIT_TAGS[@]}") |
| 70 | + else |
| 71 | + alias_tags=("${BUILD_TAGS[@]}") |
| 72 | + fi |
| 73 | +
|
| 74 | + echo "Generated the following build tags: " |
| 75 | + for TAG in "${BUILD_TAGS[@]}"; do |
| 76 | + echo "${TAG}" |
| 77 | + done |
| 78 | +
|
| 79 | + echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + - name: Retrieve akmods signing key |
| 82 | + run: | |
| 83 | + mkdir -p certs |
| 84 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 85 | + echo "Using test signing key" |
| 86 | + else |
| 87 | + echo "${{ secrets.AKMOD_PRIVKEY }}" > certs/private_key.priv |
| 88 | + fi |
| 89 | + # DEBUG: get character count of key |
| 90 | + wc -c certs/private_key.priv |
| 91 | +
|
| 92 | + # Build metadata |
| 93 | + - name: Image Metadata |
| 94 | + uses: docker/metadata-action@v4 |
| 95 | + id: meta |
| 96 | + with: |
| 97 | + images: | |
| 98 | + ${{ env.IMAGE_NAME }} |
| 99 | + labels: | |
| 100 | + org.opencontainers.image.title=${{ env.IMAGE_NAME }} |
| 101 | + org.opencontainers.image.description=ublue-os ${{ env.IMAGE_NAME }} with akmods-nvidia packages pre-built |
| 102 | + io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md |
| 103 | + io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/1728152?s=200&v=4 |
| 104 | + # Build image using Buildah action |
| 105 | + - name: Build Image |
| 106 | + id: build_image |
| 107 | + uses: redhat-actions/buildah-build@v2 |
| 108 | + with: |
| 109 | + containerfiles: | |
| 110 | + ./build.Containerfile |
| 111 | + image: ${{ env.IMAGE_NAME }} |
| 112 | + tags: | |
| 113 | + ${{ steps.generate-tags.outputs.alias_tags }} |
| 114 | + build-args: | |
| 115 | + IMAGE_NAME=base |
| 116 | + FEDORA_MAJOR_VERSION=${{ matrix.major_version }} |
| 117 | + NVIDIA_MAJOR_VERSION=${{ matrix.driver_version }} |
| 118 | + labels: ${{ steps.meta.outputs.labels }} |
| 119 | + oci: false |
| 120 | + |
| 121 | + # Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR. |
| 122 | + # https://github.com/macbre/push-to-ghcr/issues/12 |
| 123 | + - name: Lowercase Registry |
| 124 | + id: registry_case |
| 125 | + uses: ASzc/change-string-case-action@v5 |
| 126 | + with: |
| 127 | + string: ${{ env.IMAGE_REGISTRY }} |
| 128 | + |
| 129 | + # Push the image to GHCR (Image Registry) |
| 130 | + - name: Push To GHCR |
| 131 | + uses: redhat-actions/push-to-registry@v2 |
| 132 | + id: push |
| 133 | + env: |
| 134 | + REGISTRY_USER: ${{ github.actor }} |
| 135 | + REGISTRY_PASSWORD: ${{ github.token }} |
| 136 | + with: |
| 137 | + image: ${{ steps.build_image.outputs.image }} |
| 138 | + tags: ${{ steps.build_image.outputs.tags }} |
| 139 | + registry: ${{ steps.registry_case.outputs.lowercase }} |
| 140 | + username: ${{ env.REGISTRY_USER }} |
| 141 | + password: ${{ env.REGISTRY_PASSWORD }} |
| 142 | + extra-args: | |
| 143 | + --disable-content-trust |
| 144 | +
|
| 145 | + # Sign container |
| 146 | + - uses: sigstore/cosign-installer@v3.0.1 |
| 147 | + |
| 148 | + # Only needed when running `cosign sign` using a key |
| 149 | + - name: Write signing key to disk |
| 150 | + run: | |
| 151 | + echo "${{ env.COSIGN_PRIVATE_KEY }}" > cosign.key |
| 152 | + # DEBUG: get character count of key |
| 153 | + wc -c cosign.key |
| 154 | + env: |
| 155 | + COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} |
| 156 | + |
| 157 | + - name: Login to GitHub Container Registry |
| 158 | + uses: docker/login-action@v2 |
| 159 | + with: |
| 160 | + registry: ghcr.io |
| 161 | + username: ${{ github.actor }} |
| 162 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 163 | + |
| 164 | + - name: Sign container image |
| 165 | + run: | |
| 166 | + cosign sign -y --key cosign.key ${{ steps.registry_case.outputs.lowercase }}/${{ steps.build_image.outputs.image }}@${TAGS} |
| 167 | + env: |
| 168 | + TAGS: ${{ steps.push.outputs.digest }} |
| 169 | + COSIGN_EXPERIMENTAL: false |
| 170 | + |
| 171 | + - name: Echo outputs |
| 172 | + run: | |
| 173 | + echo "${{ toJSON(steps.push.outputs) }}" |
| 174 | +
|
19 | 175 | push-ghcr:
|
20 | 176 | name: Build and push image
|
| 177 | + needs: build-akmods |
21 | 178 | runs-on: ubuntu-22.04
|
22 | 179 | permissions:
|
23 | 180 | contents: read
|
@@ -108,8 +265,10 @@ jobs:
|
108 | 265 | done
|
109 | 266 |
|
110 | 267 | alias_tags=("${COMMIT_TAGS[@]}")
|
| 268 | + echo "AKMODS_VERSION=pr-${{ github.event.number }}-${{ matrix.major_version }}" >> $GITHUB_ENV |
111 | 269 | else
|
112 | 270 | alias_tags=("${BUILD_TAGS[@]}")
|
| 271 | + echo "AKMODS_VERSION=${{ matrix.major_version }}" >> $GITHUB_ENV |
113 | 272 | fi
|
114 | 273 |
|
115 | 274 | echo "Generated the following build tags: "
|
@@ -148,12 +307,13 @@ jobs:
|
148 | 307 | uses: redhat-actions/buildah-build@v2
|
149 | 308 | with:
|
150 | 309 | containerfiles: |
|
151 |
| - ./Containerfile |
| 310 | + ./install.Containerfile |
152 | 311 | image: ${{ env.IMAGE_NAME }}
|
153 | 312 | tags: |
|
154 | 313 | ${{ steps.generate-tags.outputs.alias_tags }}
|
155 | 314 | build-args: |
|
156 | 315 | IMAGE_NAME=${{ matrix.image_name }}
|
| 316 | + AKMODS_VERSION=${{ env.AKMODS_VERSION }} |
157 | 317 | FEDORA_MAJOR_VERSION=${{ matrix.major_version }}
|
158 | 318 | NVIDIA_MAJOR_VERSION=${{ matrix.driver_version }}
|
159 | 319 | labels: ${{ steps.meta.outputs.labels }}
|
|
0 commit comments