From 1ec65d3a790ced197ba6551d07f2cafe5916a997 Mon Sep 17 00:00:00 2001 From: Joseph Lombrozo Date: Thu, 11 Apr 2024 00:26:05 -0400 Subject: [PATCH] use a 'latest' tag for releases (#171) --- .github/actions/build-image/action.yaml | 6 +++++- .github/workflows/on_release_published.yaml | 1 + .tool-versions | 2 +- Earthfile | 5 +++-- charts/kubechecks/Chart.yaml | 3 +-- charts/kubechecks/templates/_helpers.tpl | 8 +++----- charts/kubechecks/templates/deployment.yaml | 5 ++--- charts/kubechecks/tests/configmap_test.yaml | 7 +++++-- charts/kubechecks/tests/deployment_test.yaml | 19 ++++++++++++++++--- charts/kubechecks/values.yaml | 2 +- 10 files changed, 38 insertions(+), 20 deletions(-) diff --git a/.github/actions/build-image/action.yaml b/.github/actions/build-image/action.yaml index 1cec541b..900082b3 100644 --- a/.github/actions/build-image/action.yaml +++ b/.github/actions/build-image/action.yaml @@ -5,6 +5,9 @@ inputs: image_tag: description: The image tag required: true + tag_latest: + description: Tag latest as well as the provided tag + default: "false" token: description: Github token required: true @@ -40,6 +43,7 @@ runs: run: >- ./earthly --push - +build + +docker-multiarch + ${{ inputs.tag_latest != 'false' && format('--LATEST_IMAGE_NAME=ghcr.io/{0}:latest', github.repository) || '' }} --GIT_TAG=${{ inputs.image_tag }} --IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ inputs.image_tag }} diff --git a/.github/workflows/on_release_published.yaml b/.github/workflows/on_release_published.yaml index 857e38c4..7d9e0328 100644 --- a/.github/workflows/on_release_published.yaml +++ b/.github/workflows/on_release_published.yaml @@ -19,4 +19,5 @@ jobs: - uses: ./.github/actions/build-image with: image_tag: ${{ github.ref_name }} + tag_latest: true token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.tool-versions b/.tool-versions index ac614c91..91d87df9 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -earthly 0.7.23 +earthly 0.8.6 golang 1.21.6 golangci-lint 1.56.1 helm 3.12.2 diff --git a/Earthfile b/Earthfile index aa4faa21..7ab4d831 100644 --- a/Earthfile +++ b/Earthfile @@ -17,7 +17,7 @@ ci-helm: BUILD +test-helm BUILD +release-helm -build: +docker-multiarch: BUILD --platform=linux/amd64 --platform=linux/arm64 +docker release: @@ -129,7 +129,8 @@ docker: CMD ["./kubechecks", "controller"] ARG --required IMAGE_NAME - SAVE IMAGE --push $IMAGE_NAME + ARG LATEST_IMAGE_NAME="" + SAVE IMAGE --push $IMAGE_NAME $LATEST_IMAGE_NAME dlv: ARG --required GOLANG_VERSION diff --git a/charts/kubechecks/Chart.yaml b/charts/kubechecks/Chart.yaml index 2e1c7b31..47779854 100644 --- a/charts/kubechecks/Chart.yaml +++ b/charts/kubechecks/Chart.yaml @@ -1,8 +1,7 @@ apiVersion: v2 name: kubechecks description: A Helm chart for kubechecks -version: 0.4.3 -appVersion: "1.3.3" +version: 0.4.4 type: application maintainers: - name: zapier diff --git a/charts/kubechecks/templates/_helpers.tpl b/charts/kubechecks/templates/_helpers.tpl index 98422308..0277874a 100644 --- a/charts/kubechecks/templates/_helpers.tpl +++ b/charts/kubechecks/templates/_helpers.tpl @@ -36,12 +36,10 @@ Common labels {{- define "kubechecks.labels" -}} helm.sh/chart: {{ include "kubechecks.chart" . }} {{ include "kubechecks.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ coalesce .Values.deployment.image.tag .Chart.AppVersion | quote }} -{{- end }} +app.kubernetes.io/version: {{ .Values.deployment.image.tag }} app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- if .Values.commonLabels }} -{{ toYaml .Values.commonLabels }} +{{- with .Values.commonLabels }} +{{ . | toYaml }} {{- end }} {{- end }} diff --git a/charts/kubechecks/templates/deployment.yaml b/charts/kubechecks/templates/deployment.yaml index 84c8611e..56ff5d10 100644 --- a/charts/kubechecks/templates/deployment.yaml +++ b/charts/kubechecks/templates/deployment.yaml @@ -5,8 +5,7 @@ metadata: {{- with .Values.deployment.annotations }} annotations: {{ toYaml . | nindent 4 }} {{- end}} - labels: - {{- include "kubechecks.labels" . | nindent 4 }} + labels: {{- include "kubechecks.labels" . | nindent 4 }} spec: replicas: {{ .Values.deployment.replicaCount }} selector: @@ -36,7 +35,7 @@ spec: containers: - name: {{ .Chart.Name }} {{- with .Values.deployment.image }} - image: "{{ .name }}:{{ coalesce .tag (printf "v%s" $.Chart.AppVersion) }}" + image: "{{ .name }}:{{ required "must set .deployment.image.tag" .tag }}" imagePullPolicy: {{ .pullPolicy }} {{- end }} {{- with .Values.deployment.args }} diff --git a/charts/kubechecks/tests/configmap_test.yaml b/charts/kubechecks/tests/configmap_test.yaml index 00fa6e7c..16b8a5c0 100644 --- a/charts/kubechecks/tests/configmap_test.yaml +++ b/charts/kubechecks/tests/configmap_test.yaml @@ -7,8 +7,11 @@ values: [basics.min-values.yaml] tests: - it: should render chart: - appVersion: 1.0.0 version: 0.1.0 + set: + deployment: + image: + tag: 1.0.0 release: name: kubechecks asserts: @@ -16,7 +19,7 @@ tests: of: ConfigMap - equal: path: data - value: + value: KUBECHECKS_ARGOCD_API_INSECURE: "false" KUBECHECKS_TEST_VALUE: Hello - equal: diff --git a/charts/kubechecks/tests/deployment_test.yaml b/charts/kubechecks/tests/deployment_test.yaml index 7585558b..6548d6a7 100644 --- a/charts/kubechecks/tests/deployment_test.yaml +++ b/charts/kubechecks/tests/deployment_test.yaml @@ -5,9 +5,21 @@ templates: [deployment.yaml] values: [basics.min-values.yaml] tests: + - it: defaults to latest image tag + asserts: + - equal: + path: metadata.labels["app.kubernetes.io/version"] + value: latest + - equal: + path: spec.template.spec.containers[0].image + value: ghcr.io/zapier/kubechecks:latest + - it: should render + set: + deployment: + image: + tag: v1.0.0 chart: - appVersion: 1.0.0 version: 0.1.0 release: name: kubechecks @@ -16,15 +28,16 @@ tests: of: Deployment - equal: path: spec.template.spec.containers[0].image - value: ghcr.io/zapier/kubechecks:v1.0.0 # App Version, not chart versions + value: ghcr.io/zapier/kubechecks:v1.0.0 - equal: path: metadata.labels value: app.kubernetes.io/instance: kubechecks app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: kubechecks - app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/version: v1.0.0 helm.sh/chart: kubechecks-0.1.0 + - it: should allow arbitrary annotations set: deployment: diff --git a/charts/kubechecks/values.yaml b/charts/kubechecks/values.yaml index 9a11138a..c2eedd46 100644 --- a/charts/kubechecks/values.yaml +++ b/charts/kubechecks/values.yaml @@ -40,7 +40,7 @@ deployment: image: pullPolicy: Always name: "ghcr.io/zapier/kubechecks" - tag: "" # Defaults to the .Chart.AppVersion + tag: "latest" imagePullSecrets: []