Monitor and Build one from the repos #266
This file contains 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: Monitor and Build one from the repos | |
# env from bridge-manager workflow | |
env: | |
GO_VERSION: "1.22" | |
GHCR_REGISTRY: ghcr.io | |
GHCR_REGISTRY_IMAGE: "ghcr.io/${{ github.repository }}" | |
on: | |
workflow_dispatch: # Allow manual triggers | |
schedule: | |
- cron: "15 0,6,12,18 * * *" # every 6 hours at XX:15 | |
jobs: | |
check-digest: | |
runs-on: ubuntu-24.04 | |
outputs: | |
digest_upstream: ${{ steps.compare-digest.outputs.digest_upstream }} | |
needs_build: ${{ steps.compare-digest.outputs.needs_build }} | |
steps: | |
- name: 'Set up skopeo' | |
uses: warjiang/setup-skopeo@71776e03c10d767c04af8924fe5a67763f9b3d34 # v0.1.3 | |
with: | |
version: v1.17.0 | |
- name: Compare upstream image digest with repo image digest | |
id: compare-digest | |
run: | | |
DIGEST=$(skopeo inspect --override-os=linux --override-arch=amd64 docker://$GHCR_REGISTRY_IMAGE:latest --format '{{ index .Labels "com.beeper.bridge-manager.image.digest" }}' || echo unknown) | |
echo "Last image digest: ${DIGEST}" | |
DIGEST_UPSTREAM=$(skopeo inspect --override-os=linux --override-arch=amd64 docker://ghcr.io/beeper/bridge-manager:latest --format "{{ .Digest }}") | |
echo "Upstream image digest: ${DIGEST_UPSTREAM}" | |
echo "digest_upstream=$DIGEST_UPSTREAM" >> "$GITHUB_OUTPUT" | |
NEEDS_BUILD="false" | |
if [[ "$DIGEST" != "$DIGEST_UPSTREAM" ]]; then | |
echo "The last image digest does not match the one from upstream. A build will commence." | |
NEEDS_BUILD="true" | |
else | |
echo "The upstream image digest matches the one from the repo. This image has already been processed." | |
fi | |
echo "needs_build=$NEEDS_BUILD" >> "$GITHUB_OUTPUT" | |
# Following stage is based on bridge-manager's workflow, @silkie's fork in particular | |
build-docker: | |
runs-on: ubuntu-latest | |
needs: check-digest | |
if: ${{ needs.check-digest.outputs.needs_build == 'true' }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: beeper/bridge-manager | |
ref: main | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GHCR_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
labels: | | |
com.beeper.bridge-manager.image.digest=${{ needs.check-digest.outputs.digest_upstream}} | |
tags: | | |
type=raw,value=latest | |
type=sha,format=long,prefix= | |
- name: Docker Build | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: ${{ env.GHCR_REGISTRY_IMAGE }}:latest | |
pull: true | |
platforms: linux/amd64,linux/arm64 | |
context: . | |
file: docker/Dockerfile | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
push: true | |
build-args: | | |
COMMIT_HASH=${{ github.sha }} | |
workflow-keepalive: | |
runs-on: ubuntu-24.04 | |
if: github.event_name == 'schedule' | |
permissions: | |
actions: write | |
steps: | |
- uses: liskin/gh-workflow-keepalive@f72ff1a1336129f29bf0166c0fd0ca6cf1bcb38c # v1.2.1 |