Push Images #82
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Push Images | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - docker-bake.hcl | |
| - .github/workflows/deploy.yml | |
| - Dockerfile | |
| schedule: | |
| - cron: 2 4 10 * * | |
| workflow_dispatch: | |
| concurrency: | |
| group: push-images-${{ github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }}/${{ matrix.platform }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - jekyll | |
| - pages | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: docker/setup-qemu-action@v4 | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Build staging image | |
| run: | | |
| target="${{ matrix.target }}" | |
| platform="${{ matrix.platform }}" | |
| arch="${platform##*/}" | |
| tag="${GITHUB_SHA::7}-${arch}" | |
| [ "$target" = "pages" ] && tag="pages-${tag}" | |
| docker buildx bake "$target" --push \ | |
| --set "$target.platform=$platform" \ | |
| --set "$target.tags=jekyll/jekyll:$tag" | |
| test: | |
| name: Test ${{ matrix.target }}/${{ matrix.platform }} | |
| needs: build | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - jekyll | |
| - pages | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: docker/setup-qemu-action@v4 | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Test staging image | |
| run: | | |
| target="${{ matrix.target }}" | |
| platform="${{ matrix.platform }}" | |
| arch="${platform##*/}" | |
| tag="${GITHUB_SHA::7}-${arch}" | |
| image="jekyll/jekyll:latest" | |
| if [ "$target" = "pages" ]; then | |
| tag="pages-${tag}" | |
| image="jekyll/jekyll:pages" | |
| fi | |
| ref="jekyll/jekyll:$tag" | |
| docker pull --platform "$platform" "$ref" | |
| docker tag "$ref" "$image" | |
| script/test "$target" "$arch" | |
| promote: | |
| name: Promote ${{ matrix.target }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| needs: test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - jekyll | |
| - pages | |
| steps: | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Promote final tags | |
| run: | | |
| tag="${GITHUB_SHA::7}" | |
| target="${{ matrix.target }}" | |
| tags="" | |
| if [ "$target" = "pages" ]; then | |
| tag="pages-${tag}" | |
| tags="pages" | |
| fi | |
| amd64_ref="jekyll/jekyll:${tag}-amd64" | |
| arm64_ref="jekyll/jekyll:${tag}-arm64" | |
| docker buildx imagetools inspect "$amd64_ref" | |
| docker buildx imagetools inspect "$arm64_ref" | |
| if [ "$target" != "pages" ]; then | |
| version="$( | |
| docker run --rm --platform linux/amd64 "$amd64_ref" \ | |
| jekyll --version | awk '{print $2}' | |
| )" | |
| if [ -z "$version" ]; then | |
| echo "could not determine Jekyll version from $amd64_ref" >&2 | |
| exit 1 | |
| fi | |
| major="${version%%.*}" | |
| minor="${version%.*}" | |
| tags="latest $version $minor $major" | |
| fi | |
| tag_args=() | |
| for final_tag in $tags; do | |
| tag_args+=(--tag "jekyll/jekyll:${final_tag}") | |
| done | |
| docker buildx imagetools create \ | |
| "${tag_args[@]}" \ | |
| "$amd64_ref" \ | |
| "$arm64_ref" | |
| for final_tag in $tags; do | |
| docker buildx imagetools inspect "jekyll/jekyll:${final_tag}" | |
| done | |
| - uses: regclient/actions/regctl-installer@1b705e32d40851370799ea5814e83d0a5f6a70dc | |
| with: | |
| release: v0.11.5 | |
| - name: Verify Regctl | |
| run: | | |
| regctl_path="$(command -v regctl)" | |
| echo "c93aa7638749f5aaac1a8e01787321889c78f0101809bb2880343478d0ba0467 $regctl_path" | sha256sum --check | |
| - uses: regclient/actions/regctl-login@1b705e32d40851370799ea5814e83d0a5f6a70dc | |
| with: | |
| registry: docker.io | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Delete staging tags | |
| run: | | |
| tag="${GITHUB_SHA::7}" | |
| [ "${{ matrix.target }}" = "pages" ] && tag="pages-${tag}" | |
| regctl tag delete --ignore-missing "jekyll/jekyll:${tag}-amd64" | |
| regctl tag delete --ignore-missing "jekyll/jekyll:${tag}-arm64" |