Add containerized staging deployment
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
name: Validate and deploy staging
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: shd-build-staging
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Validate application
|
||||
run: npm run check
|
||||
|
||||
- name: Build Node application
|
||||
run: npm run build:app
|
||||
|
||||
deploy:
|
||||
needs: validate
|
||||
runs-on: stage-deploy
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install environment tooling
|
||||
run: npm ci
|
||||
|
||||
- name: Prepare deployment configuration
|
||||
env:
|
||||
DOTENV_PRIVATE_KEY_STAGING: ${{ secrets.DOTENV_PRIVATE_KEY_STAGING }}
|
||||
CONFIGURED_DEPLOY_PATH: ${{ vars.STAGE_DEPLOY_PATH }}
|
||||
CONFIGURED_STAGE_PORT: ${{ vars.STAGE_PORT }}
|
||||
COMMIT_SHA: ${{ gitea.sha }}
|
||||
run: |
|
||||
set -eu
|
||||
deployment_path="${CONFIGURED_DEPLOY_PATH:-/opt/shd-build-stage}"
|
||||
stage_port="${CONFIGURED_STAGE_PORT:-5569}"
|
||||
mkdir -p "$deployment_path"
|
||||
cp deploy/compose.staging.yml deploy/deploy-staging.sh deploy/bootstrap-staging.sh "$deployment_path/"
|
||||
DOTENV_PRIVATE_KEY_STAGING="$DOTENV_PRIVATE_KEY_STAGING" npx dotenvx decrypt -f .env.staging --stdout > "$deployment_path/.env.staging.runtime"
|
||||
printf 'SHD_IMAGE=shd-build-stage:%s\nSHD_STAGE_PORT=%s\n' "$COMMIT_SHA" "$stage_port" > "$deployment_path/.env.deploy"
|
||||
chmod 600 "$deployment_path/.env.staging.runtime" "$deployment_path/.env.deploy"
|
||||
chmod 755 "$deployment_path/deploy-staging.sh" "$deployment_path/bootstrap-staging.sh"
|
||||
|
||||
- name: Deploy staging
|
||||
env:
|
||||
CONFIGURED_DEPLOY_PATH: ${{ vars.STAGE_DEPLOY_PATH }}
|
||||
COMMIT_SHA: ${{ gitea.sha }}
|
||||
run: |
|
||||
deployment_path="${CONFIGURED_DEPLOY_PATH:-/opt/shd-build-stage}"
|
||||
"$deployment_path/deploy-staging.sh" "$deployment_path" "$GITHUB_WORKSPACE" "shd-build-stage:$COMMIT_SHA"
|
||||
|
||||
- name: Remove unused application images
|
||||
if: success()
|
||||
run: docker image prune --force --filter "label=org.opencontainers.image.title=shd-build"
|
||||
@@ -0,0 +1,43 @@
|
||||
name: Export staging ISAC data
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: shd-build-staging
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
export:
|
||||
runs-on: stage-deploy
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Export canonical ISAC data and uploaded icons
|
||||
env:
|
||||
CONFIGURED_DEPLOY_PATH: ${{ vars.STAGE_DEPLOY_PATH }}
|
||||
run: |
|
||||
set -eu
|
||||
deployment_path="${CONFIGURED_DEPLOY_PATH:-/opt/shd-build-stage}"
|
||||
compose_file="$deployment_path/compose.staging.yml"
|
||||
deploy_environment="$deployment_path/.env.deploy"
|
||||
compose() {
|
||||
docker compose --env-file "$deploy_environment" -f "$compose_file" "$@"
|
||||
}
|
||||
restart_services() {
|
||||
compose up -d --no-build app scheduler
|
||||
}
|
||||
trap restart_services EXIT
|
||||
snapshot_name="isac-stage-${GITHUB_RUN_ID}.json"
|
||||
compose stop scheduler app
|
||||
compose run --rm --no-deps app node scripts/isac-data-export.mjs "/app/data/exports/$snapshot_name"
|
||||
compose run --rm --no-deps -v "$GITHUB_WORKSPACE:/export" app \
|
||||
cp "/app/data/exports/$snapshot_name" /export/isac-stage.json
|
||||
|
||||
- name: Publish ISAC snapshot
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: shd-stage-isac-data
|
||||
path: isac-stage.json
|
||||
retention-days: 14
|
||||
Reference in New Issue
Block a user