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