Helm Docs

Set Up PR Previews for Your Backend

A PR preview is a short-lived copy of your backend, with its own empty database and its own web address, that Helm starts for a pull request or a branch. Your team and your test apps can use it to try a change before it is merged. This page explains what your backend repository needs, which settings to fill in, and how to ask for a preview from GitHub Actions.

Who this is for: Changing the preview settings needs the Project Admin role or higher. Connecting GitHub needs an Owner or Admin of the Helm organization. Preparing the repository and the GitHub Actions workflow needs a developer.

What you're about to do, in plain English

Each preview runs in its own virtual machine: a separate computer, running in software, that no other preview shares. Helm starts the virtual machine, copies one branch of your backend repository from GitHub into it, and runs your repository's Docker Compose file there. A Docker Compose file, usually called docker-compose.yml, lists the containers your backend needs, such as the app, its database, a cache and a background worker, and how to start them. A container is an isolated, packaged copy of a program with everything it needs to run.

Helm provides the virtual machine, Docker and Docker Compose, your project's variables and secrets, two variables of its own (PREVIEW_DOMAIN and PREVIEW_URL), the route from the preview's address to your web service, and the memory and processor limits. Your Compose file provides everything else, including the database.

When your web service answers, Helm gives the preview a public address that ends in .preview.helmcode.dev, for example tastyspread-pr-118-x7k2q9.preview.helmcode.dev. The preview stays up until someone tears it down, the pull request is closed or the branch is deleted, or its lifetime runs out.

Setup has four parts:

  1. Your repository — add a Docker Compose file that starts your whole backend.
  2. GitHub — connect your GitHub account to Helm so Helm can read the repository.
  3. Helm — fill in the preview settings for your project.
  4. GitHub Actions — add a workflow that asks Helm for a preview, waits for it, and tears it down at the end.

Step 1 — Add a Compose file to your backend repository

Helm starts your backend the same way every time, with no manual steps, so the repository has to contain everything needed to build and start it.

  • A Docker Compose file, on every branch that will be previewed, including the fallback branch (see Step 3). Helm looks for docker-compose.yml at the top of the repository unless you set another path.
  • Every service the preview needs, including the database. Helm adds none.
  • A web service, called app unless you set another name, with a build: section or an image:, that listens on 0.0.0.0 at the App Port (8000 unless you change it) and answers GET / with any status below 500.
  • No env_file or environment entries for your portal variables. Helm places every variable and secret you set in the portal, plus PREVIEW_DOMAIN and PREVIEW_URL, in every container; see "How variables reach your preview" below.
  • The settings your app needs, such as DEBUG, ALLOWED_HOSTS and the database address, set in the Compose file. Helm no longer sets them.
  • No settings that previews refuse, such as privileged or host networking.

Write the Compose File explains each point, lists the refused settings and why, and gives a complete example for a Django backend with PostgreSQL, Redis and a Celery worker.

Where your preview runs

WhatEach preview gets
Processor2 cores, 64-bit x86 (linux/amd64)
Memory4 GiB, shared by every service in your Compose file
Disk40 GiB, shared by the images, the volumes and everything the services write
  • Data is temporary. Everything the services write, including the database, is deleted when the preview is rebuilt or torn down.
  • The internet works; private networks do not. The preview can call third-party APIs and send webhooks, but it cannot reach your company's own network, other previews or any private address. See "Network access" in Preview Lifecycle.
  • The public address. Helm publishes your web service's App Port at https://<name>.preview.helmcode.dev once it answers. HTTPS ends at Helm, so your service receives plain HTTP.
  • Startup time. A small stack is typically ready a few minutes after the request. Building large images, or downloading a lot during the build, takes longer. Everything must be running within 20 minutes.

Step 2 — Connect GitHub

Helm reads your code through the Helm GitHub App. An Owner or Admin of your Helm organization clicks Connect GitHub in Company settings → GitHub, which installs the App on the GitHub account that owns your repositories and links that account to your Helm organization. Then a Project Admin ticks the project's repositories on the project's Settings → GitHub tab; every step, including what to do when a GitHub organization owner must approve the App, is in Connect GitHub for PR Previews.

Step 3 — Fill in the preview settings

These settings tell Helm which Compose file to run, which service answers web traffic, and which repository to copy.

  1. Open your project in Helm and click Settings in the sidebar.
  2. Under Build, click Preview Environments.
  3. In Compose File Path, enter the path to your Compose file from the top of the repository. Leave it at docker-compose.yml if that is where your file is.
  4. In Web Service, enter the name of the service in your Compose file that answers web traffic. Leave it at app if that is its name.
  5. In App Port, enter the port that service listens on inside its container. Leave it at 8000 if that is the port it uses.
  6. In Pre-deploy Command, enter the command that creates your database tables, for example docker compose run --rm --build app python manage.py migrate --noinput. Leave Start Command and First-deploy Command empty unless you need them; see Preview Commands.
  7. In Backend Repo URL, enter the GitHub address of your backend repository, for example https://github.com/your-org/your-backend.

    Helm always copies this repository, whichever repository asked for the preview. A pull request in your iOS app gets a preview of the backend.

  8. In Fallback Branch, enter the backend branch to use when there is no backend branch with the same name as the branch that asked for the preview, for example staging or development. If you leave it empty, Helm uses staging.

  9. Click Save Changes. The page shows "Settings saved successfully."

The same tab holds the Container Environment Variables card, where you add your project's variables and secrets, such as SECRET_KEY; see Preview Variables. Every field is described in Preview Settings Reference.

How variables reach your preview

  • Every variable and secret you set in the portal, plus PREVIEW_DOMAIN and PREVIEW_URL, is placed in the environment of every container of your Compose file, including third-party images such as postgres and redis. Helm does this by adding its own env file to every service, so your Compose file does not need env_file or environment entries for them.
  • A value written under environment: in your Compose file wins over a portal value. To let the portal override a default, write it as NAME: ${NAME:-default}.
  • Avoid portal variable names that third-party images read (for example POSTGRES_PASSWORD, POSTGRES_DB, REDIS_PASSWORD, PORT) unless you mean the value for those containers too.
  • The same variables are available to ${NAME} substitution in the Compose file and to the pre-deploy, start and first-deploy commands.

Which branch Helm uses

  • If the backend repository has a branch with exactly the same name as the branch that asked for the preview, Helm uses that branch. To preview a backend change together with an app change, give both branches the same name.
  • Otherwise, Helm uses the Fallback Branch.
  • If Helm cannot check the backend repository's branches, for example because GitHub could not be reached, it uses the Fallback Branch. If the backend repository's GitHub account is not connected at all, Helm refuses the preview instead.
  • When the request names a commit of the backend repository itself, Helm uses that commit. Otherwise it uses the newest commit on the branch.

Step 4 — Ask for a preview from GitHub Actions

Your workflow asks for a preview with one web request to Helm's API (the address programs use to talk to Helm). To prove who is asking, the workflow sends a short-lived OIDC token: a signed note from GitHub that names the repository and the run. No Helm password needs to be stored in GitHub.

The requests

RequestWhat it does
POST https://app.helmcode.dev/api/previews/Asks for a new preview. Helm answers 201 with the preview's id.
GET https://app.helmcode.dev/api/previews/<id>/Returns the preview's status, its address in base_url once it is ready, and error_message if it failed.
POST https://app.helmcode.dev/api/previews/<id>/teardown/Tears the preview down. It takes no body and answers 200. A pinned preview is not torn down: Helm answers 409 with {"error": "preview_pinned", "code": "preview_pinned", "message": "This preview environment is pinned. Unpin it before tearing it down."}. See "Pinning a preview" in Preview Lifecycle.

The body of the POST /api/previews/ request is JSON with these fields:

  • platform (required) — which of your apps is asking: ios, android or backend.
  • branch and pr_number — the branch and the pull request number. Send at least one of them. A new request for a pull request that already has a preview replaces that preview.
  • commit_sha (optional) — the commit to build. Helm uses it only when the request comes from the backend repository itself.
  • project (optional) — your Helm project's short name. Send it only when several of your projects list the same repository.
  • start_timeout_minutes (optional) — how long this preview may take to start, from 5 to 60 minutes. Leave it out to use the project's Start timeout (minutes) setting. A rebuild of the preview keeps it, and so does a later request for the same pull request that leaves it out.

Each request carries the header Authorization: Bearer <token>. The token is either a GitHub Actions OIDC token made for the audience https://app.helmcode.dev, or your project's API key. An OIDC token lasts only a few minutes, so ask for a fresh one before each request.

Note: The same requests also work at https://helmcode.dev/api/, and Helm also accepts the audience https://helmcode.dev. New set-ups use https://app.helmcode.dev. Workflows, apps and connectors that already use https://helmcode.dev keep working; you do not need to change them.

Helm accepts an OIDC token when the repository named in it is in your project's GitHub Repos setting and its GitHub account is connected to your organization (Step 2). A preview asked for with an OIDC token can be read or torn down only with a token from the same repository, or with the project's API key.

A workflow you can copy

This workflow asks for a preview when a pull request opens or changes, waits until it is ready, runs your tests against it, and tears it down when the run ends, even if a test failed. It needs curl and python3, which GitHub's ubuntu-latest runners have. Change platform to match your app, and replace the test job with your own.

name: PR preview
on:
  pull_request:

permissions:
  id-token: write   # lets the jobs ask GitHub for an OIDC token
  contents: read

env:
  HELM_API_URL: https://app.helmcode.dev/api

jobs:
  preview:
    runs-on: ubuntu-latest
    outputs:
      preview_id: ${{ steps.create.outputs.preview_id }}
      preview_url: ${{ steps.wait.outputs.preview_url }}
    steps:
      - name: Ask Helm for a preview
        id: create
        env:
          BRANCH: ${{ github.head_ref || github.ref_name }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: |
          TOKEN=$(curl -s -H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
            "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://app.helmcode.dev" \
            | python3 -c "import sys,json; print(json.load(sys.stdin)['value'])")
          BODY=$(python3 -c "import json,os; print(json.dumps({'platform': 'ios', 'branch': os.environ['BRANCH'], 'pr_number': int(os.environ['PR_NUMBER'] or 0) or None}))")
          RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${HELM_API_URL}/previews/" \
            -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" -d "${BODY}")
          CODE=$(echo "$RESPONSE" | tail -1); JSON=$(echo "$RESPONSE" | sed '$d')
          [ "$CODE" = "201" ] || { echo "::error::Preview request failed (HTTP $CODE): $JSON"; exit 1; }
          echo "preview_id=$(echo "$JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")" >> "$GITHUB_OUTPUT"

      - name: Wait until the preview is ready
        id: wait
        env:
          PREVIEW_ID: ${{ steps.create.outputs.preview_id }}
        run: |
          for i in $(seq 1 120); do
            TOKEN=$(curl -s -H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
              "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://app.helmcode.dev" \
              | python3 -c "import sys,json; print(json.load(sys.stdin)['value'])")
            JSON=$(curl -s -H "Authorization: Bearer ${TOKEN}" "${HELM_API_URL}/previews/${PREVIEW_ID}/")
            STATUS=$(echo "$JSON" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status') or '')")
            echo "Preview status: ${STATUS}"
            if [ "$STATUS" = "ready" ]; then
              echo "preview_url=$(echo "$JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['base_url'])")" >> "$GITHUB_OUTPUT"
              exit 0
            fi
            if [ "$STATUS" = "failed" ] || [ "$STATUS" = "destroyed" ]; then
              echo "::error::Preview ${STATUS}: $(echo "$JSON" | python3 -c "import sys,json; print(json.load(sys.stdin).get('error_message') or '')")"
              exit 1
            fi
            sleep 20
          done
          echo "::error::The preview was not ready after 40 minutes"; exit 1

  test:
    needs: preview
    runs-on: ubuntu-latest
    steps:
      - name: Check the preview answers
        env:
          PREVIEW_URL: ${{ needs.preview.outputs.preview_url }}
        run: curl -fsS "${PREVIEW_URL}/" > /dev/null

  teardown:
    needs: [preview, test]
    # Run even when a job before it failed, but only when a preview was created.
    if: ${{ always() && needs.preview.outputs.preview_id != '' }}
    runs-on: ubuntu-latest
    steps:
      - name: Tear down the preview
        env:
          PREVIEW_ID: ${{ needs.preview.outputs.preview_id }}
        run: |
          TOKEN=$(curl -s -H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
            "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://app.helmcode.dev" \
            | python3 -c "import sys,json; print(json.load(sys.stdin)['value'])")
          RESPONSE=$(mktemp)
          CODE=$(curl -s -o "$RESPONSE" -w "%{http_code}" -X POST \
            "${HELM_API_URL}/previews/${PREVIEW_ID}/teardown/" -H "Authorization: Bearer ${TOKEN}")
          echo "Teardown answered HTTP ${CODE}"
          # A pinned preview is kept on purpose: Helm answers 409 preview_pinned.
          if [ "$CODE" = "409" ] && grep -q '"preview_pinned"' "$RESPONSE"; then
            echo "Preview is pinned; left running"
            exit 0
          fi
          [ "$CODE" = "200" ]

The values reach each script through env: rather than being written into the script, so nothing in a branch name can run as a shell command. When someone has pinned the preview, the teardown job logs "Preview is pinned; left running" and succeeds, so the run does not fail because a person chose to keep the preview.

Using the project API key instead

Older workflows use the project's API key instead of an OIDC token. It keeps working on every preview request.

  1. In Helm, open your project's Settings, click API Keys, and click Generate Key. Copy the key.
  2. In GitHub, open the repository's Settings, then Secrets and variables → Actions, and add a repository secret named HELM_API_TOKEN holding the key.
  3. In the workflow, drop the TOKEN=$(...) lines, add HELM_API_TOKEN: ${{ secrets.HELM_API_TOKEN }} under each step's env:, and send -H "Authorization: Bearer ${HELM_API_TOKEN}". The workflow then needs no id-token: write permission.
Warning: An API key can create and tear down any preview of the project. Store it only as a GitHub secret, never in the workflow file. If it leaks, click Revoke next to it on the API Keys tab and generate a new one.

Step 5 — Check the preview

Besides the status request above, you can follow every preview in Helm.

  1. Open your project in Helm and click PR Previews in the sidebar.
  2. Each preview shows its status, its branch or pull request, and its address once it is ready. A failed preview shows the reason.
  3. Use the row's Actions menu to open the preview, copy its address, Rebuild it or Teardown it. You can also start a preview by hand with Create preview: name a branch of the backend repository, which must exist. Every part of the screen is explained in The PR Previews Page.

To test a mobile app against the preview, build the app with the preview's address and send it to your testers through Helm; see Pointing a build at a PR preview backend.

The status moves through pending_submit, submitted, queued and provisioning to ready. It ends at failed if the preview could not be built or started, and at destroyed after teardown (cancel_requested and draining appear on the way). For what happens after that, see Preview Lifecycle.

Troubleshooting

The request answers 401 with invalid_oidc_token

The token has expired, is not a GitHub Actions token, or was made for another audience. Ask for a fresh token, in the same job, with audience=https://app.helmcode.dev, and check that the workflow has permissions: id-token: write.

403 with no_matching_project

No project in your organization lists the repository that sent the token, or its GitHub account is not connected. Add the repository to the project's GitHub Repos setting, and check that Company settings → GitHub shows the account as connected.

409 with project_required

Several of your projects list the same repository. Add "project": "your-project" to the request body.

409 with preview_limit_reached

Your organization already has as many previews as it may have at once. Tear down a preview you no longer need and try again. See "Limits" in Preview Lifecycle.

422 with github_owner_not_linked, or the preview fails with github_app_not_installed

Helm cannot read the backend repository. Connect its GitHub account in Company settings → GitHub → Connect GitHub, and make sure the repository is selected in the Helm App's Repository access on GitHub.

The reason starts "Helm refused this preview's settings or Compose file"

A preview setting or your Compose file broke a rule, and the rest of the reason names the setting or the service. For a service that asks for a setting previews refuse, or a Compose file Helm could not read, see "Settings Helm refuses, and why" in Write the Compose File. Fix the setting or the file, then click Rebuild.

The reason says the Compose file was not found

The branch Helm used has no file at the Compose File Path. Check which branch was used (the Fallback Branch is used when no backend branch has the same name), and add the file to it or correct the path.

The preview fails with build_failed

An image in your Compose file did not build. A step in a Dockerfile failed, a download was for the wrong processor type (not amd64, also called x86_64), or the build took too long. Run DOCKER_DEFAULT_PLATFORM=linux/amd64 docker compose build on your computer and fix the first error. An exec format error means an ARM program or base image was used.

The preview fails with predeploy_failed or first_deploy_failed

One of your commands exited with an error. The reason ends with the last lines it printed. See the Troubleshooting section of Preview Commands.

The preview fails with readiness_failed

Helm could not get an answer below 500 from GET / on the web service's App Port.

  • With "connection refused" or "EOF": the web service listens on another port or only on 127.0.0.1, or it crashed at start, often because a variable is missing. Listen on 0.0.0.0 at the App Port, check the Web Service name, and check that a value under the service's environment: is not replacing a portal variable the app needs.
  • With "app returned 500": the app runs but / fails, often because the database tables were not created. Set a Pre-deploy Command that runs your migrations.
  • With a TLS or https error: the app redirects HTTP to HTTPS. Turn the redirect off in previews.

Reading a failed preview's logs

The reason on the PR Previews page is the first place to look. Helm also keeps the output of docker compose up, of each command and of every service when a preview fails; contact Helm support with the preview's address to see them. See "Read a failed preview's reason and logs" in Write the Compose File.

The preview fails with vm_image_unavailable, vm_boot_failed, guest_timeout or guest_failed

Helm could not start or reach the preview's virtual machine. This is not caused by your repository. Click Rebuild on the PR Previews page to try again as a new preview, and contact Helm support if it happens again.

The preview stays Queued

The preview is waiting for room on Helm's preview machines. If it is still Queued after 15 minutes, tear it down and request it again. If that does not help, contact Helm support with the preview's address; they check that the preview machines are online and have room, and that nothing on Helm's side is holding the request back.

The preview shows "Internal server error: Helm couldn't create this preview right now."

The problem is on Helm's side, not in your repository. Try again later, and contact Helm support if it keeps happening.