feat: support custom tag-keys for non-standard YAML layouts
Adds tag-keys input (comma-separated) to update arbitrary YAML keys instead of just 'tag'. Handles unquoted values, quoted values, and YAML anchors (e.g. rustImageTag: &rustImageTag "value"). Makes image-repository optional when using custom tag-keys.
This commit is contained in:
@@ -1,72 +1,48 @@
|
||||
# actions-k8s
|
||||
|
||||
Reusable Gitea Actions for Kubernetes deployments via Flux GitOps.
|
||||
Reusable Gitea Actions for Kubernetes deployments.
|
||||
|
||||
## actions/flux-deploy
|
||||
## `flux-deploy`
|
||||
|
||||
Composite action that updates a [Flux HelmRelease](https://fluxcd.io/flux/components/helm/) image tag in a GitOps repo to trigger a Kubernetes deployment.
|
||||
Update a Flux HelmRelease image tag in a GitOps repo to trigger a Kubernetes deployment.
|
||||
|
||||
This action clones the GitOps repo, updates the `repository` and `tag` fields in the specified release YAML, commits, and pushes. If the release already points to the requested image, the action exits cleanly (idempotent).
|
||||
|
||||
### Usage
|
||||
### Usage (standard bjw-s app-template)
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ci]
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- name: Add SSH_KEY
|
||||
run: |
|
||||
echo "${{ secrets.SSH_KEY }}" > $HOME/.ssh/id_rsa
|
||||
chmod 400 $HOME/.ssh/id_rsa
|
||||
ssh-keyscan -H git.ericxliu.me > $HOME/.ssh/known_hosts
|
||||
- name: Deploy to K8s via Flux
|
||||
uses: https://git.ericxliu.me/eric/actions-k8s/.gitea/actions/flux-deploy@main
|
||||
with:
|
||||
image-repository: git.ericxliu.me/eric/my-app
|
||||
image-tag: ${{ steps.build.outputs.tag }}
|
||||
gitops-file: apps/myapp/my-app/release.yaml
|
||||
deploy-key: ${{ secrets.K8S_FLUX_DEPLOY_KEY }}
|
||||
```
|
||||
|
||||
- name: Checkout code
|
||||
uses: https://gitea.com/actions/checkout@v4
|
||||
with:
|
||||
ssh-key: ${{ secrets.SSH_KEY }}
|
||||
### Usage (custom tag keys — e.g. YAML anchors)
|
||||
|
||||
- name: Build and push image
|
||||
id: image
|
||||
uses: https://git.ericxliu.me/eric/actions-docker/.gitea/actions/docker-build@main
|
||||
with:
|
||||
image-name: ${{ github.event.repository.name }}
|
||||
push: true
|
||||
For non-standard layouts where image tags are stored in custom keys
|
||||
(e.g. `rustImageTag: &rustImageTag "2026-06-17-abc1234"`):
|
||||
|
||||
- name: Deploy to K8s via Flux
|
||||
uses: https://git.ericxliu.me/eric/actions-k8s/.gitea/actions/flux-deploy@main
|
||||
with:
|
||||
image-repository: ${{ github.server_url }}/${{ github.repository }}
|
||||
image-tag: ${{ steps.image.outputs.tag }}
|
||||
gitops-file: apps/myapp/my-app/release.yaml
|
||||
deploy-key: ${{ secrets.K8S_FLUX_DEPLOY_KEY }}
|
||||
```yaml
|
||||
- name: Deploy to K8s via Flux
|
||||
uses: https://git.ericxliu.me/eric/actions-k8s/.gitea/actions/flux-deploy@main
|
||||
with:
|
||||
image-tag: ${{ env.TAG }}
|
||||
tag-keys: rustImageTag,uiImageTag
|
||||
gitops-file: apps/myapp/stock-analyzer/release.yaml
|
||||
deploy-key: ${{ secrets.K8S_FLUX_DEPLOY_KEY }}
|
||||
```
|
||||
|
||||
### Inputs
|
||||
|
||||
| Input | Required | Default | Description |
|
||||
|-------|----------|---------|-------------|
|
||||
| `image-repository` | **Yes** | — | Full image repository (e.g. `git.ericxliu.me/eric/workout`) |
|
||||
| `image-tag` | **Yes** | — | Image tag to deploy (e.g. `2026-06-17-abc1234`) |
|
||||
|---|---|---|---|
|
||||
| `image-repository` | No | `""` | Full image repository to set in `repository:` fields. Optional when using `tag-keys`. |
|
||||
| `image-tag` | **Yes** | — | Image tag to deploy |
|
||||
| `tag-keys` | No | `tag` | Comma-separated YAML keys to update. Handles unquoted, quoted, and YAML anchor formats. |
|
||||
| `gitops-repo` | No | `git@github.com:eric-x-liu/k8s-flux.git` | SSH URL of the GitOps repo |
|
||||
| `gitops-file` | **Yes** | — | Path to release YAML in the GitOps repo |
|
||||
| `gitops-file` | **Yes** | — | Path to the release YAML in the GitOps repo |
|
||||
| `deploy-key` | **Yes** | — | SSH private key with push access to the GitOps repo |
|
||||
| `git-user-name` | No | `gitops-ci` | Git commit author name |
|
||||
| `git-user-email` | No | `gitops-ci@users.noreply.git.ericxliu.me` | Git commit author email |
|
||||
| `commit-message` | No | `Update {app} image to {tag}` | Custom commit message (`{app}` and `{tag}` are replaced) |
|
||||
|
||||
### How It Works
|
||||
|
||||
1. Sets up SSH with the provided deploy key
|
||||
2. Clones the GitOps repo (e.g. `k8s-flux`)
|
||||
3. Updates `repository:` and `tag:` fields in the specified release YAML via regex
|
||||
4. If no changes detected → exits cleanly (idempotent)
|
||||
5. Commits and pushes to trigger Flux reconciliation
|
||||
|
||||
### Requirements
|
||||
|
||||
- The GitOps repo must be accessible via SSH with the provided deploy key
|
||||
- The release YAML must contain `repository:` and `tag:` fields (standard bjw-s `app-template` chart format)
|
||||
- `python3` must be available on the runner (standard on `ubuntu-latest`)
|
||||
| `commit-message` | No | `Update {app} image to {tag}` | Custom commit message with `{app}` and `{tag}` placeholders |
|
||||
|
||||
Reference in New Issue
Block a user