Skip to content
Latchkey

How to Deploy a Multi-Service Preview Environment in GitHub Actions

Build each service image in a matrix, tag them with the PR SHA, then run one deploy that composes the whole stack into a single preview.

A realistic preview often needs several services. Build each image in parallel with a matrix, tag them by PR head SHA, and then deploy them together into one namespace so they can reach each other by service name.

Steps

  • Build each service image in a matrix, tagged with the PR SHA.
  • Push all images to the registry.
  • Run one deploy that installs the full stack into the preview namespace.

Workflow

.github/workflows/preview.yml
jobs:
  build:
    strategy:
      matrix:
        service: [web, api, worker]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: |
          docker build -t registry.example.com/${{ matrix.service }}:${{ github.event.pull_request.head.sha }} \
            ./services/${{ matrix.service }}
          docker push registry.example.com/${{ matrix.service }}:${{ github.event.pull_request.head.sha }}
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: |
          helm upgrade --install "pr-${{ github.event.pull_request.number }}" ./stack \
            --namespace "pr-${{ github.event.pull_request.number }}" \
            --set image.tag="${{ github.event.pull_request.head.sha }}"

Gotchas

  • Tag every service with the same PR SHA so the deploy pulls a consistent set.
  • Set resource limits per service so a multi-service preview does not starve the cluster.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →