Skip to content
Skip to Content

Deploy from CI

Deploy from GitHub Actions or GitLab CI with an API key, after your tests pass, with the CLI or with the API alone.

Your CI can deploy a service once its tests pass. It signs in with an API key in OPENPANEL_TOKEN and runs openpanel deploy, or calls the API directly. The CLI in CI page lists what the CLI reads and prints there.

1. Make an API key for CI

Make the key while signed in as yourself (openpanel login), since a key cannot make other keys. Give it the deploy scope and only the project it deploys:

openpanel keys create --name "GitHub Actions" --scope deploy --project shop

The key is printed once. The key acts as you, never with more access than you have, and stops working if you leave the organization. See Authentication.

2. Store it in your CI

CIWhere
GitHub ActionsRepository, Settings, Secrets and variables, Actions: a repository secret named OPENPANEL_TOKEN.
GitLab CIProject, Settings, CI/CD, Variables: a variable named OPENPANEL_TOKEN, masked and protected.

3. Deploy

A service built from Git

Deploy the exact commit your CI tested with --commit, and wait for the result with --wait: the step fails when the deployment fails.

.github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    timeout-minutes: 50
    steps:
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npx --yes https://cdn.openpanel.sh/cli/0.2.0/openpanel-cli-0.2.0.tgz deploy web --project shop --commit "$GITHUB_SHA" --wait
        env:
          OPENPANEL_TOKEN: ${{ secrets.OPENPANEL_TOKEN }}

To deploy only after your tests, put this job after them with needs:.

An image you build in CI

Build and push the image, point the service at the new tag, then deploy. The image must be public, since your servers pull without signing in to a registry: on GitHub, check the package's visibility in its settings.

.github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v7
      - run: |
          echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
          docker build -t "ghcr.io/acme/shop:$GITHUB_SHA" .
          docker push "ghcr.io/acme/shop:$GITHUB_SHA"
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: |
          npx --yes https://cdn.openpanel.sh/cli/0.2.0/openpanel-cli-0.2.0.tgz services update web --project shop --image "ghcr.io/acme/shop:$GITHUB_SHA"
          npx --yes https://cdn.openpanel.sh/cli/0.2.0/openpanel-cli-0.2.0.tgz deploy web --project shop --wait
        env:
          OPENPANEL_TOKEN: ${{ secrets.OPENPANEL_TOKEN }}

Tagging each image with its commit keeps every tag pointing at one build, so a rollback runs exactly what ran before.

Without the CLI

The same deploy with curl and jq, which GitHub's Ubuntu runners have. It starts the deployment, then reads it every five seconds until it runs or fails:

deployment=$(curl -sS --fail-with-body -X POST "https://openpanel.sh/api/v1/services/$SERVICE_ID/deployments" \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"commit\": \"$GITHUB_SHA\"}") || { echo "$deployment"; exit 1; }
id=$(echo "$deployment" | jq -r .id)

while true; do
  status=$(curl -sS --fail-with-body "https://openpanel.sh/api/v1/deployments/$id" \
    -H "Authorization: Bearer $OPENPANEL_TOKEN" | jq -r .status)
  echo "$status"
  case "$status" in
    running|superseded|cancelled) exit 0 ;;
    failed) exit 1 ;;
  esac
  sleep 5
done

$SERVICE_ID is the service's id, from openpanel services get web --project shop. For an image service, leave out the Content-Type and -d lines. When OpenPanel refuses the deploy, the step prints its answer, which says why. See Deploy a service and Get a deployment.

How long a deploy can take

A build on your server can run for 30 minutes, and a rollout then has 15 minutes to become ready; past either, OpenPanel marks the deployment failed. A job that waits for a Git service may wait about 45 minutes in the worst case, which is why the first workflow sets timeout-minutes: 50. An image service skips the build, so its rollout's 15 minutes are the most it waits on OpenPanel.