fix(ci): split Docker build stages

This commit is contained in:
Luke Tainton 2025-01-02 17:44:25 +00:00
parent 2d10fb9270
commit 7eb332eec7
Signed by: luke
SSH Key Fingerprint: SHA256:D34npKT7UaiT/7gULqu7EPSLWWVAjTjXf4kKfJ/fQBo

View File

@ -87,30 +87,30 @@ jobs:
fi fi
- name: Cancel if no changes - name: Cancel if no changes
if: steps.changes.outputs.changes == 'false' if: steps.changes.outputs.changes == false
run: exit 1 run: exit 1
- name: Create changelog # - name: Create changelog
id: create_changelog # id: create_changelog
if: steps.changes.outputs.changes == 'true' # if: steps.changes.outputs.changes == true
run: | # run: |
rm -f .changelog # rm -f .changelog
if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then # if [[ -z $(grep '[^[:space:]]' .changes_feat) ]] ; then
printf "## 🚀 Features" > .changelog # printf "## 🚀 Features" > .changelog
cat .changes_feat >> .changelog # cat .changes_feat >> .changelog
fi # fi
if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then # if [[ -z $(grep '[^[:space:]]' .changes_fix) ]] ; then
printf "## 🐛 Bug Fixes" >> .changelog # printf "## 🐛 Bug Fixes" >> .changelog
cat .changes_fix >> .changelog # cat .changes_fix >> .changelog
fi # fi
if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then # if [[ -z $(grep '[^[:space:]]' .changes_dep) ]] ; then
printf "## 📦 Dependencies" >> .changelog # printf "## 📦 Dependencies" >> .changelog
cat .changes_dep >> .changelog # cat .changes_dep >> .changelog
fi # fi
if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then # if [[ -z $(grep '[^[:space:]]' .changes_other) ]] ; then
printf "## 💬 Other" >> .changelog # printf "## 💬 Other" >> .changelog
cat .changes_other >> .changelog # cat .changes_other >> .changelog
fi # fi
- name: Set server URL - name: Set server URL
id: set_srvurl id: set_srvurl
@ -140,15 +140,68 @@ jobs:
with: with:
tag: ${{ steps.get_next_version.outputs.tag }} tag: ${{ steps.get_next_version.outputs.tag }}
name: ${{ steps.get_next_version.outputs.tag }} name: ${{ steps.get_next_version.outputs.tag }}
body_path: .changelog # body_path: .changelog
body: ${{ steps.get_next_version.outputs.changelog }}
- name: Set success/fail flag - name: Set success/fail flag
id: set_flag id: set_flag
if: steps.changes.outputs.changes == 'true' if: steps.changes.outputs.changes == 'true'
run: if test "${{ steps.changes.outputs.changes }}" = "true"; then echo "success=true" >> "$GITEA_OUTPUT"; else echo "success=false" >> "$GITEA_OUTPUT"; fi run: if test "${{ steps.changes.outputs.changes }}" = "true"; then echo "success=true" >> "$GITEA_OUTPUT"; else echo "success=false" >> "$GITEA_OUTPUT"; fi
create_docker: build_docker_ghcr:
name: Create Docker Image name: Build GHCR Docker Images
needs: create_release
if: ${{ needs.create_release.outputs.success == 'true' }}
outputs:
success: ${{ steps.set_flag.outputs.success }}
with:
release: ${{ needs.create_release.outputs.release_name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.release }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: luketainton
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/luketainton/webexmemebot
tags: type=semver,pattern=v{{version}},value=${{ inputs.release }}
- name: Build and push images
id: build_push
uses: docker/build-push-action@v6
with:
context: .
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: |
ghcr.io/luketainton/webexmemebot:latest
ghcr.io/luketainton/webexmemebot:${{ inputs.release }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/luketainton/webexmemebot
subject-digest: ${{ steps.build_push.outputs.digest }}
push-to-registry: true
- name: Set success flag
id: set_flag
run: echo "success=true" >> "$GITEA_OUTPUT"
build_docker_gitea:
name: Build Gitea Docker Images
needs: create_release needs: create_release
if: ${{ needs.create_release.outputs.success == 'true' }} if: ${{ needs.create_release.outputs.success == 'true' }}
outputs: outputs:
@ -166,46 +219,23 @@ jobs:
- name: Log in to Gitea Container Registry - name: Log in to Gitea Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: git.tainton.uk registry: ${{ vars.PACKAGES_REGISTRY_URL }}
username: ${{ gitea.actor }} username: ${{ vars.PACKAGES_REGISTRY_USERNAME }}
password: ${{ gitea.token }} password: ${{ vars.PACKAGES_REGISTRY_PASSWORD }}
- name: Log in to GitHub Container Registry - name: Build Gitea image(s)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: luketainton
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
git.tainton.uk/${{ gitea.repository }}
ghcr.io/luketainton/webexmemebot
tags: |
type=semver,pattern=v{{version}},value=${{ inputs.release }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: false
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
tags: | tags: |
git.tainton.uk/${{ gitea.repository }}:latest ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:latest
git.tainton.uk/${{ gitea.repository }}:${{ inputs.release }} ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:${{ inputs.release }}
ghcr.io/luketainton/webexmemebot:latest
ghcr.io/luketainton/webexmemebot:${{ inputs.release }} - name: Push Gitea image(s)
run:
- name: Generate artifact attestation docker push ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:latest ${{ vars.PACKAGES_REGISTRY_URL }}/${{ gitea.repository }}:${{ inputs.release }}
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/luketainton/webexmemebot
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Set success flag - name: Set success flag
id: set_flag id: set_flag