πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: deploy preview deployments (#15020)
Max Deichmann01f652bca5b6
diff --git a/.github/actions/preview-comment/action.yml b/.github/actions/preview-comment/action.ymlnew file mode 100644index 0000000000..a5cd5548f7--- /dev/null+++ b/.github/actions/preview-comment/action.yml@@ -0,0 +1,54 @@+name: AWS preview status comment+description: >-+ Create or update the single marker-tagged AWS preview status comment on a+ pull request, so each PR carries exactly one authoritative preview comment.++inputs:+ pr-number:+ description: Pull request number+ required: true+ body:+ description: Comment body (the hidden marker is prepended automatically)+ required: true++runs:+ using: composite+ steps:+ - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0+ env:+ PREVIEW_PR_NUMBER: ${{ inputs.pr-number }}+ PREVIEW_COMMENT_BODY: ${{ inputs.body }}+ with:+ script: |+ const marker = "<!-- aws-preview -->";+ const issue_number = Number(process.env.PREVIEW_PR_NUMBER);+ const body = `${marker}\n${process.env.PREVIEW_COMMENT_BODY}`;++ const { owner, repo } = context.repo;+ const comments = await github.paginate(github.rest.issues.listComments, {+ owner,+ repo,+ issue_number,+ per_page: 100,+ });+ const previous = comments.find(+ (comment) =>+ comment.user?.login === "github-actions[bot]" &&+ comment.body?.includes(marker),+ );++ if (previous) {+ await github.rest.issues.updateComment({+ owner,+ repo,+ comment_id: previous.id,+ body,+ });+ } else {+ await github.rest.issues.createComment({+ owner,+ repo,+ issue_number,+ body,+ });+ }diff --git a/.github/workflows/preview-autolabel.yml b/.github/workflows/preview-autolabel.ymlnew file mode 100644index 0000000000..2b9fa96789--- /dev/null+++ b/.github/workflows/preview-autolabel.yml@@ -0,0 +1,65 @@+name: AWS preview auto-label++# Auto-apply the `preview` label to same-repo PRs opened by an allowlisted+# author, so the Argo CD ApplicationSet (in the infrastructure repo) picks them+# up and builds a preview. Anyone with write access can also apply the label+# by hand; the build workflow re-checks the PR author before building with a+# cloud credential, so a manual label from a non-allowlisted author is inert.+#+# Uses the plain `pull_request` trigger (NOT pull_request_target): it holds no+# cloud credentials, never checks out or executes PR code, and only calls+# issues.addLabels. The label is not a security boundary β the build workflow+# independently re-checks the PR author before using any credential β so+# pull_request_target's tamper-resistance isn't needed here, and avoiding it+# keeps this off the dangerous-triggers list. Same-repo PRs get a write token to+# add the label; fork PRs are short-circuited below (and get a read-only token).+on:+ pull_request:+ types: [opened, reopened]++permissions: {}++jobs:+ autolabel:+ name: Auto-label allowlisted PRs+ runs-on: ubuntu-latest+ if: vars.AWS_PREVIEW_ALLOWED_USERS != ''+ permissions:+ pull-requests: write+ steps:+ - name: Label allowlisted, same-repo PRs+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0+ env:+ ALLOWED_USERS: ${{ vars.AWS_PREVIEW_ALLOWED_USERS }}+ with:+ script: |+ const pr = context.payload.pull_request;+ const { owner, repo } = context.repo;++ // Same-repo only: fork PRs cannot mint an OIDC token, so the build+ // workflow could never push their image β an auto-labeled fork PR+ // would only create a broken environment.+ if (pr.head.repo.full_name !== `${owner}/${repo}`) {+ core.info("Fork PR; auto-label is limited to same-repo branches.");+ return;+ }++ // Exact-match allowlist (never substring β a login that is a+ // substring of an allowlisted one must not pass).+ const allowed = (process.env.ALLOWED_USERS || "")+ .split(/[\s,]+/)+ .filter(Boolean)+ .map((u) => u.toLowerCase());+ const author = pr.user.login.toLowerCase();+ if (!allowed.includes(author)) {+ core.info(`Author ${author} is not on the preview allowlist; skipping.`);+ return;+ }++ await github.rest.issues.addLabels({+ owner,+ repo,+ issue_number: pr.number,+ labels: ["preview"],+ });+ core.info(`Applied 'preview' label to PR #${pr.number} (author ${author}).`);diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.ymlnew file mode 100644index 0000000000..9d8fd723fe--- /dev/null+++ b/.github/workflows/preview-build.yml@@ -0,0 +1,201 @@+name: AWS preview build++# Build the PR's web + worker images and push them to ECR as pr-<n>-<sha>.+# The Argo CD ApplicationSet in the infrastructure repo deploys whichever image+# tag exists for a labeled PR; this workflow only builds and pushes, then posts+# the preview URL on the PR.+#+# Authorization is intentionally stricter than "the PR is labeled": the+# `preview` label can be applied by any org member, but this job builds the PR+# AUTHOR's code with an AWS (ECR push) credential, so it also requires the PR+# author to be on AWS_PREVIEW_ALLOWED_USERS. Fork PRs cannot mint an OIDC token+# (public repo, read-only token), so they can never push regardless β and the+# ECR-push role's trust policy is additionally scoped to+# sub=repo:langfuse/langfuse:pull_request AND ref=refs/pull/* (GitHub OIDC has no+# event_name claim), so pull_request_target / review β which carry the base+# branch ref β cannot assume it either.+on:+ pull_request:+ types: [labeled, synchronize, reopened]++permissions: {}++concurrency:+ group: preview-build-${{ github.event.pull_request.number }}+ cancel-in-progress: true++jobs:+ authorize:+ name: Authorize+ runs-on: ubuntu-latest+ # AWS_PREVIEW_ECR_PUSH_ROLE_ARN doubles as the feature flag: unset => the+ # whole workflow no-ops instead of failing on every labeled PR.+ if: >-+ vars.AWS_PREVIEW_ECR_PUSH_ROLE_ARN != '' &&+ contains(github.event.pull_request.labels.*.name, 'preview') &&+ github.event.pull_request.head.repo.full_name == github.repository+ permissions:+ pull-requests: read+ outputs:+ authorized: ${{ steps.gate.outputs.authorized }}+ steps:+ - name: Require an allowlisted PR author+ id: gate+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0+ env:+ ALLOWED_USERS: ${{ vars.AWS_PREVIEW_ALLOWED_USERS }}+ with:+ script: |+ const author = context.payload.pull_request.user.login.toLowerCase();+ const allowed = (process.env.ALLOWED_USERS || "")+ .split(/[\s,]+/)+ .filter(Boolean)+ .map((u) => u.toLowerCase());+ const ok = allowed.includes(author);+ if (!ok) {+ core.warning(+ `PR author ${author} is not on the preview allowlist; not building. ` ++ "Ask an admin to add the author to AWS_PREVIEW_ALLOWED_USERS.",+ );+ }+ core.setOutput("authorized", ok ? "true" : "false");++ build:+ name: Build and push preview images+ needs: authorize+ if: needs.authorize.outputs.authorized == 'true'+ runs-on: blacksmith-4vcpu-ubuntu-2404+ permissions:+ contents: read+ id-token: write+ pull-requests: write+ steps:+ - name: Checkout PR head (build context only)+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3+ with:+ persist-credentials: false+ ref: ${{ github.event.pull_request.head.sha }}++ - name: Resolve image tags and preview metadata+ id: meta+ env:+ PR_NUMBER: ${{ github.event.pull_request.number }}+ WEB_REPO: ${{ vars.AWS_PREVIEW_WEB_ECR_REPOSITORY_URL }}+ WORKER_REPO: ${{ vars.AWS_PREVIEW_WORKER_ECR_REPOSITORY_URL }}+ DOMAIN_NAME: ${{ vars.AWS_PREVIEW_DOMAIN_NAME }}+ run: |+ set -euo pipefail+ commit_sha="$(git rev-parse HEAD)"+ short_sha="${commit_sha:0:12}"+ # The ApplicationSet deploys pr-<n>-{{.head_sha}} β Argo's FULL 40-char+ # SHA β so the pushed tag MUST use the full SHA or the deployed image+ # never resolves (permanent ImagePullBackOff). short_sha is display-only.+ image_tag="pr-${PR_NUMBER}-${commit_sha}"+ {+ echo "commit_sha=${commit_sha}"+ echo "image_tag=${image_tag}"+ echo "web_image=${WEB_REPO}:${image_tag}"+ echo "worker_image=${WORKER_REPO}:${image_tag}"+ echo "preview_host=pr-${PR_NUMBER}.${DOMAIN_NAME}"+ # Shared, intentionally-public seed login + API keys (synthetic data+ # only) β must match the LANGFUSE_INIT_* values in the preview chart+ # (k8s/preview/chart/values.yaml). Each preview is its own isolated+ # DB, so a shared seed identity is fine. The real crypto secrets+ # (ENCRYPTION_KEY/SALT/NEXTAUTH, DB passwords) are generated randomly+ # in-cluster by the chart's pre-sync hook and never leave the namespace.+ echo "[email protected]"+ echo "login_password=langfuse-preview"+ echo "public_key=pk-lf-preview"+ echo "secret_key=sk-lf-preview"+ } >> "$GITHUB_OUTPUT"++ - name: Mark preview building+ uses: ./.github/actions/preview-comment+ with:+ pr-number: ${{ github.event.pull_request.number }}+ body: |+ ### π‘ AWS preview building++ Building images for `${{ steps.meta.outputs.commit_sha }}` (~5 min).+ Argo CD deploys the preview once the push completes; it may briefly+ show `ImagePullBackOff` until this image propagates.++ - name: Configure AWS credentials+ uses: aws-actions/configure-aws-credentials@e7f100cf4c008499ea8adda475de1042d6975c7b # v6.2.0+ with:+ aws-region: ${{ vars.AWS_PREVIEW_REGION }}+ role-to-assume: ${{ vars.AWS_PREVIEW_ECR_PUSH_ROLE_ARN }}++ - name: Login to AWS ECR+ uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2.1.6++ - name: Build and push preview images+ env:+ COMMIT_SHA: ${{ steps.meta.outputs.commit_sha }}+ WEB_IMAGE: ${{ steps.meta.outputs.web_image }}+ WORKER_IMAGE: ${{ steps.meta.outputs.worker_image }}+ run: |+ set -euo pipefail++ # The preview ECR repos are tag-IMMUTABLE, so re-pushing an existing+ # tag fails. Tags embed the commit SHA, so an existing tag is byte-for-+ # byte the same image β skip build+push if it is already there (this+ # makes workflow re-runs on an unchanged commit idempotent).+ image_present() {+ local image="$1" repo tag+ repo="${image%:*}"; repo="${repo##*/}"+ tag="${image##*:}"+ aws ecr describe-images --repository-name "${repo}" \+ --image-ids imageTag="${tag}" >/dev/null 2>&1+ }++ if image_present "${WEB_IMAGE}"; then+ echo "${WEB_IMAGE} already present β skipping."+ else+ docker build \+ --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \+ --build-arg NEXT_PUBLIC_SIGN_UP_DISABLED=true \+ -f ./web/Dockerfile \+ -t "${WEB_IMAGE}" \+ .+ docker push "${WEB_IMAGE}"+ fi++ if image_present "${WORKER_IMAGE}"; then+ echo "${WORKER_IMAGE} already present β skipping."+ else+ docker build \+ --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \+ -f ./worker/Dockerfile \+ -t "${WORKER_IMAGE}" \+ .+ docker push "${WORKER_IMAGE}"+ fi++ - name: Mark preview image pushed+ uses: ./.github/actions/preview-comment+ with:+ pr-number: ${{ github.event.pull_request.number }}+ body: |+ ### π’ AWS preview image pushed++ Argo CD is rolling it out β the environment is usually ready within a+ few minutes of this comment.++ **URL:** https://${{ steps.meta.outputs.preview_host }}+ **Login:** `${{ steps.meta.outputs.login_email }}` / `${{ steps.meta.outputs.login_password }}`+ **API keys:** `${{ steps.meta.outputs.public_key }}` / `${{ steps.meta.outputs.secret_key }}`+ **Commit:** ${{ steps.meta.outputs.commit_sha }}++ Synthetic preview data only β never enter a real credential. Remove+ the `preview` label or close the PR to destroy the environment.++ - name: Report failure+ if: failure()+ uses: ./.github/actions/preview-comment+ with:+ pr-number: ${{ github.event.pull_request.number }}+ body: |+ ### β οΈ AWS preview build failed++ The image build/push failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}