e128406790
- .forgejo/workflows/ci.yml: fast checks on every push (TS typecheck, Python lint via ruff, pytest) — no Docker build, ~30s with cache - .forgejo/workflows/build.yml: Docker build with registry-side layer caching + SSH deploy on main branch pushes only - pyproject.toml: add ruff to dev deps, configure pytest and ruff rules - tests/: conftest.py + first unit tests for _safe_filename (no DB needed) - Makefile: add lint, fmt, typecheck, test, check targets for local use Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.4 KiB
YAML
72 lines
2.4 KiB
YAML
# Runs only on pushes to main.
|
|
# Builds the Docker image, pushes it to the Forgejo container registry,
|
|
# then SSHes into the deploy host and restarts the service.
|
|
#
|
|
# Required secrets (set in Forgejo repo → Settings → Secrets):
|
|
# REGISTRY_USER — your Forgejo username
|
|
# REGISTRY_TOKEN — Forgejo personal access token (write:packages scope)
|
|
# DEPLOY_HOST — hostname or IP of the server running the app
|
|
# DEPLOY_USER — SSH username on that server
|
|
# DEPLOY_SSH_KEY — private SSH key (the public key must be in authorized_keys on the server)
|
|
# DEPLOY_PATH — absolute path to the directory containing docker-compose.yml
|
|
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: git.fabledsword.com
|
|
IMAGE: git.fabledsword.com/bvandeusen/fabledassistant
|
|
|
|
jobs:
|
|
build:
|
|
name: Build & push image
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Forgejo registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE }}:latest
|
|
${{ env.IMAGE }}:${{ github.sha }}
|
|
# Registry-side layer cache — dramatically speeds up rebuilds.
|
|
# On first run there is no cache so it builds cold; after that
|
|
# unchanged layers (npm install, pip install) are reused.
|
|
cache-from: type=registry,ref=${{ env.IMAGE }}:cache
|
|
cache-to: type=registry,ref=${{ env.IMAGE }}:cache,mode=max
|
|
|
|
deploy:
|
|
name: Deploy
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Pull new image and restart
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: ${{ secrets.DEPLOY_USER }}
|
|
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
script: |
|
|
set -e
|
|
cd ${{ secrets.DEPLOY_PATH }}
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.fabledsword.com \
|
|
-u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
docker compose pull app
|
|
docker compose up -d --no-build app
|
|
docker image prune -f
|