Skip to content

Commit 29e1830

Browse files
authored
feat: Change Release Action to also Publish Image and Chart (#6)
As we can't trigger the publish and publish-chart workflows from the release workflow due to permissions issue we will need to publish the image and chart from the release workflow. Signed-off-by: Samuel Torres <[email protected]>
1 parent be3fe99 commit 29e1830

File tree

14 files changed

+169
-209
lines changed

14 files changed

+169
-209
lines changed

.github/workflows/publish-chart.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/publish.yaml

Lines changed: 0 additions & 73 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,115 @@ on:
99
default: 'v0.1.0'
1010
source_ref:
1111
description: 'source ref to publish from. E.g.: main or release-x.y'
12-
required: true
1312
default: 'main'
13+
required: true
14+
prerelease:
15+
required: false
16+
default: 'false'
1417

1518
jobs:
19+
publish:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
id-token: write
23+
contents: read
24+
attestations: write
25+
packages: write
26+
env:
27+
REGISTRY: ghcr.io
28+
IMAGE_NAME: ${{ github.repository }}
29+
steps:
30+
- name: Checkout Code
31+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
36+
- name: Login to GHCR
37+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 #v3.3.0
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Generate images meta
43+
id: meta
44+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
45+
with:
46+
images: |
47+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=raw,value=${{ github.event.inputs.version }}
50+
- name: Build and push
51+
id: build-push
52+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 #v6.10.0
53+
with:
54+
provenance: true
55+
sbom: true
56+
push: true
57+
platforms: linux/amd64,linux/arm64
58+
labels: ${{ steps.meta.outputs.labels }}
59+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}
60+
outputs: "type=registry,push=true"
61+
- name: Attest
62+
uses: actions/attest-build-provenance@c4fbc648846ca6f503a13a2281a5e7b98aa57202 # v2.0.1
63+
id: attest
64+
with:
65+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
66+
subject-digest: ${{ steps.build-push.outputs.digest }}
67+
push-to-registry: true
68+
69+
publish-chart:
70+
needs: publish
71+
runs-on: ubuntu-latest
72+
permissions:
73+
id-token: write
74+
contents: write
75+
attestations: write
76+
packages: write
77+
env:
78+
REGISTRY: ghcr.io
79+
CHART_DIR: charts
80+
steps:
81+
- name: Checkout Code
82+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
83+
- name: Install Helm
84+
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
85+
with:
86+
version: v3.12.0
87+
- name: Login to GHCR
88+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 #v3.3.0
89+
with:
90+
registry: ${{ env.REGISTRY }}
91+
username: ${{ github.actor }}
92+
password: ${{ secrets.GITHUB_TOKEN }}
93+
- name: Package chart
94+
id: package
95+
run: |
96+
helm package ${{ env.CHART_DIR }}/x-pdb --version=${{ github.event.inputs.version }} --app-version=${{ github.event.inputs.version }}
97+
echo "chart_file=$(ls *.tgz)" >> $GITHUB_OUTPUT
98+
- name: Push chart to GHCR
99+
id: push
100+
run: |
101+
helm push ${{ steps.package.outputs.chart_file }} oci://${{ env.REGISTRY }}/${{ github.repository }}/charts |& tee helm-push-output.log
102+
DIGEST=$(awk -F "[, ]+" '/Digest/{print $NF}' < helm-push-output.log)
103+
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
104+
- name: Attest
105+
uses: actions/attest-build-provenance@c4fbc648846ca6f503a13a2281a5e7b98aa57202 # v2.0.1
106+
id: attest
107+
with:
108+
subject-name: ${{ env.REGISTRY }}/${{ github.repository }}/charts/x-pdb
109+
subject-digest: ${{ steps.push.outputs.digest }}
110+
push-to-registry: true
111+
- name: Publish Helm charts to GH Pages
112+
uses: stefanprodan/helm-gh-pages@0ad2bb377311d61ac04ad9eb6f252fb68e207260 # v1.7.0
113+
with:
114+
token: ${{ secrets.GITHUB_TOKEN }}
115+
charts_dir: ${{ env.CHART_DIR }}
116+
16117
release:
118+
needs: [publish, publish-chart]
17119
name: Create Release
18120
runs-on: ubuntu-latest
19-
20121
steps:
21122
- name: Checkout
22123
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -28,8 +129,7 @@ jobs:
28129
with:
29130
tag_name: ${{ github.event.inputs.version }}
30131
target_commitish: ${{ github.event.inputs.source_ref }}
132+
prerelease: ${{ github.event.inputs.prerelease }}
31133
generate_release_notes: true
32-
body: |
33-
Image: `${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}`
34134
env:
35135
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
- name: Lint
3434
id: run-lint
3535
run: make lint
36+
- name: Helm Lint
37+
id: helm-lint
38+
run: make helm-lint
3639
- name: Run Go tests
3740
id: run-tests
3841
run: make test

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##########
44

55
# Image names
6-
IMG ?= x-pdb:latest
6+
IMG ?= ghcr.io/form3tech-oss/x-pdb:latest
77
TEST_APP_IMG ?= x-pdb-test:latest
88
TEST_DISRUPTION_PROBE_IMG ?= x-pdb-test-disruption-probe:latest
99

@@ -127,6 +127,10 @@ lint: golangci-lint ## Run golangci-lint linter
127127
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
128128
$(GOLANGCI_LINT) run --fix
129129

130+
.PHONY: helm-lint
131+
helm-lint: # Lints the x-pdb helm chartk
132+
helm lint charts/x-pdb
133+
130134
##@ Build
131135

132136
.PHONY: build
@@ -220,10 +224,12 @@ install: kind-load ## Installs x-pdb into a cluster
220224

221225
.PHONY: proto-generate
222226
proto-generate: ## Generates the go packages from the proto contracts.
223-
protoc --go_out=$(PROTO_GO_OUT_DIR) --go_opt=paths=source_relative \
224-
--go-grpc_out=$(PROTO_GO_OUT_DIR) --go-grpc_opt=paths=source_relative \
225-
$(PROTO_FILES)
227+
buf generate
226228

229+
.PHONY: proto-lint
230+
proto-lint: ## Lints the proto contracts
231+
buf lint
232+
227233
##@ Dependencies
228234

229235
## Location to install dependencies to

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This is needed, because each cluster acts individually (evictions, rolling out u
88
Please refer to the documentation at https://form3tech-oss.github.com/x-pdb
99

1010
## Development
11+
1112
### Running tests
1213

1314
Simple tests can be ran with `make test`.
@@ -17,6 +18,7 @@ This will create three `kind` clusters which are connected through `metallb`.
1718

1819
```
1920
make multi-cluster
21+
make deploy-e2e
2022
make e2e
2123
```
2224

charts/x-pdb/Chart.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apiVersion: v2
2-
name: x-pdb
2+
appVersion: 0.0.1
33
description: A Helm chart for Kubernetes
4+
name: x-pdb
45
type: application
56
version: 0.0.1

charts/x-pdb/templates/_helpers.tpl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,3 @@ Create the name of the service account to use
7575
{{- default "default" .Values.serviceAccount.name }}
7676
{{- end }}
7777
{{- end }}
78-
79-
{{/*
80-
Creates an image name from the image structure available in the values file
81-
*/}}
82-
{{- define "x-pdb.image" -}}
83-
{{- if .registry }}
84-
{{- print .registry "/" (required "An image repository is required" .repository) ":" .tag -}}
85-
{{- else }}
86-
{{- print (required "An image repository is required" .repository) ":" .tag -}}
87-
{{- end }}
88-
{{- end }}

charts/x-pdb/templates/certificates.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.webhook.tls.certManager.enabled -}}
1+
{{- if .Values.webhook.tls.certManager.enabled }}
22
---
33
apiVersion: cert-manager.io/v1
44
kind: Certificate
@@ -26,8 +26,9 @@ spec:
2626
encoding: PKCS1
2727
size: 2048
2828
{{- end }}
29+
30+
{{- if .Values.controller.tls.certManager.enabled }}
2931
---
30-
{{- if .Values.controller.tls.certManager.enabled -}}
3132
apiVersion: cert-manager.io/v1
3233
kind: Certificate
3334
metadata:

charts/x-pdb/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
- name: {{ .Chart.Name }}
3939
securityContext:
4040
{{- toYaml .Values.securityContext | nindent 12 }}
41-
image: "{{ include "x-pdb.image" .Values.image }}"
41+
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}"
4242
imagePullPolicy: {{ .Values.image.pullPolicy }}
4343
command:
4444
- /x-pdb

0 commit comments

Comments
 (0)