Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ on:
description: The repository within Github that holds the version file to deploy via GitOps
default: parcelLab/deployment
type: string
stagingDeploymentRepoRef:
required: false
description: Git ref or SHA for staging GitOps configuration (requires pushToEnvTag). Ignored outside staging; empty uses main.
default: ""
type: string
imageTargets:
required: false
description: If provided, sets targets for as many image builds as targets specified. When bakeFile is provided, these are Docker Buildx Bake targets.
Expand Down Expand Up @@ -169,6 +174,15 @@ jobs:
channel-id: ${{ steps.vars.outputs.channel-id }}
version: ${{ steps.vars.outputs.version }}
steps:
- name: Require an environment tag for staging configuration overrides
if: (github.event.deployment.payload.env || inputs.env) == 'staging' && inputs.stagingDeploymentRepoRef != ''
env:
PUSH_TO_ENV_TAG: ${{ format('{0}', github.event.deployment.payload.pushToEnvTag) == 'true' || inputs.pushToEnvTag }}
run: |
if [ "$PUSH_TO_ENV_TAG" != "true" ]; then
echo "::error::stagingDeploymentRepoRef requires pushToEnvTag to avoid pushing branch configuration to main"
exit 1
fi
- name: Check if 'env' input is provided
run: |
DEPLOY_ENV="${{ github.event.deployment.payload.env || inputs.env }}"
Expand Down Expand Up @@ -247,7 +261,7 @@ jobs:
repository: ${{ inputs.deploymentRepoURL }}
path: remote
token: ${{ secrets.repoAccessToken }}
ref: ${{ github.event.deployment.payload.rebuild != null && (github.event.deployment.payload.pushToEnvTag == 'true' || inputs.pushToEnvTag) && 'refs/tags/prod' || 'main' }}
ref: ${{ (github.event.deployment.payload.env || inputs.env) == 'staging' && inputs.stagingDeploymentRepoRef || (github.event.deployment.payload.rebuild != null && (github.event.deployment.payload.pushToEnvTag == 'true' || inputs.pushToEnvTag) && 'refs/tags/prod' || 'main') }}
- name: Refuse to replace a newer production release
if: github.event.deployment.payload.rebuild != null
uses: mikefarah/yq@v4.53.2
Expand Down Expand Up @@ -278,7 +292,7 @@ jobs:
GIT_USER_NAME: parcellab-dev-bot
ENV: ${{ github.event.deployment.payload.env || inputs.env }}
VERSION: ${{ needs.initialize.outputs.version }}
PUSH_TO_ENV_TAG: ${{ github.event.deployment.payload.pushToEnvTag || inputs.pushToEnvTag }}
PUSH_TO_ENV_TAG: ${{ format('{0}', github.event.deployment.payload.pushToEnvTag) == 'true' || inputs.pushToEnvTag }}
- if: success() && github.event_name == 'deployment'
name: Successful ${{ github.event.deployment.payload.name || inputs.appName }} deployment
uses: chrnorm/deployment-status@v2
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ the release tag or commit in `.chart/prod/values.yaml` (at the `prod` tag with `
with fresh base images and no cache. It deploys as `rebuild-<run-id>.<attempt>-<release>` and is skipped
if another release reaches production first.

## Staging configuration from a feature branch

`kubernetes.yaml` accepts `stagingDeploymentRepoRef` to select the GitOps configuration
revision for staging. When the deployment repository is the application repository,
pass the deployment SHA to use the chart and values from the same commit as the code:

```yaml
uses: parcelLab/ci/.github/workflows/kubernetes.yaml@v9
with:
deploymentRepoURL: parcelLab/backend
deploymentRepoPath: .chart/${{ github.event.deployment.payload.env }}
stagingDeploymentRepoRef: ${{ github.event.deployment.sha }}
```

This requires `pushToEnvTag: true` in the deployment payload or Kubernetes workflow
inputs. The workflow updates the image version on top of the selected revision and
pushes the `staging` tag, which ArgoCD must track. It fails before building if tag
publishing is disabled, to prevent pushing feature branch configuration to `main`.
The ref must exist in `deploymentRepoURL`; it does not select a revision in a
separate infrastructure repository or change the application build revision.

An empty ref keeps staging configuration on `main`. The input is ignored for all
other environments, including production and weekly production rebuilds.

## Contributing

[Contribution guidelines](CONTRIBUTING.md)
Loading