chore: add forgejo workflow for docker build and deploy
This commit is contained in:
parent
9c7c190979
commit
7b725206af
1 changed files with 41 additions and 38 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
name: Build
|
name: Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -6,56 +6,59 @@ on:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_BUILDKIT: 1
|
REGISTRY: git.mcintire.me
|
||||||
DOCKER_TLS_CERTDIR: ""
|
IMAGE_NAME: graham/aprs.me
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
name: Build and Push Docker Image
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v6
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Install Docker CLI
|
||||||
uses: docker/setup-buildx-action@v3
|
run: |
|
||||||
|
apt-get update && apt-get install -y docker.io
|
||||||
|
|
||||||
- name: Log in to container registry
|
- name: Generate image tag
|
||||||
uses: docker/login-action@v3
|
id: tag
|
||||||
with:
|
|
||||||
registry: ${{ secrets.REGISTRY_URL }}
|
|
||||||
username: ${{ secrets.REGISTRY_USER }}
|
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Extract metadata
|
|
||||||
id: meta
|
|
||||||
run: |
|
run: |
|
||||||
TIMESTAMP=$(date +%s)
|
TIMESTAMP=$(date +%s)
|
||||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
SHORT_SHA=$(git rev-parse --short=7 HEAD | cut -c1-7)
|
||||||
IMAGE=${{ secrets.REGISTRY_URL }}/${{ github.repository }}
|
TAG="main-${TIMESTAMP}-${SHORT_SHA}"
|
||||||
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
|
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
||||||
echo "tag=${IMAGE}:main-${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
||||||
echo "latest_tag=${IMAGE}:latest" >> $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
|
- 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: |
|
run: |
|
||||||
sed -i "s|image: git\.mcintire\.me/graham/aprs\.me:.*|image: ${{ steps.meta.outputs.tag }}|g" k8s/deployment.yaml
|
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
||||||
git config user.email "ci@git.mcintire.me"
|
TAG="${{ steps.tag.outputs.tag }}"
|
||||||
git config user.name "CI"
|
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 add k8s/deployment.yaml
|
||||||
git diff --cached --quiet || git commit -m "chore: update aprs.me image to ${{ steps.meta.outputs.tag }} [skip ci]"
|
git diff --cached --quiet && echo "No changes to commit" && exit 0
|
||||||
git push origin HEAD:main
|
git commit -m "chore: update aprs.me image to ${IMAGE}:${TAG} [skip ci]"
|
||||||
|
git push origin main
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue