Add Gitea deploy workflow, compose stack and health endpoint
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c39cb5562
commit
e9758499ff
13 files changed
+421
-2
No files matched your search
@@ -0,0 +1,134 @@
|
||||
# Builds the image on every push to main, pushes it to the Gitea registry (tagged
|
||||
# :latest AND the short commit SHA, for rollback) and deploys the stack on Unraid
|
||||
# from the repo's compose.yaml.
|
||||
#
|
||||
# The deploy works because the act_runner runs ON Unraid and hands its Docker
|
||||
# socket to the job: every `docker` command here talks to the Unraid daemon, so
|
||||
# absolute paths in compose.yaml (the /data bind mount) are host paths.
|
||||
#
|
||||
# Required repository secrets (Gitea -> repo -> Settings -> Actions -> Secrets):
|
||||
# REGISTRY_USER the registry username (e.g. Tom)
|
||||
# REGISTRY_TOKEN a Gitea access token with package:write -- NOT the password
|
||||
# FLYPAPER_ADMIN_PASSWORD the dashboard login password
|
||||
|
||||
name: Build and deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
# Docs alone change neither the image nor the stack.
|
||||
paths-ignore:
|
||||
- "docs/**"
|
||||
- "**/*.md"
|
||||
# Manual run from Gitea (Actions tab), e.g. to redeploy after a server restart.
|
||||
workflow_dispatch:
|
||||
|
||||
# Two quick pushes must not deploy over each other; the later one waits.
|
||||
concurrency:
|
||||
group: deploy-flypaper
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
IMAGE: gitea.anticarnist.de/tom/flypaper
|
||||
COMPOSE_VERSION: v2.39.4
|
||||
# Host folder of the /data volume and the UID of the image's app user.
|
||||
DATA_DIR: /mnt/user/appdata/flypaper
|
||||
APP_UID: "1654"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to the Gitea registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.anticarnist.de
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
# The short SHA names the image content unambiguously and never moves,
|
||||
# so it is the stable handle for a rollback.
|
||||
- name: Compute the short commit SHA
|
||||
id: sha
|
||||
run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push (:latest and :<sha>)
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE }}:latest
|
||||
${{ env.IMAGE }}:${{ steps.sha.outputs.short }}
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# The job image ships the Docker CLI (the build needs it) but not
|
||||
# necessarily the compose plugin; install a pinned one if it is missing.
|
||||
- name: Ensure docker compose
|
||||
run: |
|
||||
docker compose version && exit 0
|
||||
mkdir -p ~/.docker/cli-plugins
|
||||
curl -fsSL -o ~/.docker/cli-plugins/docker-compose \
|
||||
"https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-linux-x86_64"
|
||||
chmod +x ~/.docker/cli-plugins/docker-compose
|
||||
docker compose version
|
||||
|
||||
# The container runs as the image's app user, not as root. The folder lives
|
||||
# on the host, so a throwaway container creates it there and hands it to that
|
||||
# user -- on every deploy, so a reset by Unraid's "New Permissions" heals itself.
|
||||
- name: Prepare the data folder
|
||||
run: |
|
||||
docker run --rm -v "${DATA_DIR}:/data" busybox:1.37 \
|
||||
chown -R "${APP_UID}:${APP_UID}" /data
|
||||
|
||||
# The image is private; the pull below runs with this job's login.
|
||||
- name: Log in to the Gitea registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.anticarnist.de
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
# An explicit pull: `up` alone keeps a local :latest and would not notice
|
||||
# the image the build job just pushed.
|
||||
- name: Pull and start the stack
|
||||
env:
|
||||
FLYPAPER_ADMIN_PASSWORD: ${{ secrets.FLYPAPER_ADMIN_PASSWORD }}
|
||||
run: |
|
||||
docker compose -f compose.yaml pull
|
||||
docker compose -f compose.yaml up -d --wait --remove-orphans
|
||||
|
||||
# /health answers 200 only when the app runs AND reads its database. It is
|
||||
# checked from inside proxynet, the same way NPM reaches the app. The probe
|
||||
# comes from a private address, so /health is exempt from the trap even
|
||||
# though the Host header (flypaper) is unknown. A failure marks the run red;
|
||||
# the rollback stays a deliberate step.
|
||||
- name: Health gate
|
||||
run: |
|
||||
for attempt in $(seq 1 30); do
|
||||
if docker run --rm --network proxynet busybox:1.37 \
|
||||
wget -qO- http://flypaper:8080/health; then
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "flypaper did not report healthy within 60 seconds." >&2
|
||||
docker logs --tail 50 flypaper >&2
|
||||
exit 1
|
||||
|
||||
# Every deploy leaves the previous :latest behind as an untagged image. Only
|
||||
# untagged images go; a rollback pulls its :<sha> from the registry anyway.
|
||||
- name: Remove untagged images
|
||||
run: docker image prune -f
|
||||
Reference in new issue
Block a user