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
|
||||
# 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):
|
||||
# secrets.REGISTRY_TOKEN Gitea access token with package write access
|
||||
# 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_PATH directory on the server (default /opt/sorsfonalak)
|
||||
|
||||
@@ -14,7 +16,7 @@ name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
branches: [main, prod]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
@@ -77,11 +79,16 @@ jobs:
|
||||
run: |
|
||||
set -eu
|
||||
tag=$(echo "${{ github.sha }}" | cut -c1-12)
|
||||
extra="${{ github.ref_name }}"
|
||||
[ "$extra" = prod ] && extra="prod latest"
|
||||
build() {
|
||||
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: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 backend -f services/backend/Dockerfile .
|
||||
@@ -95,9 +102,12 @@ jobs:
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
if: vars.DEPLOY_HOST != ''
|
||||
if: github.ref == 'refs/heads/prod'
|
||||
runs-on: linux
|
||||
steps:
|
||||
- name: Check settings
|
||||
run: |
|
||||
[ -n "${{ vars.DEPLOY_HOST }}" ] || { echo "vars.DEPLOY_HOST is not set (Settings → Actions → Variables)" >&2; exit 1; }
|
||||
- name: Checkout
|
||||
run: |
|
||||
apk add --no-cache -q git openssh-client
|
||||
|
||||
Reference in New Issue
Block a user