Skip to content

Commit 495d191

Browse files
stplasimalexlanz
andauthored
GitHub action to setup Helm chart with appVersion for deployment (#3)
* add optional helm version input to action configuration * add helm chart authentication, versioning, and deployment steps * update readme to include helm inputs and usage examples * Apply suggestions from code review Co-authored-by: Alex Lanz <alex.lanz@aboutbits.it> * make helm-registry-url a required input --------- Co-authored-by: Alex Lanz <alex.lanz@aboutbits.it>
1 parent 9fe037c commit 495d191

3 files changed

Lines changed: 87 additions & 29 deletions

File tree

do-setup-kubectl/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ inputs:
88
cluster-name:
99
description: 'Kubernetes cluster name'
1010
required: true
11+
helm-version:
12+
description: 'Helm version'
13+
required: false
14+
default: '3.17.1'
15+
1116

1217
runs:
1318
using: "composite"
@@ -23,3 +28,5 @@ runs:
2328

2429
- name: Setup Helm
2530
uses: azure/setup-helm@v4.2.0
31+
with:
32+
version: ${{ inputs.helm-version }}

helm-deploy/action.yml

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,76 @@
1-
name: 'Deploy Helm chart to Kubernetes'
2-
description: 'Deploy an application to a Kubernetes cluster using its Helm chart'
1+
name: "Helm Chart Setup and Deployment"
2+
description: "Setup a Helm chart, modify its appVersion, and deploy it to a Kubernetes cluster"
33

44
inputs:
5+
helm-chart-version:
6+
description: "The Helm chart version"
7+
required: true
8+
helm-registry-url:
9+
description: "The Helm OCI registry URL"
10+
required: true
11+
helm-package:
12+
description: "The Helm package"
13+
required: true
14+
helm-username:
15+
description: "The username to authenticate with the Helm registry"
16+
required: true
17+
helm-password:
18+
description: "The password to authenticate with the Helm registry"
19+
required: true
20+
helm-protocol:
21+
description: "The protocol for fetching the Helm chart (e.g., oci://). Default is 'oci://'."
22+
default: "oci://"
523
release-name:
6-
description: 'The name of the Helm release'
24+
description: "The name of the Helm release"
725
required: true
8-
chart-path:
9-
description: 'The directory of the Helm chart'
10-
default: '.'
1126
values-file:
12-
description: 'Path to the Helm values file'
27+
description: "Path to the Helm values file"
1328
required: true
1429
image-tag:
15-
description: 'Tag of the container image'
16-
default: 'latest'
30+
description: "Tag of the container image"
31+
default: "latest"
1732
timeout:
18-
description: 'Timeout for the Helm command'
19-
default: '5m'
33+
description: "Timeout for the Helm command"
34+
default: "5m"
2035
working-directory:
21-
description: 'The working directory'
22-
default: '.'
36+
description: "The working directory"
37+
default: "."
2338

2439
runs:
2540
using: "composite"
2641
steps:
42+
- name: Login to Helm registry
43+
shell: bash
44+
run: |
45+
helm registry login ${{ inputs.helm-registry-url }} \
46+
-u ${{ inputs.helm-username }} \
47+
-p ${{ inputs.helm-password }}
48+
49+
- name: Pull the Helm chart
50+
shell: bash
51+
working-directory: ${{ inputs.working-directory }}
52+
run: |
53+
helm pull ${{ inputs.helm-protocol }}${{ inputs.helm-registry-url }}/${{ inputs.helm-package }} \
54+
--version ${{ inputs.helm-chart-version }}
55+
56+
- name: Extract Helm chart
57+
shell: bash
58+
working-directory: ${{ inputs.working-directory }}
59+
run: |
60+
tar -xzf ${{ inputs.helm-package }}-*.tgz
61+
62+
- name: Update appVersion in Chart.yaml
63+
shell: bash
64+
working-directory: ${{ inputs.working-directory }}
65+
run: |
66+
yq -i '.appVersion = "${{ github.sha }}" | .appVersion style="double"' \
67+
${{ inputs.helm-package }}/Chart.yaml
68+
2769
- name: Deploy Helm chart
2870
shell: bash
2971
working-directory: ${{ inputs.working-directory }}
3072
run: |
31-
helm upgrade --wait --install ${{ inputs.release-name }} ${{ inputs.chart-path }} \
73+
helm upgrade --wait --install ${{ inputs.release-name }} ./${{ inputs.helm-package }} \
3274
--values ${{ inputs.values-file }} \
3375
--atomic --timeout ${{ inputs.timeout }} \
3476
--set image.tag=${{ inputs.image-tag }}

readme.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ Setup Digital-Ocean CLI and configure Kubernetes.
2121
2222
The following inputs can be used as `step.with` keys:
2323

24-
| Name | Required/Default | Description |
25-
|--------------------------|--------------------|---------------------------------|
26-
| `digital-ocean-token` | required | Digital Ocean access token |
27-
| `cluster-name` | required | Kubernetes cluster name |
24+
| Name | Required/Default | Description |
25+
|-----------------------|------------------|----------------------------------------|
26+
| `digital-ocean-token` | required | DigitalOcean access token |
27+
| `cluster-name` | required | Kubernetes cluster name |
28+
| `helm-version` | `3.17.1` | The version of Helm to install and use |
2829

2930

3031
### Deploy to Kubernetes using kubectl
@@ -54,17 +55,20 @@ The following inputs can be used as `step.with` keys:
5455

5556
### Deploy to Kubernetes using Helm
5657

57-
Deploy an application to a Kubernetes cluster using its Helm diagram. Requires Kubernetes to be configured first.
58+
Deploy an application to a Kubernetes cluster using its Helm chart. Requires Kubernetes to be configured first.
5859

5960
#### Example
6061

6162
```yaml
6263
- uses: aboutbits/github-actions-kubernetes/helm-deploy@v2
6364
with:
65+
helm-chart-version: "1.0.0"
66+
helm-package: "my-app-chart"
67+
helm-username: ${{ secrets.HELM_USERNAME }}
68+
helm-password: ${{ secrets.HELM_PASSWORD }}
6469
release-name: my-app
65-
chart-directory: my-chart
66-
image-tag: "1.0.0"
6770
values-file: environments/values-test.yaml
71+
image-tag: "1.0.42"
6872
timeout: 5m
6973
working-directory: ./infrastructure
7074
```
@@ -73,14 +77,19 @@ Deploy an application to a Kubernetes cluster using its Helm diagram. Requires K
7377

7478
The following inputs can be used as `step.with` keys:
7579

76-
| Name | Required/Default | Description |
77-
|---------------------|------------------|------------------------------------|
78-
| `release-name` | required | The name of the Helm release |
79-
| `values-file` | required | Path to the Helm values file |
80-
| `working-directory` | `.` | The working directory |
81-
| `chart-directory` | `.` | Root directory of the helm diagram |
82-
| `image-tag` | `latest` | Tag of the container image |
83-
| `timeout` | `5m` | Timeout for the Helm command |
80+
| Name | Required/Default | Description |
81+
|----------------------|------------------|--------------------------------------------------------------|
82+
| `helm-chart-version` | required | The version of the Helm chart to pull |
83+
| `helm-registry-url` | required | The URL of the Helm OCI registry |
84+
| `helm-package` | required | The name of the Helm package to pull |
85+
| `helm-username` | required | The username for authenticating with the Helm registry |
86+
| `helm-password` | required | The password for authenticating with the Helm registry |
87+
| `helm-protocol` | `oci://` | The protocol for pulling Helm charts (e.g., `oci://`) |
88+
| `release-name` | required | The name of the Helm release |
89+
| `values-file` | required | Path to the Helm values file for customization |
90+
| `image-tag` | `latest` | The tag of the container image to set |
91+
| `timeout` | `5m` | The timeout for the Helm command |
92+
| `working-directory` | `.` | The working directory where the action commands will operate |
8493

8594
## Versioning
8695

0 commit comments

Comments
 (0)