ci(deploy): switch to libretech/runner-image:v1 and consolidate
CI / ci (pull_request) Failing after 5m52s
CI / ci (pull_request) Failing after 5m52s
The deploy workflow is now a single job that builds, pushes, and deploys in one runner. Tag computation moved to docker/metadata-action, the per-deploy .env perl rewrite is gone (host pins LIBRENOTES_IMAGE once; main pushes update :main rolling, releases pin to :vX.Y.Z by manual edit), and both jobs run in our bespoke runner image whose runner user already has socket access via group membership. ci.yml moves to the same image so go/make/node are all available without per-step apt installs. Drops compose.prod.yaml (unused, redundant with compose.netcup.yaml).
This commit is contained in:
+47
-80
@@ -6,124 +6,91 @@ on:
|
||||
tags: ["v*"]
|
||||
|
||||
# Required repository secrets:
|
||||
# REGISTRY registry hostname, e.g. git.librete.ch
|
||||
# REGISTRY_USER robot account or PAT username
|
||||
# REGISTRY_PASS robot/PAT token with package:write
|
||||
# DEPLOY_HOST deployment SSH target, e.g. root@netcup
|
||||
# DEPLOY_KEY private SSH key (PEM, no passphrase)
|
||||
# DEPLOY_PATH remote stack directory, e.g. /srv/librenotes
|
||||
# HEALTH_URL public URL to verify post-deploy, e.g.
|
||||
# https://ln.cloud.librete.ch/healthz
|
||||
# REGISTRY registry hostname (git.librete.ch)
|
||||
# REGISTRY_USER robot account or PAT username (libretech-bot)
|
||||
# REGISTRY_PASS PAT with write:package
|
||||
# DEPLOY_HOST SSH target, e.g. root@cloud.librete.ch
|
||||
# DEPLOY_KEY passphrase-less private key (PEM)
|
||||
# DEPLOY_PATH remote stack dir (/srv/librenotes)
|
||||
# HEALTH_URL https://ln.cloud.librete.ch/healthz
|
||||
#
|
||||
# Required repository variable:
|
||||
# DEPLOY_ENABLED set to "true" to enable the workflow
|
||||
#
|
||||
# Image path: ${REGISTRY}/public/librenotes (matches Gitea owner/repo).
|
||||
# Main pushes publish :main and :<sha7>. Tag pushes publish :<tag> and
|
||||
# :latest, then pin LIBRENOTES_IMAGE on the host to the immutable tag
|
||||
# so rollback is just `perl -i -pe 's|^LIBRENOTES_IMAGE=.*|...=...:vX.Y.Z|' .env`
|
||||
# followed by `docker compose ... up -d`.
|
||||
# Image: ${REGISTRY}/public/librenotes
|
||||
# main pushes → :main + :<sha7>
|
||||
# tag pushes → :<tag> + :latest
|
||||
#
|
||||
# The host's /srv/librenotes/.env pins LIBRENOTES_IMAGE once
|
||||
# (e.g. =git.librete.ch/public/librenotes:main). Main pushes
|
||||
# update :main rolling so a `compose pull` picks up the new image
|
||||
# without rewriting any file. Tag pin / rollback is a manual edit
|
||||
# of LIBRENOTES_IMAGE in .env followed by `compose pull && up -d`.
|
||||
|
||||
jobs:
|
||||
build:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
# Gitea Actions: pin image so docker CLI is present. The runner
|
||||
# already bind-mounts /var/run/docker.sock into job containers
|
||||
# automatically (because it has the socket mounted itself); adding
|
||||
# `volumes:` here again triggers a duplicate-mount-point error.
|
||||
# Custom Gitea runner image: Ubuntu 24.04 + docker CLI + node + git
|
||||
# + perl + ssh, runner user pre-joined to docker gid 998 so the
|
||||
# auto-mounted /var/run/docker.sock is writable without --user root.
|
||||
container:
|
||||
image: catthehacker/ubuntu:runner-latest
|
||||
timeout-minutes: 15
|
||||
image: git.librete.ch/libretech/runner-image:v1
|
||||
timeout-minutes: 20
|
||||
if: ${{ vars.DEPLOY_ENABLED == 'true' }}
|
||||
outputs:
|
||||
image_ref: ${{ steps.tags.outputs.image_ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to registry
|
||||
uses: docker/login-action@v3
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASS }}
|
||||
|
||||
- name: Compute tags
|
||||
id: tags
|
||||
run: |
|
||||
BASE="${{ secrets.REGISTRY }}/public/librenotes"
|
||||
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
||||
TAG="${GITHUB_REF##refs/tags/}"
|
||||
echo "tags=${BASE}:${TAG},${BASE}:latest" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "image_ref=${BASE}:${TAG}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
SHA7="${GITHUB_SHA::7}"
|
||||
echo "tags=${BASE}:main,${BASE}:${SHA7}" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${SHA7}" >> "$GITHUB_OUTPUT"
|
||||
echo "image_ref=${BASE}:main" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ secrets.REGISTRY }}/public/librenotes
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha,format=short
|
||||
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.tags.outputs.tags }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
VERSION=${{ steps.tags.outputs.version }}
|
||||
VERSION=${{ steps.meta.outputs.version }}
|
||||
BUILDTIME=${{ github.event.head_commit.timestamp }}
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
# Same image as build — bundles ssh, perl, curl. No docker needed.
|
||||
container:
|
||||
image: catthehacker/ubuntu:runner-latest
|
||||
needs: build
|
||||
timeout-minutes: 10
|
||||
if: ${{ vars.DEPLOY_ENABLED == 'true' }}
|
||||
steps:
|
||||
- name: Configure SSH
|
||||
- name: Deploy to host
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
HEALTH_URL: ${{ secrets.HEALTH_URL }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/id_deploy
|
||||
chmod 600 ~/.ssh/id_deploy
|
||||
ssh-keyscan -H "${DEPLOY_HOST#*@}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
|
||||
- name: Pull and restart on deploy host
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
IMAGE_REF: ${{ needs.build.outputs.image_ref }}
|
||||
run: |
|
||||
REMOTE_CMD='cd "$DEPLOY_PATH" || exit 1
|
||||
git pull --ff-only
|
||||
# Always pin LIBRENOTES_IMAGE so first deploy works without manual
|
||||
# .env priming and so rollback only ever needs an .env edit.
|
||||
perl -i -pe "s|^LIBRENOTES_IMAGE=.*|LIBRENOTES_IMAGE=$IMAGE_REF|" .env
|
||||
grep -q "^LIBRENOTES_IMAGE=" .env || echo "LIBRENOTES_IMAGE=$IMAGE_REF" >> .env
|
||||
docker compose -f compose.yaml -f compose.netcup.yaml pull
|
||||
docker compose -f compose.yaml -f compose.netcup.yaml up -d --remove-orphans'
|
||||
ssh -i ~/.ssh/id_deploy \
|
||||
-o StrictHostKeyChecking=accept-new \
|
||||
"$DEPLOY_HOST" \
|
||||
"DEPLOY_PATH='$DEPLOY_PATH' IMAGE_REF='$IMAGE_REF' bash -s" <<< "$REMOTE_CMD"
|
||||
"set -e
|
||||
cd '$DEPLOY_PATH'
|
||||
git pull --ff-only
|
||||
docker compose -f compose.yaml -f compose.netcup.yaml pull
|
||||
docker compose -f compose.yaml -f compose.netcup.yaml up -d --remove-orphans"
|
||||
|
||||
- name: Verify health
|
||||
env:
|
||||
HEALTH_URL: ${{ secrets.HEALTH_URL }}
|
||||
run: |
|
||||
# Give the new container ~60s to come up, then poll for
|
||||
# 200 from /healthz. Failure aborts the workflow.
|
||||
# Wait up to 60s for /healthz to return 200.
|
||||
for i in $(seq 1 12); do
|
||||
if curl -fsS "$HEALTH_URL" >/dev/null; then
|
||||
echo "deploy verified"
|
||||
exit 0
|
||||
fi
|
||||
curl -fsS "$HEALTH_URL" >/dev/null && exit 0
|
||||
sleep 5
|
||||
done
|
||||
echo "deploy verification failed"
|
||||
exit 1
|
||||
echo "deploy health check failed"; exit 1
|
||||
|
||||
Reference in New Issue
Block a user