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
How to Generate Preview Environments With an Argo CD ApplicationSet in GitHub ActionsLet an Argo CD ApplicationSet pull request generator create and delete preview Applications automatically, wi…
How to Deploy a Preview for Only the Changed App in a Monorepo in GitHub ActionsDeploy a preview for just the app a pull request touched in a monorepo using a GitHub Actions paths filter or…