Your favorite shift management application!
feat(ci): move preview hosts to bs-pr-<n> (#222)
panteL3cf5430cdba3
diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.ymlindex a2398b9..cd23a88 100644--- a/.github/workflows/pr-preview.yml+++ b/.github/workflows/pr-preview.yml@@ -19,6 +19,10 @@ permissions:env:PREVIEW_LABEL: previewSTACK_COMMENT_MARKER: "<!-- pr-preview -->"+ # Hostname prefix, not the image tag: previews live at+ # <prefix>-<n>.<PREVIEW_DOMAIN>, while ghcr.io keeps its pr-<n> tags.+ # Inherited by every step, so scripts/preview-stack.mjs reads the same value.+ PREVIEW_HOST_PREFIX: bs-prjobs:fork-notice:@@ -146,7 +150,7 @@ jobs:- name: Wait for the instanceenv:- URL: https://pr-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}+ URL: https://${{ env.PREVIEW_HOST_PREFIX }}-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}BASIC_PASSWORD: ${{ secrets.PREVIEW_BASIC_AUTH_PASSWORD }}CF_BYPASS: ${{ secrets.PREVIEW_CF_BYPASS_TOKEN }}run: |@@ -180,7 +184,7 @@ jobs:- name: Seed the demo dataenv:- PREVIEW_URL: https://pr-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}+ PREVIEW_URL: https://${{ env.PREVIEW_HOST_PREFIX }}-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}PREVIEW_BASIC_AUTH_PASSWORD: ${{ secrets.PREVIEW_BASIC_AUTH_PASSWORD }}PREVIEW_ADMIN_EMAIL: admin@${{ vars.PREVIEW_DOMAIN }}PREVIEW_MEMBER_EMAIL: member@${{ vars.PREVIEW_DOMAIN }}@@ -192,7 +196,7 @@ jobs:env:GH_TOKEN: ${{ github.token }}PR: ${{ github.event.number }}- URL: https://pr-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}+ URL: https://${{ env.PREVIEW_HOST_PREFIX }}-${{ github.event.number }}.${{ vars.PREVIEW_DOMAIN }}ADMIN_EMAIL: admin@${{ vars.PREVIEW_DOMAIN }}MEMBER_EMAIL: member@${{ vars.PREVIEW_DOMAIN }}ADMIN_PASSWORD: ${{ secrets.PREVIEW_ADMIN_PASSWORD }}diff --git a/docs/PR_PREVIEWS.md b/docs/PR_PREVIEWS.mdindex ab56313..320af1c 100644--- a/docs/PR_PREVIEWS.md+++ b/docs/PR_PREVIEWS.md@@ -18,7 +18,7 @@ This guide explains the automated preview environments BetterShift spins up for## What It Does-Adding the `preview` label to a pull request from this repository gets it a running, seeded BetterShift instance at `https://pr-<number>.<PREVIEW_DOMAIN>`. Usually that takes a few minutes; in the worst case it takes considerably longer, because the deploy job first waits for the PR's image to finish building — that wait alone is allowed to run for up to 25 minutes. Every further push to the PR (a `synchronize` event) redeploys it from scratch: the old container and its data are destroyed first, so the instance always reflects the latest commit and starts from a clean, freshly seeded database.+Adding the `preview` label to a pull request from this repository gets it a running, seeded BetterShift instance at `https://bs-pr-<number>.<PREVIEW_DOMAIN>`. Usually that takes a few minutes; in the worst case it takes considerably longer, because the deploy job first waits for the PR's image to finish building — that wait alone is allowed to run for up to 25 minutes. Every further push to the PR (a `synchronize` event) redeploys it from scratch: the old container and its data are destroyed first, so the instance always reflects the latest commit and starts from a clean, freshly seeded database.Closing a PR that carries the `preview` label, or removing the label again, tears the instance down completely — container and data, nothing left behind. Closing a PR that never had the label does nothing: the `teardown` job checks for the label on the `closed` event and skips itself otherwise, so it doesn't go looking for a stack that was never created. Reopening a closed PR that still carries the `preview` label deploys it again, the same way a `synchronize` push does: fresh container, freshly reseeded database.@@ -140,7 +140,7 @@ Leaving `PREVIEW_CF_BYPASS_TOKEN` unset is fine for a host that isn't behind CloThe header is a shared secret, not authentication — anyone who learns it can skip the WAF for those hostnames. Komodo's own API key and the Basic Auth in front of every preview instance still apply behind it.-Two details of the generated compose file are worth knowing before the first deploy. The site label is written as `caddy: http://pr-<n>.<PREVIEW_DOMAIN>` — the explicit scheme keeps Caddy from starting automatic HTTPS for a name that resolves to Cloudflare rather than to the server, which behind a TLS-terminating proxy ends in a redirect loop or a certificate order that can never complete.+Two details of the generated compose file are worth knowing before the first deploy. The site label is written as `caddy: http://bs-pr-<n>.<PREVIEW_DOMAIN>` — the explicit scheme keeps Caddy from starting automatic HTTPS for a name that resolves to Cloudflare rather than to the server, which behind a TLS-terminating proxy ends in a redirect loop or a certificate order that can never complete.## How the Pieces Fit Togetherdiff --git a/scripts/preview-stack.mjs b/scripts/preview-stack.mjsindex d0715f6..e690595 100644--- a/scripts/preview-stack.mjs+++ b/scripts/preview-stack.mjs@@ -169,7 +169,7 @@ function escapeEnvValue(value) {function stackConfig() {const pr = process.env.PR_NUMBER;- const host = `pr-${pr}.${process.env.PREVIEW_DOMAIN}`;+ const host = `${process.env.PREVIEW_HOST_PREFIX || "bs-pr"}-${pr}.${process.env.PREVIEW_DOMAIN}`;return {server_id: process.env.KOMODO_SERVER_ID,project_name: `bettershift-pr-${pr}`,