Compare commits
1 Commits
feat/priva
...
fix/ci-bui
| Author | SHA1 | Date | |
|---|---|---|---|
| bd61a64c70 |
@@ -72,9 +72,17 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test-backend, test-frontend]
|
||||
# PRs only run the test jobs; build + deploy are reserved for
|
||||
# post-merge pushes to main. Without this gate every PR would push
|
||||
# a tagged image to the registry and SSH-deploy to prod.
|
||||
# post-merge pushes to main.
|
||||
if: github.event_name != 'pull_request'
|
||||
# Build on the host docker daemon directly (docker-outside-of-docker):
|
||||
# the runner shares the deploy host's daemon, so a plain `docker build`
|
||||
# reuses the host's layer cache and avoids buildx's docker-container
|
||||
# driver + the gha cache exporter — neither works against this single-host
|
||||
# act_runner, and there is no in-job daemon socket unless we mount it.
|
||||
container:
|
||||
image: docker.gitea.com/runner-images:ubuntu-latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
outputs:
|
||||
image_tag: ${{ steps.meta.outputs.image_tag }}
|
||||
version: ${{ steps.meta.outputs.version }}
|
||||
@@ -93,48 +101,32 @@ jobs:
|
||||
echo "image_tag=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: docker login
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY_URL }}
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build & push backend
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./backend
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-backend:latest
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-backend:${{ steps.meta.outputs.image_tag }}
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-backend:${{ steps.meta.outputs.version }}
|
||||
cache-from: type=gha,scope=backend
|
||||
cache-to: type=gha,mode=max,scope=backend
|
||||
|
||||
- name: Build & push frontend
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./frontend
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-frontend:latest
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-frontend:${{ steps.meta.outputs.image_tag }}
|
||||
${{ secrets.REGISTRY_URL }}/mangalord-frontend:${{ steps.meta.outputs.version }}
|
||||
cache-from: type=gha,scope=frontend
|
||||
cache-to: type=gha,mode=max,scope=frontend
|
||||
- name: Build & push backend + frontend
|
||||
env:
|
||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
IMAGE_TAG: ${{ steps.meta.outputs.image_tag }}
|
||||
VERSION: ${{ steps.meta.outputs.version }}
|
||||
run: |
|
||||
set -eu
|
||||
echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" -u "$REGISTRY_USERNAME" --password-stdin
|
||||
for svc in backend frontend; do
|
||||
img="$REGISTRY_URL/mangalord-$svc"
|
||||
docker build -t "$img:$IMAGE_TAG" -t "$img:latest" -t "$img:$VERSION" "./$svc"
|
||||
for tag in "$IMAGE_TAG" latest "$VERSION"; do docker push "$img:$tag"; done
|
||||
done
|
||||
docker logout "$REGISTRY_URL"
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-push
|
||||
if: github.event_name != 'pull_request'
|
||||
# Single-host deploy: the runner lives on the same box as the stack, so we
|
||||
# drive the host docker daemon directly (act_runner shares its socket via
|
||||
# `docker_host: "-"`) instead of SSHing out. The compose dir is bind-mounted
|
||||
# at its REAL host path so compose's relative bind-mounts (./mangalord/...,
|
||||
# ./Caddyfile) resolve; this requires `/mnt/ssd/docker-data` in the runner's
|
||||
# drive the host docker daemon directly (the job mounts the host docker
|
||||
# socket) instead of SSHing out. The compose dir is bind-mounted at its
|
||||
# REAL host path so compose's relative bind-mounts (./mangalord/...,
|
||||
# ./Caddyfile) resolve; both paths must be in the runner's
|
||||
# container.valid_volumes. The central compose references the images as
|
||||
# registry.mc02.dev/mangalord-*:${MANGALORD_TAG:-latest}, so we only pull
|
||||
# and recreate the two mangalord services at the freshly built SHA.
|
||||
@@ -142,6 +134,7 @@ jobs:
|
||||
image: docker:cli
|
||||
volumes:
|
||||
- /mnt/ssd/docker-data:/mnt/ssd/docker-data
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
steps:
|
||||
- name: Deploy to the local stack
|
||||
working-directory: /mnt/ssd/docker-data
|
||||
|
||||
Reference in New Issue
Block a user