|
| 1 | +name: Container Build |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - .github/workflows/buildah-build-toolchain.yml # Self-trigger |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io/bouncmpe |
| 10 | + IMAGE_NAME: labs344 |
| 11 | + LABS344_VERSION: latest |
| 12 | + CONTAINERS_ROOT: /home/runner/.local/share/containers |
| 13 | + TMPDIR: /home/runner/.local/share/containers/tmp |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + buildah-build: |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + os: [ubuntu-24.04, ubuntu-24.04-arm] |
| 25 | + runs-on: ${{ matrix.os }} |
| 26 | + concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Install container tools |
| 32 | + run: sudo apt-get install podman buildah jq |
| 33 | + |
| 34 | + - name: Maximize build space |
| 35 | + uses: easimon/maximize-build-space@v10 |
| 36 | + with: |
| 37 | + root-reserve-mb: 2048 # Reserve disk space for repository |
| 38 | + remove-dotnet: "true" |
| 39 | + remove-android: "true" |
| 40 | + remove-haskell: "true" |
| 41 | + remove-codeql: "true" |
| 42 | + remove-docker-images: "true" |
| 43 | + build-mount-path: ${{ env.CONTAINERS_ROOT }} # The remaining space only for container build |
| 44 | + |
| 45 | + - run: mkdir -p $TMPDIR |
| 46 | + |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Prepare environment variables |
| 51 | + run: | |
| 52 | + echo "HOSTARCH=$(podman info --format='{{.Host.Arch}}')" >> $GITHUB_ENV |
| 53 | + echo "PLATFORM=$(podman info --format='{{.Version.OsArch}}' | sed 's/\//-/g')" >> $GITHUB_ENV |
| 54 | + echo "LABS344_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Log in to the GitHub Container registry |
| 57 | + uses: redhat-actions/podman-login@v1 |
| 58 | + with: |
| 59 | + registry: ${{ env.REGISTRY }} |
| 60 | + username: ${{ github.actor }} |
| 61 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + |
| 63 | + - name: Build toolchain container image |
| 64 | + id: build-toolchain |
| 65 | + uses: redhat-actions/buildah-build@v2 |
| 66 | + with: |
| 67 | + image: ${{ env.IMAGE_NAME }} |
| 68 | + tags: | |
| 69 | + ${{ env.LABS344_VERSION }}-toolchain |
| 70 | + ${{ env.LABS344_VERSION }}-toolchain-${{ env.HOSTARCH }} |
| 71 | + layers: true |
| 72 | + oci: true |
| 73 | + build-args: | |
| 74 | + LABS344_VERSION=${{ env.LABS344_VERSION }} |
| 75 | + extra-args: | |
| 76 | + --target labs344-toolchain |
| 77 | + containerfiles: | |
| 78 | + containers/labs344/Dockerfile |
| 79 | + context: containers |
| 80 | + |
| 81 | + - name: Push to GitHub Container Repository |
| 82 | + if: github.ref == 'refs/heads/main' |
| 83 | + id: push-toolchain-ghcr |
| 84 | + uses: redhat-actions/push-to-registry@v2 |
| 85 | + with: |
| 86 | + registry: ${{ env.REGISTRY }} |
| 87 | + image: ${{ steps.build-toolchain.outputs.image }} |
| 88 | + tags: ${{ env.LABS344_VERSION }}-toolchain-${{ env.HOSTARCH }} |
| 89 | + digestfile: ${{ runner.temp }}/digest-labs344-toolchain-${{ env.LABS344_VERSION }}-${{ env.PLATFORM }} |
| 90 | + |
| 91 | + - name: Upload digests |
| 92 | + if: github.ref == 'refs/heads/main' |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: digest-bouncmpe-${{ env.LABS344_VERSION }}-${{ env.PLATFORM }} |
| 96 | + path: ${{ runner.temp }}/digest-* |
| 97 | + if-no-files-found: error |
| 98 | + retention-days: 1 |
| 99 | + compression-level: 0 # no compression |
| 100 | + |
| 101 | + buildah-merge: |
| 102 | + name: Merge container images |
| 103 | + runs-on: ubuntu-24.04 |
| 104 | + needs: buildah-build |
| 105 | + if: github.ref == 'refs/heads/main' && always() |
| 106 | + steps: |
| 107 | + - name: Download digests |
| 108 | + uses: actions/download-artifact@v4 |
| 109 | + with: |
| 110 | + path: ${{ runner.temp }}/digests |
| 111 | + pattern: digest-* |
| 112 | + merge-multiple: true |
| 113 | + |
| 114 | + - name: Prepare environment variables |
| 115 | + run: | |
| 116 | + echo "LABS344_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV |
| 117 | +
|
| 118 | + - name: Log in to the GitHub Container registry |
| 119 | + uses: redhat-actions/podman-login@v1 |
| 120 | + with: |
| 121 | + registry: ${{ env.REGISTRY }} |
| 122 | + username: ${{ github.repository_owner }} |
| 123 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + |
| 125 | + - name: Create and push manifest list for labs344-toolchain |
| 126 | + run: | |
| 127 | + MANIFEST=labs344-toolchain |
| 128 | + FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 129 | + buildah manifest create $MANIFEST |
| 130 | + for digest in ${{ runner.temp }}/digests/digest-labs344-toolchain-*; do |
| 131 | + echo "Adding $(cat $digest)" |
| 132 | + buildah manifest add $MANIFEST $FULL_IMAGE_NAME@$(cat $digest) |
| 133 | + done |
| 134 | + buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:${{ env.LABS344_VERSION }}-toolchain |
| 135 | + buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:latest-toolchain |
0 commit comments