CI: deploy only from the prod branch
main builds images tagged with the commit hash and `main`; prod also tags `prod` and `latest` and deploys. A prod run without DEPLOY_HOST now fails instead of skipping silently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
+17
-7
@@ -1,12 +1,14 @@
|
|||||||
# Tests, image build and deployment on every push to main.
|
# main: tests and image build (tags: commit hash, `main`).
|
||||||
|
# prod: the same, then deployment to the server (tags: commit hash, `prod`, `latest`).
|
||||||
#
|
#
|
||||||
# Runs on the self-hosted runner in ci/runner (label `linux`). Jobs use the
|
# Runs on the self-hosted runner in ci/runner (label `linux`). Jobs use the
|
||||||
# host's Docker daemon, so image builds share its BuildKit cache.
|
# host's Docker daemon, so image builds share its BuildKit cache; a commit
|
||||||
|
# already built on main is rebuilt from cache in seconds.
|
||||||
#
|
#
|
||||||
# Repository settings (Settings → Actions):
|
# Repository settings (Settings → Actions):
|
||||||
# secrets.REGISTRY_TOKEN Gitea access token with package write access
|
# secrets.REGISTRY_TOKEN Gitea access token with package write access
|
||||||
# secrets.DEPLOY_SSH_KEY private key of the deploy user on the server
|
# secrets.DEPLOY_SSH_KEY private key of the deploy user on the server
|
||||||
# vars.DEPLOY_HOST user@host of the server; deployment is skipped when unset
|
# vars.DEPLOY_HOST user@host of the server
|
||||||
# vars.DEPLOY_KNOWN_HOSTS `ssh-keyscan <host>` output
|
# vars.DEPLOY_KNOWN_HOSTS `ssh-keyscan <host>` output
|
||||||
# vars.DEPLOY_PATH directory on the server (default /opt/sorsfonalak)
|
# vars.DEPLOY_PATH directory on the server (default /opt/sorsfonalak)
|
||||||
|
|
||||||
@@ -14,7 +16,7 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main, prod]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -77,11 +79,16 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
tag=$(echo "${{ github.sha }}" | cut -c1-12)
|
tag=$(echo "${{ github.sha }}" | cut -c1-12)
|
||||||
|
extra="${{ github.ref_name }}"
|
||||||
|
[ "$extra" = prod ] && extra="prod latest"
|
||||||
build() {
|
build() {
|
||||||
image="$IMAGE_PREFIX-$1"; shift
|
image="$IMAGE_PREFIX-$1"; shift
|
||||||
docker build --label sorsfonalak.ci=1 -t "$image:$tag" -t "$image:latest" "$@"
|
docker build --label sorsfonalak.ci=1 -t "$image:$tag" "$@"
|
||||||
docker push -q "$image:$tag"
|
docker push -q "$image:$tag"
|
||||||
docker push -q "$image:latest"
|
for t in $extra; do
|
||||||
|
docker tag "$image:$tag" "$image:$t"
|
||||||
|
docker push -q "$image:$t"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
build horoscope-api -f services/horoscope-api/Dockerfile .
|
build horoscope-api -f services/horoscope-api/Dockerfile .
|
||||||
build backend -f services/backend/Dockerfile .
|
build backend -f services/backend/Dockerfile .
|
||||||
@@ -95,9 +102,12 @@ jobs:
|
|||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: build
|
needs: build
|
||||||
if: vars.DEPLOY_HOST != ''
|
if: github.ref == 'refs/heads/prod'
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
steps:
|
steps:
|
||||||
|
- name: Check settings
|
||||||
|
run: |
|
||||||
|
[ -n "${{ vars.DEPLOY_HOST }}" ] || { echo "vars.DEPLOY_HOST is not set (Settings → Actions → Variables)" >&2; exit 1; }
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache -q git openssh-client
|
apk add --no-cache -q git openssh-client
|
||||||
|
|||||||
+8
-3
@@ -1,10 +1,15 @@
|
|||||||
# Build és telepítés
|
# Build és telepítés
|
||||||
|
|
||||||
Minden `main`-re pusholt commit után lefut a `.gitea/workflows/ci.yml` (Gitea Actions):
|
A `.gitea/workflows/ci.yml` (Gitea Actions) két ágra fut:
|
||||||
|
|
||||||
|
- **main**: tesztek, majd image-build. Címkék: a commit hash első 12 karaktere és `main`.
|
||||||
|
- **prod**: ugyanez, majd telepítés a szerverre. Címkék: hash, `prod` és `latest`. Élesíteni tehát úgy kell, hogy a main-t a prod-ba mergeled (vagy pusholod).
|
||||||
|
|
||||||
|
A lépések:
|
||||||
|
|
||||||
1. **test**: `cargo test` a backendre, a workerre, a db-re, a horoscope-clientre és a service-kitre, egy Postgres szolgáltatás-konténerrel.
|
1. **test**: `cargo test` a backendre, a workerre, a db-re, a horoscope-clientre és a service-kitre, egy Postgres szolgáltatás-konténerrel.
|
||||||
2. **build**: megépíti a négy image-et, és feltölti őket a `registry.sagifer.com/sagifer/sorsfonalak-<szolgáltatás>` címre. A címke a commit hash első 12 karaktere, plusz `latest`. A frontend buildje a TypeScript-típusokat is ellenőrzi.
|
2. **build**: megépíti a négy image-et, és feltölti őket a `registry.sagifer.com/sagifer/sorsfonalak-<szolgáltatás>` címre. A frontend buildje a TypeScript-típusokat is ellenőrzi. Egy main-en már megépült commit a cache-ből pár mp alatt újraépül.
|
||||||
3. **deploy** (csak ha a `DEPLOY_HOST` be van állítva): felmásolja a `docker-compose.yml`-t és a `Caddyfile`-t a szerverre, beírja az új `TAG`-et a szerveren lévő `.env`-be, majd `docker compose pull && up -d`. Az adatbázis-migrációk a backend indulásakor futnak le.
|
3. **deploy** (csak prod): felmásolja a `docker-compose.yml`-t és a `Caddyfile`-t a szerverre, beírja az új `TAG`-et a szerveren lévő `.env`-be, majd `docker compose pull && up -d`. Az adatbázis-migrációk a backend indulásakor futnak le.
|
||||||
|
|
||||||
Kézzel is indítható a repó Actions oldaláról (workflow_dispatch).
|
Kézzel is indítható a repó Actions oldaláról (workflow_dispatch).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user