185 lines
7.3 KiB
YAML
185 lines
7.3 KiB
YAML
name: Production container deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
paths-ignore:
|
|
- "docs/**"
|
|
- "**/*.md"
|
|
- ".beads/**"
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: production-${{ github.repository }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
NODE_VERSION: "22"
|
|
DOMAIN: videoreg.ru
|
|
STACK_NAME: videoreg
|
|
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
|
|
REGISTRY: ${{ vars.REGISTRY }}
|
|
PRODUCTION_TRAEFIK_NETWORK: ${{ vars.PRODUCTION_TRAEFIK_NETWORK }}
|
|
TRAEFIK_NETWORK: ${{ vars.TRAEFIK_NETWORK }}
|
|
TRAEFIK_ENTRYPOINTS: ${{ vars.TRAEFIK_ENTRYPOINTS }}
|
|
TRAEFIK_ENTRYPOINT: ${{ vars.TRAEFIK_ENTRYPOINT }}
|
|
TRAEFIK_TLS: ${{ vars.TRAEFIK_TLS }}
|
|
TRAEFIK_CERTRESOLVER: le
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
SWARM_MANAGER_HOST: ${{ vars.VIDEOREG_DEPLOY_HOST || '77.91.88.137' }}
|
|
SWARM_SSH_USER: ${{ vars.VIDEOREG_DEPLOY_USER || 'shire' }}
|
|
SWARM_SSH_PORT: ${{ vars.VIDEOREG_DEPLOY_PORT || '22' }}
|
|
|
|
jobs:
|
|
production:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node for build
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- name: Prepare deployment metadata
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
REGISTRY="${CONTAINER_REGISTRY:-${REGISTRY:-git.pryanik.synology.me}}"
|
|
: "${REGISTRY:?Set Gitea variable CONTAINER_REGISTRY or REGISTRY}"
|
|
: "${SWARM_MANAGER_HOST:?Set Gitea secret SWARM_MANAGER_HOST}"
|
|
: "${SWARM_SSH_USER:?Set Gitea secret SWARM_SSH_USER}"
|
|
|
|
short_sha="${GITHUB_SHA:-${GITEA_SHA:-manual}}"
|
|
short_sha="${short_sha:0:12}"
|
|
image_repo="${REGISTRY}/${GITHUB_REPOSITORY}"
|
|
|
|
{
|
|
echo "REGISTRY=${REGISTRY}"
|
|
echo "IMAGE_REPO=${image_repo}"
|
|
echo "IMAGE=${image_repo}:${short_sha}"
|
|
echo "SWARM_SSH_PORT=${SWARM_SSH_PORT:-22}"
|
|
network="${PRODUCTION_TRAEFIK_NETWORK:-${TRAEFIK_NETWORK:-traefik-public}}"
|
|
entrypoints="${TRAEFIK_ENTRYPOINTS:-${TRAEFIK_ENTRYPOINT:-websecure}}"
|
|
tls="${TRAEFIK_TLS:-true}"
|
|
echo "TRAEFIK_NETWORK=${network}"
|
|
echo "TRAEFIK_ENTRYPOINTS=${entrypoints}"
|
|
echo "TRAEFIK_TLS=${tls}"
|
|
echo "TRAEFIK_CERTRESOLVER=${TRAEFIK_CERTRESOLVER:-le}"
|
|
} >> "${GITHUB_ENV}"
|
|
|
|
- name: Install dependencies
|
|
run: npm ci --no-audit --no-fund
|
|
|
|
- name: Build static site
|
|
env:
|
|
NEXT_TELEMETRY_DISABLED: "1"
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: npm run ci:quality
|
|
|
|
- name: Restore exact five-role reviewed limited export
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
manifest=docs/rebuild-v2/releases/current.json
|
|
test -f "$manifest"
|
|
python3 deploy/release-artifact.py verify --manifest "$manifest" --restore --tree web-front/out
|
|
python3 - <<'PYIDENTITY' >> "$GITHUB_ENV"
|
|
import json
|
|
data = json.load(open('docs/rebuild-v2/releases/current.json'))
|
|
print('REVIEWED_SOURCE_COMMIT=' + data['sourceCommit'])
|
|
print('REVIEWED_EXPORT_SHA=' + data['exportManifestSha256'])
|
|
PYIDENTITY
|
|
- name: Verify published corpus without claiming complete history
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
python3 -S scripts/rebuild-v2/verify-vendor.py
|
|
node scripts/rebuild-v2/check-raster-sharp.mjs
|
|
python3 deploy/serve-local.py > "${RUNNER_TEMP}/videoreg-limited-preview.log" 2>&1 &
|
|
preview_pid=$!
|
|
trap 'kill "$preview_pid" 2>/dev/null || true' EXIT
|
|
base=$(python3 - "$preview_pid" <<'PYREADY'
|
|
import json, pathlib, sys, time, urllib.request
|
|
for attempt in range(50):
|
|
try:
|
|
state = json.loads(pathlib.Path('.local-run/server.json').read_text())
|
|
if state['pid'] == int(sys.argv[1]):
|
|
with urllib.request.urlopen(state['url'] + '/health/ready', timeout=1) as response:
|
|
if response.status == 200:
|
|
print(state['url']); break
|
|
except (OSError, ValueError, KeyError):
|
|
pass
|
|
time.sleep(0.1)
|
|
else:
|
|
raise SystemExit('Reviewed preview did not become ready')
|
|
PYREADY
|
|
)
|
|
python3 deploy/verify-published-corpus.py --manifest docs/rebuild-v2/releases/current.json --base "$base" --report "${RUNNER_TEMP}/videoreg-limited-fresh-crawl.json"
|
|
|
|
- name: Verify static output
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
test -f web-front/out/index.html
|
|
test ! -e web-front/out/server.js
|
|
test ! -e web-front/out/.next
|
|
printf 'Static files: '
|
|
find web-front/out -type f | wc -l
|
|
|
|
- name: Login to container registry
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
: "${REGISTRY_USERNAME:?Set Gitea secret REGISTRY_USERNAME}"
|
|
: "${REGISTRY_PASSWORD:?Set Gitea secret REGISTRY_PASSWORD}"
|
|
printf '%s' "${REGISTRY_PASSWORD}" | docker login "${REGISTRY}" \
|
|
--username "${REGISTRY_USERNAME}" \
|
|
--password-stdin
|
|
|
|
- name: Build static image
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
docker build --pull --platform linux/amd64 --build-arg BASE_IMAGE=git.pryanik.synology.me/huncode/videoreg.ru:9b5b080e6019@sha256:2fb63f2666d7c57643328aae1e76cdc5c3e498f704e007a7c57f2fecb033053e --label "org.opencontainers.image.revision=${REVIEWED_SOURCE_COMMIT}" --label "me.videoreg.export-sha256=${REVIEWED_EXPORT_SHA}" --label "me.videoreg.delivery-commit=${GITHUB_SHA}" --label "me.videoreg.scope=reviewed-corpus-only" --tag "${IMAGE}" .
|
|
test "$(docker image inspect "$IMAGE" --format '{{.Architecture}}')" = amd64
|
|
docker run --rm --entrypoint nginx "$IMAGE" -t
|
|
cid=$(docker create "$IMAGE")
|
|
trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT
|
|
docker cp "$cid:/usr/share/nginx/html/." - | python3 deploy/release-artifact.py image-tar --manifest docs/rebuild-v2/releases/current.json
|
|
|
|
- name: Push static image
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
docker push "${IMAGE}"
|
|
docker tag "${IMAGE}" "${IMAGE_REPO}:latest"
|
|
docker push "${IMAGE_REPO}:latest"
|
|
digest=$(docker image inspect "$IMAGE" --format '{{index .RepoDigests 0}}')
|
|
[[ "$digest" =~ @sha256:[a-f0-9]{64}$ ]]
|
|
echo "IMAGE=$digest" >> "$GITHUB_ENV"
|
|
|
|
- name: Configure remote Docker
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
docker_host="ssh://${SWARM_SSH_USER}@${SWARM_MANAGER_HOST}:${SWARM_SSH_PORT}"
|
|
DOCKER_SSH_COMMAND="ssh -o BatchMode=yes -o ConnectTimeout=10" docker --host "${docker_host}" info >/dev/null
|
|
echo "DOCKER_HOST=${docker_host}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Deploy production stack
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
docker stack deploy \
|
|
--with-registry-auth \
|
|
--compose-file deploy/stack.yml \
|
|
"${STACK_NAME}"
|
|
docker stack services "${STACK_NAME}"
|