From 7b725206affcac70ca5caab01100b3e0d6306b92 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 17 Apr 2026 12:59:28 -0500 Subject: [PATCH] chore: add forgejo workflow for docker build and deploy --- .forgejo/workflows/build.yaml | 79 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 0333498..890a90c 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Build +name: Build and Deploy on: push: @@ -6,56 +6,59 @@ on: - main env: - DOCKER_BUILDKIT: 1 - DOCKER_TLS_CERTDIR: "" + REGISTRY: git.mcintire.me + IMAGE_NAME: graham/aprs.me concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - build: - runs-on: ubuntu-latest + build-and-push: + name: Build and Push Docker Image + runs-on: ubuntu-22.04 + steps: - name: Checkout code - uses: actions/checkout@v6 + uses: https://github.com/actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Install Docker CLI + run: | + apt-get update && apt-get install -y docker.io - - name: Log in to container registry - uses: docker/login-action@v3 - with: - registry: ${{ secrets.REGISTRY_URL }} - username: ${{ secrets.REGISTRY_USER }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Extract metadata - id: meta + - name: Generate image tag + id: tag run: | TIMESTAMP=$(date +%s) - SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) - IMAGE=${{ secrets.REGISTRY_URL }}/${{ github.repository }} - echo "image=${IMAGE}" >> $GITHUB_OUTPUT - echo "tag=${IMAGE}:main-${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT - echo "latest_tag=${IMAGE}:latest" >> $GITHUB_OUTPUT + SHORT_SHA=$(git rev-parse --short=7 HEAD | cut -c1-7) + TAG="main-${TIMESTAMP}-${SHORT_SHA}" + echo "tag=${TAG}" >> $GITHUB_OUTPUT + + - name: Log in to container registry + run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USER }} --password-stdin - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: | - ${{ steps.meta.outputs.tag }} - ${{ steps.meta.outputs.latest_tag }} - cache-from: type=registry,ref=${{ steps.meta.outputs.latest_tag }} - cache-to: type=inline - - - name: Update deployment image tag run: | - sed -i "s|image: git\.mcintire\.me/graham/aprs\.me:.*|image: ${{ steps.meta.outputs.tag }}|g" k8s/deployment.yaml - git config user.email "ci@git.mcintire.me" - git config user.name "CI" + IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + TAG="${{ steps.tag.outputs.tag }}" + docker build -t "${IMAGE}:${TAG}" -t "${IMAGE}:main" . + docker push "${IMAGE}:${TAG}" + docker push "${IMAGE}:main" + + - name: Update deployment manifest + run: | + IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + TAG="${{ steps.tag.outputs.tag }}" + sed -i "s|image: ${IMAGE}:.*|image: ${IMAGE}:${TAG}|g" k8s/deployment.yaml + + - name: Commit and push updated manifest + run: | + IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" + TAG="${{ steps.tag.outputs.tag }}" + git config user.name "FluxCD" + git config user.email "fluxcd@w5isp.com" + git remote set-url origin https://${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASSWORD }}@git.mcintire.me/graham/aprs.me.git git add k8s/deployment.yaml - git diff --cached --quiet || git commit -m "chore: update aprs.me image to ${{ steps.meta.outputs.tag }} [skip ci]" - git push origin HEAD:main + git diff --cached --quiet && echo "No changes to commit" && exit 0 + git commit -m "chore: update aprs.me image to ${IMAGE}:${TAG} [skip ci]" + git push origin main