Skip to content

Commit 3185c5b

Browse files
author
gurghet
committed
feat: add Helm chart and automated releases
BREAKING CHANGE: The operator now uses github-token secret instead of ghcr-secret. - Add Helm chart for easy installation - Add GitHub Actions workflow for automated releases - Add semantic-release configuration - Update operator to use github-token secret - Add comprehensive documentation
1 parent 8b2e00e commit 3185c5b

11 files changed

Lines changed: 476 additions & 4 deletions

File tree

.github/workflows/release.yaml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
if: github.event_name != 'pull_request'
19+
permissions:
20+
contents: write
21+
issues: write
22+
pull-requests: write
23+
packages: write
24+
25+
outputs:
26+
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
27+
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Setup Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 'lts/*'
39+
40+
- name: Install semantic-release
41+
run: |
42+
npm install -g semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github
43+
44+
- name: Create Release
45+
id: semantic
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: npx semantic-release
49+
50+
build-and-push:
51+
needs: release
52+
if: needs.release.outputs.new_release_published == 'true'
53+
runs-on: ubuntu-latest
54+
permissions:
55+
contents: read
56+
packages: write
57+
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
- name: Log in to GitHub Container Registry
66+
uses: docker/login-action@v3
67+
with:
68+
registry: ${{ env.REGISTRY }}
69+
username: ${{ github.actor }}
70+
password: ${{ secrets.GITHUB_TOKEN }}
71+
72+
- name: Extract metadata for Docker
73+
id: meta
74+
uses: docker/metadata-action@v5
75+
with:
76+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
77+
tags: |
78+
type=semver,pattern={{version}},value=v${{ needs.release.outputs.new_release_version }}
79+
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.release.outputs.new_release_version }}
80+
type=raw,value=latest
81+
82+
- name: Build and push Docker image
83+
uses: docker/build-push-action@v5
84+
with:
85+
context: .
86+
push: true
87+
tags: ${{ steps.meta.outputs.tags }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
cache-from: type=gha
90+
cache-to: type=gha,mode=max
91+
92+
release-chart:
93+
needs: [release, build-and-push]
94+
if: needs.release.outputs.new_release_published == 'true'
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: write
98+
pages: write
99+
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v4
103+
with:
104+
fetch-depth: 0
105+
106+
- name: Configure Git
107+
run: |
108+
git config user.name "$GITHUB_ACTOR"
109+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
110+
111+
- name: Install Helm
112+
uses: azure/setup-helm@v3
113+
114+
- name: Update chart version
115+
env:
116+
VERSION: ${{ needs.release.outputs.new_release_version }}
117+
run: |
118+
yq e -i '.version = env(VERSION)' charts/github-deploy-key-operator/Chart.yaml
119+
yq e -i '.appVersion = env(VERSION)' charts/github-deploy-key-operator/Chart.yaml
120+
121+
- name: Package Helm chart
122+
run: |
123+
helm package charts/github-deploy-key-operator
124+
125+
- name: Setup GitHub Pages
126+
uses: actions/configure-pages@v4
127+
128+
- name: Upload GitHub Pages artifact
129+
uses: actions/upload-pages-artifact@v3
130+
with:
131+
path: '.'
132+
133+
- name: Deploy GitHub Pages
134+
uses: actions/deploy-pages@v4
135+
136+
- name: Upload chart to release
137+
uses: softprops/action-gh-release@v1
138+
with:
139+
tag_name: v${{ needs.release.outputs.new_release_version }}
140+
files: github-deploy-key-operator-*.tgz
141+
generate_release_notes: true

.releaserc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"branches": ["master"],
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
"@semantic-release/github"
7+
]
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2
2+
name: github-deploy-key-operator
3+
description: A Kubernetes operator that manages GitHub deploy keys
4+
type: application
5+
version: 0.1.0
6+
appVersion: "latest"
7+
maintainers:
8+
- name: gurghet
9+
keywords:
10+
- github
11+
- deploy-key
12+
- operator
13+
- flux
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# GitHub Deploy Key Operator Helm Chart
2+
3+
This Helm chart installs the GitHub Deploy Key Operator in your Kubernetes cluster.
4+
5+
## Prerequisites
6+
7+
- Kubernetes 1.16+
8+
- Helm 3.0+
9+
- A GitHub token with appropriate permissions
10+
11+
## Installation
12+
13+
### Add the Helm Repository
14+
15+
```bash
16+
helm repo add github-deploy-key-operator https://gurghet.github.io/github-deploy-key-operator
17+
helm repo update
18+
```
19+
20+
### Install the Chart
21+
22+
1. Using a new GitHub token:
23+
24+
```bash
25+
helm install github-deploy-key-operator github-deploy-key-operator/github-deploy-key-operator \
26+
--set github.token=<your-github-token>
27+
```
28+
29+
2. Using an existing secret:
30+
31+
```bash
32+
helm install github-deploy-key-operator github-deploy-key-operator/github-deploy-key-operator \
33+
--set github.existingSecret=my-github-secret \
34+
--set github.existingSecretKey=GITHUB_TOKEN
35+
```
36+
37+
## Configuration
38+
39+
| Parameter | Description | Default |
40+
|-----------|-------------|---------|
41+
| `replicaCount` | Number of operator replicas | `1` |
42+
| `image.repository` | Image repository | `ghcr.io/gurghet/github-deploy-key-operator` |
43+
| `image.tag` | Image tag | `latest` |
44+
| `image.pullPolicy` | Image pull policy | `Always` |
45+
| `github.existingSecret` | Name of existing secret with GitHub token | `""` |
46+
| `github.existingSecretKey` | Key in existing secret for GitHub token | `"GITHUB_TOKEN"` |
47+
| `github.token` | GitHub token (if not using existing secret) | `""` |
48+
| `serviceAccount.create` | Create service account | `true` |
49+
| `serviceAccount.name` | Service account name | `""` |
50+
| `podSecurityContext` | Pod security context | See values.yaml |
51+
| `securityContext` | Container security context | See values.yaml |
52+
| `resources` | Pod resource requests/limits | `{}` |
53+
| `nodeSelector` | Node selector | `{}` |
54+
| `tolerations` | Pod tolerations | `[]` |
55+
| `affinity` | Pod affinity | `{}` |
56+
57+
## Usage with Flux
58+
59+
```yaml
60+
apiVersion: helm.toolkit.fluxcd.io/v2beta1
61+
kind: HelmRelease
62+
metadata:
63+
name: github-deploy-key-operator
64+
namespace: flux-system
65+
spec:
66+
interval: 5m
67+
chart:
68+
spec:
69+
chart: github-deploy-key-operator
70+
version: "0.1.0" # Use specific version
71+
sourceRef:
72+
kind: HelmRepository
73+
name: github-deploy-key-operator
74+
namespace: flux-system
75+
values:
76+
github:
77+
existingSecret: github-token
78+
existingSecretKey: GITHUB_TOKEN
79+
```
80+
81+
## License
82+
83+
This chart is available under the same license as the GitHub Deploy Key Operator.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "github-deploy-key-operator.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "github-deploy-key-operator.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "github-deploy-key-operator.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "github-deploy-key-operator.labels" -}}
37+
helm.sh/chart: {{ include "github-deploy-key-operator.chart" . }}
38+
{{ include "github-deploy-key-operator.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "github-deploy-key-operator.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "github-deploy-key-operator.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "github-deploy-key-operator.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "github-deploy-key-operator.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "github-deploy-key-operator.fullname" . }}
5+
labels:
6+
{{- include "github-deploy-key-operator.labels" . | nindent 4 }}
7+
spec:
8+
replicas: {{ .Values.replicaCount }}
9+
selector:
10+
matchLabels:
11+
{{- include "github-deploy-key-operator.selectorLabels" . | nindent 6 }}
12+
template:
13+
metadata:
14+
labels:
15+
{{- include "github-deploy-key-operator.selectorLabels" . | nindent 8 }}
16+
spec:
17+
serviceAccountName: {{ include "github-deploy-key-operator.serviceAccountName" . }}
18+
{{- with .Values.podSecurityContext }}
19+
securityContext:
20+
{{- toYaml . | nindent 8 }}
21+
{{- end }}
22+
containers:
23+
- name: {{ .Chart.Name }}
24+
securityContext:
25+
{{- toYaml .Values.securityContext | nindent 12 }}
26+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
27+
imagePullPolicy: {{ .Values.image.pullPolicy }}
28+
env:
29+
- name: GITHUB_TOKEN
30+
valueFrom:
31+
secretKeyRef:
32+
{{- if .Values.github.existingSecret }}
33+
name: {{ .Values.github.existingSecret }}
34+
{{- else }}
35+
name: {{ include "github-deploy-key-operator.fullname" . }}-github
36+
{{- end }}
37+
key: {{ .Values.github.existingSecretKey }}
38+
- name: KOPF_NAMESPACE
39+
value: ""
40+
resources:
41+
{{- toYaml .Values.resources | nindent 12 }}
42+
{{- with .Values.nodeSelector }}
43+
nodeSelector:
44+
{{- toYaml . | nindent 8 }}
45+
{{- end }}
46+
{{- with .Values.affinity }}
47+
affinity:
48+
{{- toYaml . | nindent 8 }}
49+
{{- end }}
50+
{{- with .Values.tolerations }}
51+
tolerations:
52+
{{- toYaml . | nindent 8 }}
53+
{{- end }}

0 commit comments

Comments
 (0)