diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 42db9bae..425b8ab3 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -1,118 +1,78 @@ +name: Publish static bundles + on: push: branches: [main] workflow_dispatch: concurrency: - group: deploy-main + group: publish-main cancel-in-progress: true jobs: - deploy: + publish: runs-on: docker container: image: node:24-bookworm timeout-minutes: 30 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.GARAGE_SITES_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.GARAGE_SITES_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: garage-sites + GARAGE_S3_ENDPOINT: https://s3-sites.bcgen.ie + NODE_OPTIONS: --max-old-space-size=768 + PUBLIC_ANALYTICS_DASHBOARD_URL: ${{ secrets.PUBLIC_ANALYTICS_DASHBOARD_URL }} + PUBLIC_CONTACT_FORM_ENDPOINT: ${{ secrets.PUBLIC_CONTACT_FORM_ENDPOINT }} + PUBLIC_CONTACT_RECIPIENTS: ${{ secrets.PUBLIC_CONTACT_RECIPIENTS }} + PUBLIC_CONTACT_SUBMISSIONS_URL: ${{ secrets.PUBLIC_CONTACT_SUBMISSIONS_URL }} + PUBLIC_PLAUSIBLE_DOMAIN: ${{ secrets.PUBLIC_PLAUSIBLE_DOMAIN }} + PUBLIC_PLAUSIBLE_SCRIPT_SRC: ${{ secrets.PUBLIC_PLAUSIBLE_SCRIPT_SRC }} steps: - - name: Install deploy tools + - uses: actions/checkout@v4 + + - name: Install build and S3 tools run: | set -eu apt-get update -qq - apt-get install -y -q ca-certificates curl git jq + apt-get install -y -q ca-certificates python3-venv + python3 -m venv /opt/awscli + /opt/awscli/bin/pip install --quiet awscli - - name: Build Astro and restart Nomad - env: - NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }} - NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }} - PUBLIC_ANALYTICS_DASHBOARD_URL: ${{ secrets.PUBLIC_ANALYTICS_DASHBOARD_URL }} - PUBLIC_CONTACT_FORM_ENDPOINT: ${{ secrets.PUBLIC_CONTACT_FORM_ENDPOINT }} - PUBLIC_CONTACT_RECIPIENTS: ${{ secrets.PUBLIC_CONTACT_RECIPIENTS }} - PUBLIC_CONTACT_SUBMISSIONS_URL: ${{ secrets.PUBLIC_CONTACT_SUBMISSIONS_URL }} - PUBLIC_PLAUSIBLE_DOMAIN: ${{ secrets.PUBLIC_PLAUSIBLE_DOMAIN }} - PUBLIC_PLAUSIBLE_SCRIPT_SRC: ${{ secrets.PUBLIC_PLAUSIBLE_SCRIPT_SRC }} - NODE_OPTIONS: --max-old-space-size=768 - REPO_URL: https://git.bcgen.ie/familyfedie/familyfedie-website.git + - name: Build and validate Astro output run: | set -eu - export REF_NAME="${GITHUB_REF_NAME:-main}" + npm ci --no-audit --no-fund + npm run check - git config --global http.lowSpeedLimit 1024 - git config --global http.lowSpeedTime 60 + - name: Split public and protected admin bundles + run: | + set -eu + rm -rf bundle-public bundle-admin + mkdir -p bundle-public bundle-admin/admin bundle-admin/css + cp -a dist/. bundle-public/ + rm -rf bundle-public/admin bundle-public/admin.html + test ! -e bundle-public/admin + test ! -e bundle-public/admin.html - for attempt in 1 2 3; do - echo "Cloning $REPO_URL ($REF_NAME), attempt $attempt/3" - rm -rf source - if timeout 180 git clone --depth 1 --branch "$REF_NAME" "$REPO_URL" source; then - break - fi - if [ "$attempt" -eq 3 ]; then - echo "git clone failed after 3 attempts" >&2 - exit 1 - fi - sleep $((attempt * 10)) - done + cp dist/admin/index.html bundle-admin/index.html + cp dist/admin/index.html bundle-admin/admin/index.html + cp -a dist/admin/content bundle-admin/admin/content + cp dist/css/admin.css bundle-admin/css/admin.css - cd source - npm config set fetch-retries 4 - npm config set fetch-retry-mintimeout 10000 - npm config set fetch-retry-maxtimeout 60000 - npm config set fetch-timeout 300000 + - name: Publish to Garage + run: | + set -eu + aws=/opt/awscli/bin/aws + common="--endpoint-url $GARAGE_S3_ENDPOINT --no-progress" - echo "Installing npm dependencies..." - timeout 600 npm ci --no-audit --no-fund - rm -rf dist - echo "Building Astro site..." - timeout 600 npm run build + $aws $common s3 sync bundle-public s3://familyfed.ie --delete \ + --cache-control 'public, max-age=3600, must-revalidate' + $aws $common s3 cp bundle-public s3://familyfed.ie --recursive \ + --exclude '*' --include '*.html' \ + --cache-control 'public, max-age=0, must-revalidate' + $aws $common s3 cp bundle-public s3://familyfed.ie --recursive \ + --exclude '*' --include '*.json' \ + --cache-control 'public, max-age=0, must-revalidate' - test -f dist/index.html - test -f dist/admin/index.html - test -f dist/speeches/index.html - test -f dist/assets/icons/familyfed-favicon.png - - export DEPLOY_MANIFEST="$( - cd dist - find . -type f -print0 \ - | LC_ALL=C sort -z \ - | xargs -0 sha256sum \ - | sha256sum \ - | awk '{print $1}' - )" - - export DEPLOY_COMMIT="${GITHUB_SHA:-$(git rev-parse HEAD)}" - echo "Registering Nomad deployment for $DEPLOY_COMMIT ($DEPLOY_MANIFEST)" - curl -fsS \ - --connect-timeout 15 \ - --max-time 60 \ - --retry 3 \ - --retry-delay 5 \ - --retry-all-errors \ - -H "X-Nomad-Token: $NOMAD_TOKEN" \ - "$NOMAD_ADDR/v1/job/familyfed" \ - | jq ' - (.TaskGroups[].Tasks[].Env //= {}) - | .TaskGroups[].Tasks[].Env.DEPLOY_COMMIT = env.DEPLOY_COMMIT - | ((.TaskGroups[].Tasks[] | select(.Name == "build-site") | .Config.args[]) |= - (sub("/archive/[0-9a-f]{40}\\.tar\\.gz"; - "/archive/" + env.DEPLOY_COMMIT + ".tar.gz") - | sub("test \"\\$actual_manifest\" = \"[0-9a-f]{64}\""; ":"))) - | (.TaskGroups[].Tasks[].Artifacts[]?.GetterSource |= - if startswith("git::") and test("[?&]ref=") then - sub("ref=[^&]*"; "ref=" + env.DEPLOY_COMMIT) - elif startswith("git::") then - . + (if contains("?") then "&" else "?" end) + "ref=" + env.DEPLOY_COMMIT - else . end) - | {Job: .} - ' \ - > /tmp/familyfed-job.json - - curl -fsS -X POST \ - --connect-timeout 15 \ - --max-time 60 \ - --retry 3 \ - --retry-delay 5 \ - --retry-all-errors \ - -H "Content-Type: application/json" \ - -H "X-Nomad-Token: $NOMAD_TOKEN" \ - --data-binary @/tmp/familyfed-job.json \ - "$NOMAD_ADDR/v1/jobs" - echo "Deploy registered. Nomad will replace the allocation and re-fetch the site." + $aws $common s3 sync bundle-admin s3://admin.familyfed.ie --delete \ + --cache-control 'private, max-age=0, must-revalidate' diff --git a/src/pages/admin/index.astro b/src/pages/admin/index.astro index 11378e5b..e9d4454b 100644 --- a/src/pages/admin/index.astro +++ b/src/pages/admin/index.astro @@ -55,7 +55,7 @@ const adminConfig = {
@@ -309,7 +309,7 @@ const adminConfig = {

Fill in the event details. The repository-ready snippet updates automatically as you type.

- View public calendar + View public calendar
@@ -417,7 +417,7 @@ const adminConfig = {

Search the archive, open an existing speech, or generate a new Markdown file.

- View speech archive + View speech archive