Build FCOS layer image #311
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: Build FCOS layer image | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 6,18 * * *" | |
| push: | |
| branches: [main] | |
| paths: [Containerfile] | |
| env: | |
| IMAGE: ghcr.io/lthms/elsa-fcos-layer:latest | |
| BASE_IMAGE: quay.io/fedora/fedora-coreos:stable | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Compute input digest | |
| id: inputs | |
| run: | | |
| base_digest=$(skopeo inspect --no-tags "docker://$BASE_IMAGE" | jq -r '.Digest') || true | |
| if [ -z "$base_digest" ]; then | |
| echo "Failed to fetch base image digest, forcing build." | |
| echo "input_digest=unknown" >> "$GITHUB_OUTPUT" | |
| else | |
| input_digest=$(echo "${base_digest} $(sha256sum Containerfile)" | sha256sum | cut -d' ' -f1) | |
| echo "input_digest=${input_digest}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Check published image | |
| id: published | |
| run: | | |
| published_digest=$(skopeo inspect --no-tags "docker://$IMAGE" 2>/dev/null \ | |
| | jq -r '.Labels["elsa.input-digest"] // empty') || true | |
| echo "input_digest=${published_digest}" >> "$GITHUB_OUTPUT" | |
| - name: Check if build is needed | |
| id: check | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Forced build via workflow_dispatch." | |
| elif [ "${{ steps.inputs.outputs.input_digest }}" = "${{ steps.published.outputs.input_digest }}" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "Inputs unchanged, skipping build." | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Inputs changed, building." | |
| fi | |
| - uses: docker/login-action@v4 | |
| if: steps.check.outputs.skip != 'true' | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/build-push-action@v7 | |
| if: steps.check.outputs.skip != 'true' | |
| with: | |
| context: . | |
| file: Containerfile | |
| push: true | |
| pull: true | |
| tags: ${{ env.IMAGE }} | |
| labels: elsa.input-digest=${{ steps.inputs.outputs.input_digest }} |