Circleci should publish helm chart to gh-pages (#15)

* Update screenshot to match current output
* Add job to Helm package and push to gh-pages branch
* Update .gitignore
* Add job to get version, semver2 compatible
* Only helm publish on main branch
* Add build arg to Dockerfile build command to set application version number
This commit is contained in:
Iain Sproat
2022-11-24 16:28:00 +00:00
committed by GitHub
parent f2872d6dea
commit c6dd80140e
8 changed files with 198 additions and 16 deletions
+7 -2
View File
@@ -1,7 +1,12 @@
#!/usr/bin/env bash
set -eo pipefail
DOCKER_IMAGE_TAG=speckle/alertmanager-discord
if [[ -z "${VERSION}" ]]; then
echo "VERSION environment variable should be set"
exit 1
fi
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG:-"speckle/alertmanager-discord"}"
export DOCKER_BUILDKIT=1
docker build --tag "${DOCKER_IMAGE_TAG}:${CIRCLE_SHA1}.${CIRCLE_BUILD_NUM}" --file ./Dockerfile .
docker build --tag "${DOCKER_IMAGE_TAG}:${VERSION}" --build-arg="APPLICATION_VERSION=${VERSION}" --file ./Dockerfile .
+83 -9
View File
@@ -1,33 +1,79 @@
version: 2.1
orbs:
helm: travelaudience/helm@0.2.13
workflows:
version: 2
build-image:
jobs:
- get-version:
filters:
tags: &filter-allow-all
only: /.*/
- pre-commit:
filters:
tags: &filter-all-tags # run for all tags
only: /.*/
tags: *filter-allow-all
- docker-build:
filters:
tags: *filter-all-tags
tags: *filter-allow-all
branches:
ignore:
- main
requires:
- get-version
- docker-build-and-publish:
context:
- docker-hub
filters:
tags: *filter-all-tags
tags: *filter-allow-all
branches:
only:
- main
requires:
- get-version
- pre-commit
- helm-package-and-publish:
context:
- github-write-alertmanagerdiscord-repo
filters:
tags: *filter-allow-all
branches:
only:
- main
requires:
- docker-build
- docker-build-and-publish
jobs:
get-version:
docker: &docker-image
- image: cimg/base:2022.04
working_directory: &workingdir /tmp/ci
steps:
- checkout
- run: mkdir -p workspace
- run:
name: set version
command: |
echo "export VERSION=$(.circleci/get_version.sh)" >> workspace/env-vars
- run:
name: store version
command: |
cat workspace/env-vars >> $BASH_ENV
- run:
name: echo version
command: |
echo "VERSION=${VERSION}"
- persist_to_workspace:
root: workspace
paths:
- env-vars
pre-commit:
parameters:
config_file:
@@ -41,8 +87,8 @@ jobs:
type: string
docker:
- image: speckle/pre-commit-runner:latest
resource_class: large
working_directory: &workingdir /tmp/ci
resource_class: &docker-resource-class medium
working_directory: *workingdir
steps:
- checkout
- restore_cache:
@@ -64,12 +110,17 @@ jobs:
when: on_fail
docker-build-and-publish:
docker: &docker-image
- image: cimg/base:2022.04
resource_class: &docker-resource-class large
docker: *docker-image
resource_class: *docker-resource-class
working_directory: *workingdir
steps:
- checkout
- attach_workspace:
at: /tmp/ci/workspace
- run:
name: populate environment variables
command: |
cat workspace/env-vars >> $BASH_ENV
- setup_remote_docker: &remote-docker
# a weird issue with yarn installing packages throwing EPERM errors
# this fixes it
@@ -85,7 +136,30 @@ jobs:
working_directory: *workingdir
steps:
- checkout
- attach_workspace:
at: /tmp/ci/workspace
- run:
name: populate environment variables
command: |
cat workspace/env-vars >> $BASH_ENV
- setup_remote_docker: *remote-docker
- run:
name: Build
command: ./.circleci/build.sh
helm-package-and-publish:
docker:
- image: quay.io/helmpack/chart-testing:v3.7.1-amd64
resource_class: *docker-resource-class
working_directory: *workingdir
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- run:
name: populate environment variables
command: |
cat /tmp/workspace/env-vars >> $BASH_ENV
- run:
name: Build and Publish
command: ./.circleci/package_and_publish_helm.sh
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
set -eo pipefail
if [[ "${CIRCLE_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "${CIRCLE_TAG}"
exit 0
fi
# shellcheck disable=SC2068,SC2046
LAST_RELEASE="$(git describe --always --tags $(git rev-list --tags) | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)"
NEXT_RELEASE="$(echo "${LAST_RELEASE}" | awk -F. -v OFS=. '{$NF += 1 ; print}')"
if [[ "${CIRCLE_BRANCH}" == "main" ]]; then
echo "${NEXT_RELEASE}-alpha.${CIRCLE_BUILD_NUM}"
exit 0
fi
# docker has a 128 character tag limit, so ensuring the branch name will be short enough
# helm uses semver 2, only valid characters are a-zA-Z0-9 and hyphen '-'
# shellcheck disable=SC2034
BRANCH_NAME_TRUNCATED="$(echo "${CIRCLE_BRANCH}" | cut -c -50 | sed 's/[^a-zA-Z0-9.-]/-/g')"
echo "${NEXT_RELEASE}-branch.${BRANCH_NAME_TRUNCATED}.${CIRCLE_BUILD_NUM}"
exit 0
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -eo pipefail
TEMP_PACKAGE_DIR="${TEMP_PACKAGE_DIR:-"/tmp/.cr-release-packages"}"
HELM_PACKAGE_BRANCH="${HELM_PACKAGE_BRANCH:-"gh-pages"}"
HELM_STABLE_BRANCH="${HELM_STABLE_BRANCH:-"main"}"
HELM_CHART_DIR_PATH="${HELM_CHART_DIR_PATH:-"deploy/helm"}"
if [[ -z "${VERSION}" ]]; then
echo "VERSION environment variable should be set"
exit 1
fi
if [[ -z "${GIT_EMAIL}" ]]; then
echo "GIT_EMAIL environment variable should be set"
exit 1
fi
if [[ -z "${GIT_USERNAME}" ]]; then
echo "GIT_USERNAME environment variable should be set"
exit 1
fi
echo "🧹 cleaning temporary directory"
rm -rf "${TEMP_PACKAGE_DIR}" || true
mkdir "${TEMP_PACKAGE_DIR}"
helm version -c
echo "🏗️ building dependencies"
helm dependency build "${HELM_CHART_DIR_PATH}"
echo "🎁 packaging ${HELM_CHART_DIR_PATH} with version: ${VERSION}"
helm package "${HELM_CHART_DIR_PATH}" --dependency-update --version "${VERSION}" --app-version "${VERSION}" --destination "${TEMP_PACKAGE_DIR}"
echo "⏬ checking out git branch '${HELM_PACKAGE_BRANCH}'"
git config user.email "${GIT_EMAIL}"
git config user.name "${GIT_USERNAME}"
git fetch
git switch "${HELM_PACKAGE_BRANCH}"
if [ "${CIRCLE_BRANCH}" == "${HELM_STABLE_BRANCH}" ]; then
echo "🛻 copying packages to stable directory"
cp -a "${TEMP_PACKAGE_DIR}" stable/
pushd stable
helm repo index .
popd
else
cp -a "${TEMP_PACKAGE_DIR}/." incubator/
echo "🛻 copying packages to incubator directory"
pushd incubator
helm repo index .
popd
fi
echo "⏫ adding, commiting, and pushing to git repository"
git add .
git commit -m "updating helm chart to version ${VERSION}"
git push --set-upstream origin "${HELM_PACKAGE_BRANCH}"
+22 -2
View File
@@ -1,9 +1,29 @@
#!/usr/bin/env bash
set -eo pipefail
DOCKER_IMAGE_TAG=speckle/alertmanager-discord
if [[ -z "${VERSION}" ]]; then
echo "VERSION environment variable should be set"
exit 1
fi
docker tag "${DOCKER_IMAGE_TAG}:${CIRCLE_SHA1}.${CIRCLE_BUILD_NUM}" "${DOCKER_IMAGE_TAG}:latest"
if [[ -z "${DOCKER_REG_PASS}" ]]; then
echo "DOCKER_REG_PASS environment variable should be set"
exit 1
fi
if [[ -z "${DOCKER_REG_USER}" ]]; then
echo "DOCKER_REG_USER environment variable should be set"
exit 1
fi
if [[ -z "${DOCKER_REG_URL}" ]]; then
echo "DOCKER_REG_URL environment variable should be set"
exit 1
fi
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG:-"speckle/alertmanager-discord"}"
docker tag "${DOCKER_IMAGE_TAG}:${VERSION}" "${DOCKER_IMAGE_TAG}:latest"
echo "${DOCKER_REG_PASS}" | docker login -u "${DOCKER_REG_USER}" --password-stdin "${DOCKER_REG_URL}"
docker push -a "${DOCKER_IMAGE_TAG}"
+3
View File
@@ -2,3 +2,6 @@ alertmanager-discord
alertmanager-discord.darwin
alertmanager-discord.linux
cover.out
# CircleCI orb Helm package & push
.cr-release-packages
+2 -2
View File
@@ -6,6 +6,6 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.0.0-local
# This is the version number of the application being deployed.
appVersion: "0.1.0"
appVersion: "0.0.0-local"
+1 -1
View File
@@ -1,6 +1,6 @@
# alertmanager-discord
![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square)
![Version: 0.0.0-local](https://img.shields.io/badge/Version-0.0.0--local-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.0-local](https://img.shields.io/badge/AppVersion-0.0.0--local-informational?style=flat-square)
A Helm chart to deploy alertmanager-discord to Kubernetes