Skip to content

Commit

Permalink
Merge pull request kuskoman#83 from kuskoman/chart-versioning
Browse files Browse the repository at this point in the history
Implement application and chart versioning script
  • Loading branch information
kuskoman authored Apr 13, 2023
2 parents e26782c + 3efbe07 commit 3e7f98a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: logstash-exporter
description: Prometheus exporter for Logstash written in Go
type: application
version: v1.0.2
appVersion: 1.0.2
version: "1.0.2"
appVersion: "1.0.2"
12 changes: 6 additions & 6 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

### Image settings

| Name | Description | Value |
| ------------------ | ---------------------------------- | ---------------------------- |
| `image.repository` | Image repository | `kuskoman/logstash-exporter` |
| `image.tag` | Image tag | `v1.0.2` |
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
| `fullnameOverride` | Override the fullname of the chart | `""` |
| Name | Description | Value |
| ------------------ | -------------------------------------------- | ---------------------------- |
| `image.repository` | Image repository | `kuskoman/logstash-exporter` |
| `image.tag` | Image tag, if not set the appVersion is used | `""` |
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
| `fullnameOverride` | Override the fullname of the chart | `""` |

### Deployment settings

Expand Down
4 changes: 2 additions & 2 deletions chart/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"tag": {
"type": "string",
"description": "Image tag",
"default": "v1.0.2"
"description": "Image tag, if not set the appVersion is used",
"default": ""
},
"pullPolicy": {
"type": "string",
Expand Down
14 changes: 13 additions & 1 deletion chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ If release name contains chart name it will be used as a full name.
{{- printf "%s" .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "logstash-exporter.serviceAccountName" -}}
{{/*
By default we want service account name to be the same as fullname
but this may change in the future, so for easier usage this is extracted
to a separate template.
*/}}
{{- define "logstash-exporter.serviceAccountName" -}}
{{- include "logstash-exporter.fullname" . }}
{{- end -}}

{{/*
logstash-exporter.imageTag is a named template that returns the image tag.
It checks if .Values.image.tag is provided, and if not, it returns a tag with "v" prefix followed by the app version from the Chart.yaml.
*/}}
{{- define "logstash-exporter.imageTag" -}}
{{- if .Values.image.tag -}}
{{- .Values.image.tag -}}
{{- else -}}
{{- printf "v%s" .Chart.AppVersion -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ spec:
valueFrom:
{{- toYaml $value | nindent 14 }}
{{- end }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
image: "{{ .Values.image.repository }}:{{ include "logstash-exporter.imageTag" $ }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}

{{- if .Values.deployment.resources }}
Expand Down
4 changes: 2 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ image:
## @param image.repository Image repository
##
repository: "kuskoman/logstash-exporter"
## @param image.tag Image tag
## @param image.tag Image tag, if not set the appVersion is used
##
tag: "v1.0.2"
tag: ""
## @param image.pullPolicy Image pull policy
## Options: Always, Never, IfNotPresent
##
Expand Down
47 changes: 47 additions & 0 deletions scripts/release_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -euo pipefail

function ask_confirmation() {
local prompt="$1"
local yn

while true; do
read -p "$prompt [y/n]: " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer y or n.";;
esac
done
}

git_status=$(git status --porcelain)
if [[ -n "$git_status" ]]; then
echo "You have unsaved changes:"
echo "$git_status"
ask_confirmation "You have unsaved changes. Do you want to proceed?" || exit
fi

latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
echo "Latest tag on the given branch: $latest_tag"
read -p "Enter the version to release: " release_version

if [[ $release_version =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
chart_version=${release_version:1}
else
echo "Warning: Version does not match the format vX.Y.Z."
ask_confirmation "Do you want to continue?" || exit
chart_version=$release_version
fi

yq eval ".version = \"$chart_version\" | .appVersion = \"$chart_version\"" chart/Chart.yaml -i
sed -i "/^## @param image.tag\s*$/,/^\s*tag:\s*\"[^\"]*\"\s*$/s/\(^\s*tag:\s*\).*\$/\1\"$release_version\"/" chart/values.yaml
./scripts/generate_helm_readme.sh

git diff
ask_confirmation "Do you want to proceed with the above changes?" || exit

git add .
git commit -m "Release $release_version"
git tag $release_version

0 comments on commit 3e7f98a

Please sign in to comment.