Files
sor/.gitea/workflows/build-push.yml
T

82 lines
3.5 KiB
YAML

name: Build & Push to Harbor
on:
push:
branches: [main]
paths:
- "Server/**"
- ".gitea/workflows/**"
env:
REGISTRY: registry.aeternalisgames.com
PROJECT: sor
jobs:
build-and-push:
runs-on: [self-hosted, linux, ubuntu-22.04]
steps:
- name: Checkout
uses: actions/checkout@v4
# Short SHA used as the immutable image tag.
- name: Compute image tag
id: tag
run: echo "SHA=$(echo '${{ github.sha }}' | cut -c1-8)" >> $GITHUB_OUTPUT
- name: Log in to Harbor
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
# Enable BuildKit for faster, more efficient multi-stage builds.
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# ── SOR.Host ────────────────────────────────────────────────────────────
- name: Build and push sor-server
uses: docker/build-push-action@v5
with:
context: Server
file: Server/Dockerfile.host
push: true
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:buildcache,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:${{ steps.tag.outputs.SHA }}
${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:latest
# ── SOR.Admin ───────────────────────────────────────────────────────────
- name: Build and push sor-admin
uses: docker/build-push-action@v5
with:
context: Server
file: Server/Dockerfile.admin
push: true
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:buildcache,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:${{ steps.tag.outputs.SHA }}
${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:latest
# ── Update k8s manifests with new image tags ─────────────────────────────
# ArgoCD watches deploy/k8s/ in git; updating these tags triggers a sync.
- name: Update deployment image tags
run: |
SHA=${{ steps.tag.outputs.SHA }}
sed -i "s|image: ${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:.*|image: ${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-server:${SHA}|" deploy/k8s/deployment-host.yaml
sed -i "s|image: ${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:.*|image: ${{ env.REGISTRY }}/${{ env.PROJECT }}/sor-admin:${SHA}|" deploy/k8s/deployment-admin.yaml
- name: Commit updated manifests
run: |
SHA=${{ steps.tag.outputs.SHA }}
git config user.email "ci@aeternalisgames.com"
git config user.name "Gitea CI"
git add deploy/k8s/deployment-host.yaml deploy/k8s/deployment-admin.yaml
# Only commit if there are staged changes; [skip ci] prevents a re-trigger.
git diff --cached --quiet || \
git commit -m "ci: deploy image tags ${SHA} [skip ci]"
git push