Skip to content

Commit

Permalink
adding a release process
Browse files Browse the repository at this point in the history
  • Loading branch information
slim-bean authored and Ed committed Jun 3, 2019
1 parent 1dc130d commit c326d6b
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ workflows:
filters:
branches:
only: master
release:
jobs:
- release:
filters:
tags:
# Matches tags pushed such as v0.1.0, matches anything after the patch to also allow v0.2.0-beta or v0.2.0-rc.1
only: /^v\d+\.\d+\.\d+.*$/

# https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/
defaults: &defaults
Expand Down Expand Up @@ -159,3 +166,24 @@ jobs:
--data "{\"build_parameters\": {\"CIRCLE_JOB\": \"deploy\", \"IMAGE_NAMES\": \"$(make images)\"}}" \
--request POST \
https://circleci.com/api/v1.1/project/github/raintank/deployment_tools/tree/master?circle-token=$CIRCLE_TOKEN
release:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: v1-loki-{{ .Branch }}-{{ .Revision }}
- run:
name: Load Images
command: |
touch loki-build-image/.uptodate &&
make BUILD_IN_CONTAINER=false load-images
- run:
name: "Print Tag"
command: echo ${CIRCLE_TAG}
- run:
name: "Release"
command: |
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" &&
make VERSION=${CIRCLE_TAG} release-perform
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all test clean images protos assets check_assets
.PHONY: all test clean images protos assets check_assets release-prepare release-perform
.DEFAULT_GOAL := all

CHARTS := production/helm/loki production/helm/promtail production/helm/loki-stack
Expand Down Expand Up @@ -221,6 +221,21 @@ push-latest:
fi \
done

release-prepare:
@set -e; ./tools/release_prepare.sh

release-perform:
@[ "${VERSION}" ] || ( echo ">> VERSION env var must be set to create a release"; exit 1 )
@echo ">> Pushing docker images with tag for version $(VERSION)"
@set -e; \
for image_name in $(IMAGE_NAMES); do \
if ! echo $$image_name | grep build; then \
docker tag $$image_name:$(IMAGE_TAG) $$image_name:$(VERSION); \
docker push $$image_name:$(VERSION); \
fi \
done


helm:
-rm -f production/helm/*/requirements.lock
@set -e; \
Expand Down
77 changes: 77 additions & 0 deletions tools/increment_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# This script was soruced here: https://github.com/fmahnke/shell-semver and had the following license:

# The MIT License (MIT)
#
# Copyright (c) 2014 Fritz Mahnke
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


# Increment a version string using Semantic Versioning (SemVer) terminology.

# Parse command line options.

while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done

shift $(($OPTIND - 1))

version=$1

# Build array from version string.

a=( ${version//./ } )

# If version string is missing or has the wrong number of members, show usage message.

if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi

# Increment version numbers as requested.

if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi

if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi

if [ ! -z $patch ]
then
((a[2]++))
fi

echo "${a[0]}.${a[1]}.${a[2]}"
75 changes: 75 additions & 0 deletions tools/release_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh

echo
echo "Last 5 tags:"
git tag --sort=-taggerdate | head -n 5
echo

read -p "Enter release version: " VERSION

if [[ ${VERSION} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "New Version: ${VERSION}"
else
echo "Version must be in the format v0.1.0"
exit 1
fi

LOKI_CURRENT=$(sed -n -e 's/^version: //p' production/helm/loki/Chart.yaml)
LOKI_SUGGESTED=$(tools/increment_version.sh -m ${LOKI_CURRENT})
PROMTAIL_CURRENT=$(sed -n -e 's/^version: //p' production/helm/promtail/Chart.yaml)
PROMTAIL_SUGGESTED=$(tools/increment_version.sh -m ${PROMTAIL_CURRENT})
LOKI_STACK_CURRENT=$(sed -n -e 's/^version: //p' production/helm/loki-stack/Chart.yaml)
LOKI_STACK_SUGGESTED=$(tools/increment_version.sh -m ${LOKI_STACK_CURRENT})
echo
echo "Current Loki helm chart version: ${LOKI_CURRENT}"
read -p "Enter new Loki helm chart version [${LOKI_SUGGESTED}]: " LOKI_VERSION
LOKI_VERSION=${LOKI_VERSION:-${LOKI_SUGGESTED}}
echo
echo "Current Promtail helm chart version: ${PROMTAIL_CURRENT}"
read -p "Enter new Promtail helm chart version [${PROMTAIL_SUGGESTED}]: " PROMTAIL_VERSION
PROMTAIL_VERSION=${PROMTAIL_VERSION:-${PROMTAIL_SUGGESTED}}
echo
echo "Current Loki-Stack helm chart version: ${LOKI_STACK_CURRENT}"
read -p "Enter new Loki-Stack helm chart version [${LOKI_STACK_SUGGESTED}]: " LOKI_STACK_VERSION
LOKI_STACK_VERSION=${LOKI_STACK_VERSION:-${LOKI_STACK_SUGGESTED}}
echo

echo "Creating Release"
echo "Release Version: ${VERSION}"
echo "Loki Helm Chart: ${LOKI_VERSION}"
echo "Promtail Helm Chart: ${PROMTAIL_VERSION}"
echo "Loki-Stack Helm Chart: ${LOKI_STACK_VERSION}"
echo
read -p "Is this correct? [y]: " CONTINUE
CONTINUE=${CONTINUE:-y}
echo

if [[ "${CONTINUE}" != "y" ]]; then
exit 1
fi

echo "Updating helm and ksonnet image versions"
sed -i '' "s/.*promtail:.*/ promtail: '\''grafana\/promtail:${VERSION}'\'',/" production/ksonnet/promtail/config.libsonnet
sed -i '' "s/.*loki:.*/ loki: '\''grafana\/loki:${VERSION}'\'',/" production/ksonnet/loki/images.libsonnet
sed -i '' "s/.*tag:.*/ tag: ${VERSION}/" production/helm/loki/values.yaml
sed -i '' "s/.*tag:.*/ tag: ${VERSION}/" production/helm/promtail/values.yaml

echo "Updating helm charts"
sed -i '' "s/^version:.*/version: ${LOKI_VERSION}/" production/helm/loki/Chart.yaml
sed -i '' "s/^version:.*/version: ${PROMTAIL_VERSION}/" production/helm/promtail/Chart.yaml
sed -i '' "s/^version:.*/version: ${LOKI_STACK_VERSION}/" production/helm/loki-stack/Chart.yaml
echo
echo "######################################################################################################"
echo "NEXT STEPS"
echo
echo "Verify the changes, then commit and push and get them merged to master"
echo
echo "Once merged to master"
echo
echo "git pull"
echo "git tag -a ${VERSION} -m \"tagging release ${VERSION}\""
echo "git push origin ${VERSION}"
echo
echo "This should initiate the CircleCI build to push the images and finish the release"
echo "######################################################################################################"

0 comments on commit c326d6b

Please sign in to comment.