68 lines
2.3 KiB
YAML
68 lines
2.3 KiB
YAML
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 }}
|
|
BUILD_NUMBER: ${{ gitea.run_number }}
|
|
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\nSHD_BUILD_NUMBER=%s\n' "$COMMIT_SHA" "$stage_port" "$BUILD_NUMBER" > "$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"
|