Skip to content

Commit

Permalink
Retrieve latest tag from GitHub when syncing the chart (#1159)
Browse files Browse the repository at this point in the history
* Restore values

* Retrieve latest tag from github

* Use ACCESS_TOKEN as var
  • Loading branch information
Andres Martinez Gotor authored Sep 13, 2019
1 parent 959d608 commit d3d30d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
7 changes: 2 additions & 5 deletions chart/kubeapps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,8 @@ dashboard:
replicaCount: 2
image:
registry: docker.io
# Once issue #1156 is fixed we can continue using kubeapps repository instead of bitnami fixed tags
# repository: kubeapps/dashboard
# tag: latest
repository: bitnami/kubeapps-dashboard
tag: 1.5.0-debian-9-r14
repository: kubeapps/dashboard
tag: latest
service:
port: 8080
livenessProbe:
Expand Down
36 changes: 30 additions & 6 deletions script/chart_sync_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ configUser() {
cd -
}

replaceImage() {
local service=${1:?}
local file=${2:?}
local repoName="bitnami-docker-kubeapps-${service}"
local currentImageEscaped="kubeapps\/${service}"
local targetImageEscaped="bitnami\/kubeapps-${service}"

local header=""
if [[ $ACCESS_TOKEN != "" ]]; then
header="-H 'Authorization: token ${ACCESS_TOKEN}'"
fi

# Get the latest tag from the bitnami repository
local tag=`curl ${header} https://api.github.com/repos/bitnami/${repoName}/tags | jq -r '.[0].name'`
if [[ $tag == "" ]]; then
echo "ERROR: Unable to obtain latest tag for ${repoName}. Aborting"
exit 1
fi

# Replace image and tag from the values.yaml
sed -i.bk -e '1h;2,$H;$!d;g' -re \
's/repository: '${currentImageEscaped}'\n tag: latest/repository: '${targetImageEscaped}'\n tag: '${tag}'/g' \
${file}
rm "${file}.bk"
}

updateRepo() {
local targetRepo=${1:?}
local targetTag=${2:?}
Expand All @@ -56,12 +82,10 @@ updateRepo() {
# Update Chart.yaml with new version
sed -i.bk 's/appVersion: DEVEL/appVersion: '"${targetTag}"'/g' "${chartYaml}"
rm "${targetChartPath}/Chart.yaml.bk"
# DANGER: This replaces any tag marked as latest in the values.yaml
local tagWithoutV=$(echo $targetTag | tr -d v)
sed -i.bk 's/tag: latest/tag: '"${tagWithoutV}"'-r0/g' "${targetChartPath}/values.yaml"
# Use bitnami images
sed -i.bk 's/repository: kubeapps\/\(.*\)/repository: bitnami\/kubeapps-\1/g' "${targetChartPath}/values.yaml"
rm "${targetChartPath}/values.yaml.bk"
# Replace images for the latest available
replaceImage dashboard "${targetChartPath}/values.yaml"
replaceImage tiller-proxy "${targetChartPath}/values.yaml"
replaceImage apprepository-controller "${targetChartPath}/values.yaml"
}

commitAndPushChanges() {
Expand Down

0 comments on commit d3d30d4

Please sign in to comment.