Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
groups:
github-actions:
patterns:
- "*"
68 changes: 42 additions & 26 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

- name: Log in to GHCR
uses: docker/login-action@v3
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push preview image
id: image
uses: docker/build-push-action@v6
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
push: true
build-args: |
GIT_SHA=${{ github.sha }}
tags: ghcr.io/${{ github.repository }}:pr-${{ github.event.pull_request.number }}-${{ github.sha }}

- name: Checkout repo for previews branch
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
path: gitops
Expand Down Expand Up @@ -106,43 +108,57 @@ jobs:
git push
fi

- name: Wait for preview to serve this revision
env:
PREVIEW_URL: https://pr-${{ github.event.pull_request.number }}.${{ env.PREVIEW_DOMAIN }}
EXPECTED_SHA: ${{ github.sha }}
TIMEOUT_SECONDS: "900"
run: |
set -uo pipefail
deadline=$((SECONDS + TIMEOUT_SECONDS))
while true; do
# Cache-buster + no-cache so we never read a stale cached response
served=$(curl -fsS --max-time 10 -H 'Cache-Control: no-cache' \
"${PREVIEW_URL}/version.txt?t=$(date +%s)" 2>/dev/null | tr -d '[:space:]') || served=""
if [ "$served" = "$EXPECTED_SHA" ]; then
if curl -fsS --max-time 10 -o /dev/null "${PREVIEW_URL}/"; then
echo "Preview at ${PREVIEW_URL} is serving ${EXPECTED_SHA}"
break
fi
echo "Revision matches but index page is not reachable yet"
else
echo "Preview not ready (served: '${served:-<unreachable>}', expected: ${EXPECTED_SHA})"
fi
if [ "$SECONDS" -ge "$deadline" ]; then
echo "::error::Timed out after ${TIMEOUT_SECONDS}s waiting for ${PREVIEW_URL} to serve ${EXPECTED_SHA}"
exit 1
fi
sleep 10
done

- name: Comment preview URL on PR
uses: actions/github-script@v7
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PREVIEW_URL: https://pr-${{ github.event.pull_request.number }}.${{ env.PREVIEW_DOMAIN }}
COMMIT_SHA: ${{ github.sha }}
with:
script: |
const marker = '<!-- pr-preview-comment -->';
const body = `${marker}\n🚀 Preview deployed: ${process.env.PREVIEW_URL}\n\nFlux will roll this out shortly after this comment appears.`;
const { data: comments } = await github.rest.issues.listComments({
const body = `${marker}\n🚀 Preview ready: ${process.env.PREVIEW_URL}\n\nVerified: the preview is serving commit ${process.env.COMMIT_SHA}.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}

cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -207,7 +223,7 @@ jobs:
fi

- name: Comment on PR
uses: actions/github-script@v7
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const marker = '<!-- pr-preview-comment -->';
Expand Down
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
FROM nginxinc/nginx-unprivileged:alpine
FROM nginx/nginx-unprivileged:1.31.8-alpine3.24-slim@sha256:629d3227f39ec10201345e420e2d9d430e463a9893d374b515a8eb6541e71938

ARG GIT_SHA=unknown

COPY images/ /usr/share/nginx/html/images/
COPY downloads/ /usr/share/nginx/html/downloads/
COPY migration/ /usr/share/nginx/html/migration/
COPY *.html *.css main.js /usr/share/nginx/html/

# Expose the built revision so deployments can be verified (see PR preview workflow).
COPY <<EOF /usr/share/nginx/html/version.txt
${GIT_SHA}
EOF

EXPOSE 8080
Loading