Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
1ef138b
ci: add k8s stack PR preview via labeled deploy + Cloudflare Tunnel
aktech Aug 3, 2026
72dab46
ci: temporarily trigger smoketest on this PR for iteration
aktech Aug 3, 2026
52d9f86
fix: move cloudflared --no-autoupdate flag before the run subcommand
aktech Aug 3, 2026
2818f48
ci: use single-level github.fyi hostnames for the preview tunnel
aktech Aug 3, 2026
fedb68f
ci: drop temporary pull_request trigger from smoketest workflow
aktech Aug 3, 2026
b22f710
fix: fetch chart dependencies before helm install in preview workflow
aktech Aug 3, 2026
1c7618a
ci: post smoketest URL as a PR comment via optional pr_number input
aktech Aug 3, 2026
0a75683
fix: register the jupyterhub chart repo before dependency build
aktech Aug 3, 2026
1eec127
fix: opt preview namespace into nic-operator management, add failure …
aktech Aug 3, 2026
17f723b
fix: disable nebariapp for preview deploy, hub crash-loops otherwise
aktech Aug 3, 2026
a43dfb7
fix: set jupyterhub.custom.external-url to the tunnel hostname
aktech Aug 3, 2026
57f1b00
Merge branch 'main' into add-k8s-preview-workflow
aktech Aug 5, 2026
a146616
ci: show deploy/expiry timestamps in preview PR comments
aktech Aug 5, 2026
c0ca336
Merge branch 'add-k8s-preview-workflow' of github.com:nebari-dev/neba…
aktech Aug 5, 2026
65651b4
fix: make tunnel creation idempotent, retries reuse the run_id
aktech Aug 5, 2026
774c0d6
Merge branch 'main' into add-k8s-preview-workflow
aktech Aug 31, 2026
74d3d49
ci: source preview domain from a repo Variable instead of hardcoding it
aktech Aug 31, 2026
71817f5
ci: switch preview domain to openteams.app, flatten per-PR hostname
aktech Aug 31, 2026
4919f73
ci: migrate k8s-preview to action-nebari-sandbox v3 (kind, not k3d)
aktech Aug 31, 2026
c849c85
ci: bump kind CLI to v0.33.0 in k8s-preview for containerd config v4
aktech Aug 31, 2026
cec54be
ci: always dump hub logs in k8s-preview to diagnose jhub-apps startup
aktech Aug 31, 2026
f577f6a
ci: smoke-test jhub-apps directly in k8s-preview before opening the t…
aktech Aug 31, 2026
10fa371
ci: capture hub logs after the tunnel closes, not just at startup
aktech Aug 31, 2026
26f7b65
ci: cache docker build, enable Keycloak auth, always start tmate debug
aktech Aug 31, 2026
d15efbc
ci: wait for the operator's Keycloak secret instead of blocking helm …
aktech Aug 31, 2026
2b6f1a9
ci: cover the keycloak namespace in the deploy-failure debug dump
aktech Aug 31, 2026
494eee4
ci: label the preview namespace so nic-operator actually reconciles it
aktech Aug 31, 2026
be49af8
docs: update k8s-preview comments to match the current auth setup
aktech Aug 31, 2026
daba573
ci: diagnose why the operator's issuer-url secret key comes back empty
aktech Aug 31, 2026
47e6606
ci: wait for issuer-url specifically, not just the secret's existence
aktech Aug 31, 2026
612f07d
ci: retry the hub restart until it actually picks up the operator secret
aktech Aug 31, 2026
b0c12f0
ci: fix the actual bug -- hub was mounting the wrong secret name
aktech Aug 31, 2026
0d041ce
ci: use --set-json for extraVolumes, not indexed --set
aktech Aug 31, 2026
0b2e76e
ci: expose Keycloak's own login page through a second tunnel route
aktech Aug 31, 2026
f925800
ci: point Keycloak's own hostname at the public route instead of rewr…
aktech Aug 31, 2026
c85f9b4
ci: fix Keycloak hostname via GitOps instead of a direct kubectl patch
aktech Aug 31, 2026
78b0086
ci: create a simple reviewer/admin test user in Keycloak
aktech Aug 31, 2026
6c96912
ci: route hub's Keycloak backchannel calls in-cluster, not through Ac…
aktech Aug 31, 2026
d5c27c7
fix: point jhub-apps' hub-API client at localhost, not the hub Service
aktech Aug 31, 2026
fdec180
fix: the env-dict override for JUPYTERHUB_API_URL doesn't survive spawn
aktech Aug 31, 2026
3ca96ef
ci: pre-fill email/name on the reviewer test user
aktech Aug 31, 2026
928adec
fix: the JUPYTERHUB_API_URL rewrite for jhub-apps never actually ran
aktech Aug 31, 2026
ba3fd45
ci: bound the tunnel step to 20min instead of the job timeout
aktech Sep 1, 2026
d284543
ci: add a GitHub Deployment for the preview, not just a comment
aktech Sep 1, 2026
044a28e
ci: fix the tunnel step's exit-124 handling under bash -e
aktech Sep 1, 2026
7371cc1
ci: replace the preview comment's prose with a Vercel-style table
aktech Sep 1, 2026
f2896bc
ci: fix the deployment table's Project column
aktech Sep 1, 2026
7b1df6a
ci: show a live-updating expiry time instead of a static UTC string
aktech Sep 1, 2026
26bbfe1
ci: update the preview comment again when it expires
aktech Sep 1, 2026
f6c9f4a
ci: extend the preview's lifetime in place via an extend-preview label
aktech Sep 1, 2026
6bdfafb
Merge branch 'main' into add-k8s-preview-workflow
aktech Sep 1, 2026
3693d08
ci: don't let extend-preview cancel the run it's meant to extend
aktech Sep 1, 2026
9ab529d
refactor: add a testable Python foundation for k8s-preview.yaml's CI …
aktech Sep 2, 2026
748e6d5
refactor: move Cloudflare Tunnel/DNS logic into scripts/preview/cloud…
aktech Sep 2, 2026
6844087
refactor: move Keycloak + k8s readiness logic into scripts/preview/
aktech Sep 2, 2026
037c993
refactor: move remaining GitHub API/comment logic into scripts/preview/
aktech Sep 2, 2026
9305abe
refactor: move the extend-preview tunnel loop into scripts/preview/tu…
aktech Sep 2, 2026
df6d007
ci: dump ArgoCD Application status on deploy failure
aktech Sep 2, 2026
148323a
ci: also dump cloudnative-pg's own ArgoCD Application status on failure
aktech Sep 3, 2026
30d7f6a
fix: update the PR comment's expiry when extend-preview actually exte…
aktech Sep 3, 2026
4a3dec5
fix: the comment-timer fix computed the new expiry from the wrong clock
aktech Sep 3, 2026
f1809b0
ci: trim every workflow comment and cap each action at ~4 lines
aktech Sep 4, 2026
f492690
test: remove 4 ceremonial CLI passthrough tests
aktech Sep 7, 2026
9256f2f
ci: remove the standalone tunnel smoketest workflow
aktech Sep 7, 2026
ed70518
ci: cut contrastive "X, not Y" padding from workflow comments
aktech Sep 7, 2026
2f76800
fix: "for 20 more minutes" read as cumulative, it isn't
aktech Sep 7, 2026
f2661e7
build: bump actions/checkout to v7.0.1, helm/kind-action to v1.15.0
aktech Sep 7, 2026
0d9d3e6
docs: trim redundant '(not cumulative)' aside in k8s-preview.yaml
aktech Sep 7, 2026
d3d3a2d
docs: move k8s-preview.yaml's comments into a PR Preview Environments…
aktech Sep 7, 2026
7ab009d
docs: lead with a How it works diagram, drop generic debugging sectio…
aktech Sep 7, 2026
23f8fa5
docs: cut implementation-detail aside from the intro paragraph
aktech Sep 7, 2026
269924d
feat: point preview deploys at the PR's own JupyterLab image build
aktech Sep 7, 2026
e50d1d3
docs: explain why the namespace label is manual here (ArgoCD does it …
aktech Sep 7, 2026
644529b
docs: frame the manual namespace label as a known gap, not a permanen…
aktech Sep 7, 2026
eec0b14
docs: explain why kind/kindnet can't hairpin a pod back to its own Se…
aktech Sep 7, 2026
4603e0d
docs: trim the hairpin-NAT comment down, no fluff
aktech Sep 7, 2026
1ef4c3f
docs: shrink the hairpin-NAT comment to a tweet, fix hub_connect_url …
aktech Sep 7, 2026
c751720
fix: disable prePuller.hook for preview deploys, it blocks install on…
aktech Sep 7, 2026
bd9dfc2
docs: state the exec-time-rewrite reason directly instead of via what…
aktech Sep 7, 2026
35ab2ae
docs: attribute the jhub-apps hub-API timeout to the hub NetworkPolic…
aktech Sep 7, 2026
11b307f
fix: put prePuller override at the jupyterhub level, it had swallowed…
aktech Sep 7, 2026
85b2fc3
fix: label the hub pod network-access-hub so jhub-apps can reach the …
aktech Sep 7, 2026
55980ee
refactor: use gh for the workflow's GitHub API steps, drop unused tun…
aktech Sep 7, 2026
4044005
test: drop tests that pin request shapes and constants instead of beh…
aktech Sep 7, 2026
839d712
test: drop the create-tunnel success test, it only pinned the request…
aktech Sep 7, 2026
91522fd
test: remove the scripts/preview unit tests and their injection seams
aktech Sep 7, 2026
7606a08
chore: drop unread tunnel_id output, gha path param, and unused PREVI…
aktech Sep 7, 2026
42ad288
feat: show reviewer credentials in the PR comment and docs; tunnel.py…
aktech Sep 7, 2026
8e3e646
docs: one-line why on the Keycloak hostname repoint
aktech Sep 7, 2026
d98ff4d
chore: drop the debug-dump script and its failure step, tmate covers it
aktech Sep 7, 2026
8d17fa9
chore: drop tmate and hub log-dump steps
aktech Sep 7, 2026
0c57d21
Merge branch 'main' into add-k8s-preview-workflow
aktech Sep 8, 2026
e1232ea
feat: keep main's pinned image as a second profile choice in previews
aktech Sep 8, 2026
00f666a
feat: deploying status comment with CI run link, Keycloak admin creds…
aktech Sep 8, 2026
c1b6816
refactor: tunnel.py talks to the GitHub API directly, run() split int…
aktech Sep 8, 2026
6e30d58
docs: deploying comment says ready in a few minutes
aktech Sep 8, 2026
3487d66
feat: remove the deploy-preview label when the preview ends
aktech Sep 8, 2026
cbc4cfd
fix: cascade-delete the tunnel and warn instead of silently swallowin…
aktech Sep 8, 2026
3c8e1bb
chore: rename the workflow to Deploy Preview
aktech Sep 8, 2026
6512f5e
chore: declare pr_image.py's dependency inline (PEP 723), run it with…
aktech Sep 8, 2026
101a7cb
fix: pr_image.py puts the repo root on sys.path itself, pipx run drop…
aktech Sep 8, 2026
bd6dcf2
docs: clarify the preview Keycloak reviewer account, drop implementat…
aktech Sep 8, 2026
8a4b8df
fix: pass the Keycloak admin password via env, post a failed-preview …
aktech Sep 8, 2026
5a57bb4
ci: skip preview deploys for fork PRs, drop the fork plumbing
aktech Sep 9, 2026
bd6e30d
docs: state the fork-PR skip with GitHub's own wording on secrets
aktech Sep 9, 2026
780e76c
docs: plain wording for why fork PRs are skipped
aktech Sep 9, 2026
db04576
ci: keep the pinned JupyterLab image when the PR has no pr-N tag
aktech Sep 9, 2026
a84bfd3
ci: preview profiles sized for the 4 vCPU runner, log resource summary
aktech Sep 9, 2026
699d8c7
ci: preview profile limits match their descriptions
aktech Sep 9, 2026
518c347
ci: preview profile limits and guarantees in the same ballpark
aktech Sep 9, 2026
9c66433
ci: let a newer preview run take over the comment and label
aktech Sep 9, 2026
6b300cf
ci: preview profiles get their image selector from the single pin
aktech Sep 10, 2026
081c220
ci: preview profiles get their image selector from the single pin
aktech Sep 10, 2026
992d8fe
Merge branch 'main' into add-k8s-preview-workflow
aktech Sep 18, 2026
6cdc581
ci: keep preview port-forwards alive, stop label events cancelling th…
aktech Sep 18, 2026
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
375 changes: 375 additions & 0 deletions .github/workflows/k8s-preview.yaml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export default defineConfig({
{ label: 'NebariApp Integration', slug: 'nebariapp-integration' },
],
},
{
label: 'Development',
items: [{ label: 'PR Preview Environments', slug: 'pr-preview-workflow' }],
},
],
}),
],
Expand Down
173 changes: 173 additions & 0 deletions docs/src/content/docs/pr-preview-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
title: PR Preview Environments
description: How the k8s-preview CI workflow deploys and exposes an ephemeral per-PR environment.
---

The `k8s-preview` GitHub Actions workflow
(`.github/workflows/k8s-preview.yaml`) deploys this PR's chart into an
ephemeral kind cluster running the full Nebari platform stack (Keycloak +
Nebari Operator + Envoy Gateway, via `nebari-dev/action-nebari-sandbox`),
then exposes it through a per-PR Cloudflare Tunnel behind Cloudflare Access
(GitHub SSO).

## How it works

```mermaid
flowchart TB
Label(["deploy-preview label added"]) --> Runner
subgraph Runner["GitHub Actions runner"]
Build["Build hub image\nfrom this PR"] --> Kind["kind cluster +\nKeycloak, Operator, Envoy Gateway"]
Kind --> Deploy["helm install\nthis PR's chart"]
Deploy --> PF["port-forward hub + Keycloak\nto runner localhost"]
PF --> Tunnel["cloudflared tunnel"]
end
Tunnel --> DNS["Cloudflare DNS record\npr-<n>-....<domain>"]
DNS --> Access["Cloudflare Access\n(GitHub SSO gate)"]
Runner -. posts .-> Comment["PR comment +\nGitHub Deployment"]
Reviewer(["Reviewer's browser"]) -->|opens the link| Access --> Tunnel
```

1. Labeling the PR `deploy-preview` starts the `deploy-preview` job.
2. It builds the hub image from this PR and boots a kind cluster running
Keycloak, the Nebari Operator, and Envoy Gateway
(`nebari-dev/action-nebari-sandbox`), then side-loads the built image
into it.
3. It points the chart's JupyterLab image at this PR's own build (see
"JupyterLab image" below), then installs the chart with
`helm upgrade --install`, patches Keycloak's own hostname to match the
public route, and waits for the Operator to finish provisioning the
OIDC client.
4. It port-forwards the hub and Keycloak services from the cluster to the
runner's `localhost`, starts a `cloudflared` tunnel mapping the public
preview hostnames to those local ports, and points a Cloudflare DNS
record at the tunnel. The tunnel step shows kubectl's output in its
log, restarts a port-forward that exits after it was forwarding (lost
connection to the pod), and fails the run if one exits before it ever
forwarded (kubectl's error says why).
5. It posts the preview URL as a GitHub Deployment and a PR comment.
6. A reviewer opening the link authenticates through Cloudflare Access
(GitHub SSO) before any request reaches the tunnel. Past Access, traffic
flows tunnel -> runner port-forward -> cluster service -> pod, and the
hub runs its own OAuth flow against Keycloak so it knows who signed in.
7. After 20 minutes (or on `extend-preview`/label removal), the tunnel
closes, the DNS record and tunnel are deleted, and the runner (with its
kind cluster) is torn down when the job ends.

## Triggering it

Add the `deploy-preview` label to a PR. That label gates who can trigger a
deploy (GitHub label permissions). Fork PRs are skipped: workflow runs
from forked repositories do not receive repository secrets. Removing the
label runs the `cleanup-preview` job, which cancels any in-flight deploy
for that PR, marks the GitHub deployment inactive, and posts a "stopped"
comment.
Pushing a new commit while the label is on cancels the in-flight deploy
and starts a fresh one. The fresh run starts only after the cancelled
run's cleanup (which updates the comment and drops the label) has
finished; it then puts the label back and takes the comment over. A
deploy cancelled any other way posts a "cancelled" comment and drops the
label.

Whether a finishing run updates the comment and drops the label depends
only on the label: present means the run still owns the preview, absent
means a person removed it and the `cleanup-preview` job owns it.

## Lifetime and the `extend-preview` label

A preview is live for 20 minutes by default (the tunnel step's own
timeout, kept under the job's 90-minute timeout so it self-ends cleanly
instead of GitHub reporting a false "cancelled" run). Adding the
`extend-preview` label resets the deadline to 20 minutes from that moment;
it can be added any number of times, but each add is a reset, not an
addition on top of what's left. The label is polled from inside the running
tunnel step (`scripts/preview/tunnel.py`), not by the workflow run the
label event starts. Only a push while `deploy-preview` is on, or a person
adding or removing `deploy-preview`, shares the PR's concurrency group.
Every other event gets a group of its own, so it can neither cancel the
live preview nor replace a queued stop or redeploy (a group keeps one
pending run). Label changes the workflow makes itself start no runs.

## Hostnames and TLS

Preview hostnames stay single-level
(`pr-<number>-data-science-pack.<domain>`): the free Cloudflare Universal
SSL certificate on the preview zone only covers the zone itself plus one
wildcard level.

## Authentication

`nebariapp.enabled=true` routes login through a real Operator-provisioned
Keycloak client, the same auth path production deployments use. The preview
Keycloak is a fresh realm with no users and no link to any external identity
provider, so the workflow seeds one account, `reviewer` / `admin`, for the
hub login. Cloudflare Access (GitHub sign-in) in front of the tunnel is the
actual security boundary, so a simple known password for that account is
acceptable.

## JupyterLab image

The hub image is built and side-loaded locally by this workflow, but the
JupyterLab image users actually spawn is built separately by
`build-images.yaml` (multi-arch, pushed to ghcr.io/quay.io on the same PR
trigger). `scripts/preview/pr_image.py` rewrites `values.yaml`'s
singleuser and per-profile image refs, in the ephemeral checkout only, to
that PR's `pr-<number>` tag before the chart deploys. If no such tag exists
on the registry, `values.yaml` is left as is and the preview runs the
pinned image.

The two builds aren't ordered against each other. A pod only pulls the
image when a reviewer actually spawns a server, by which point
`build-images.yaml` has usually finished; if not, kubelet retries the pull
automatically once the tag exists; no action is needed either way.

## Tunnel and GitHub visibility

- **Named Tunnel**: each PR gets its own named Cloudflare Tunnel sitting
behind Access, rather than an anonymous quick tunnel.
- **GitHub Deployment**: a Vercel-style deployment box is created via the
GitHub Deployments API, separate from the sticky PR comment (which
doesn't move once posted). `required_contexts: []` keeps this preview
link from gating on unrelated checks like lint or test.
- **Comment timestamps**: rendered with GitHub's `<relative-time>` web
component, so "Expires in 12 minutes" keeps ticking client-side with no
manual timezone math or re-editing needed.
- **On expiry**: the deployment is marked inactive and, if a "ready"
comment was posted, it's re-rendered to the expired state.
- **On failure**: if the deploy dies before a "ready" comment exists, or
the tunnel step fails after it (cloudflared exits, or a port-forward
cannot be restarted), the comment is re-rendered to a failed state linking
the run.

## One-time Cloudflare setup

Configured once in the Cloudflare Zero Trust dashboard for this repository:

- Repository variable `PREVIEW_DOMAIN`: the zone name (e.g.
`openteams.app`).
- A Cloudflare Access application for `*.<PREVIEW_DOMAIN>`, GitHub as the
identity provider, and a policy scoped to this org.
- Secret `CLOUDFLARE_TUNNEL_ACCOUNT_ID`: that Cloudflare account's ID.
- Secret `CLOUDFLARE_TUNNEL_API_TOKEN`: `Tunnel:Edit` + `Zone:Read` +
`DNS:Edit`, scoped to the `PREVIEW_DOMAIN` zone/account only. This is
separate from `CLOUDFLARE_API_TOKEN`, which belongs to the Pages account
used by `docs.yml`.

## Security model

- **Public exposure is gated before it reaches the cluster**: Cloudflare
Access sits in front of the tunnel and requires a GitHub SSO login plus
an org policy match before any request reaches `cloudflared`. Nothing in
the preview cluster is reachable without passing that gate.
- **kind shares the runner's Docker daemon**: a container escaping its pod
gets host-level Docker access on that ephemeral runner only, not on any
shared or production infrastructure, and the runner is destroyed with
the job.
- **Fork PRs are skipped**: workflow runs from forked repositories do not
receive repository secrets.
- **Token scope**: `GITHUB_TOKEN` is limited to `contents:read`,
`pull-requests:write`, `issues:write`, `deployments:write` for this job.
The Cloudflare API token can only edit Tunnels and DNS and read the zone,
scoped to the single `PREVIEW_DOMAIN` zone, not account-wide.
- **Nothing outlives the run**: the tunnel, its DNS record, the Keycloak
reviewer account, and the kind cluster all exist only for the job's
lifetime, or until the preview expires or is stopped early.
Loading
Loading