From 0dab1091d61a887b911a56ea1775c66196742cab Mon Sep 17 00:00:00 2001 From: Stephen Moloney Date: Sat, 26 Dec 2020 16:00:57 +0100 Subject: [PATCH] Added: ci functionality to push helm charts to github pages ***What does this PR do?*** - Installs helm chart releaser in CI - Adds stage to CI to publish changed charts to github pages ***Why is this PR needed?*** - Ensure that published charts are accessible via helm repo --- .azure-pipelines/templates/01_lint.yaml | 2 +- .../templates/02_docker_build.yaml | 4 +- .../templates/03_docker_push.yaml | 2 +- .azure-pipelines/templates/04_helm_push.yaml | 53 +++++ .cr.yaml | 21 ++ .gitignore | 6 + .markdownlintignore | 1 + Makefile | 20 +- README.md | 31 ++- azure-pipelines.yaml | 2 + charts/saleor-core/Chart.yaml | 2 +- charts/saleor-dashboard/Chart.yaml | 2 +- charts/saleor-platform/Chart.lock | 21 -- charts/saleor-platform/Chart.yaml | 17 +- charts/saleor-storefront/Chart.yaml | 2 +- scripts/charts_ci.sh | 198 ++++++++++++++++++ scripts/ci.sh | 42 +++- scripts/make.sh | 1 + scripts/tag_helpers.sh | 62 ------ 19 files changed, 371 insertions(+), 118 deletions(-) create mode 100644 .azure-pipelines/templates/04_helm_push.yaml create mode 100644 .cr.yaml delete mode 100644 charts/saleor-platform/Chart.lock create mode 100755 scripts/charts_ci.sh mode change 100644 => 100755 scripts/tag_helpers.sh diff --git a/.azure-pipelines/templates/01_lint.yaml b/.azure-pipelines/templates/01_lint.yaml index 8835655..5e58c42 100644 --- a/.azure-pipelines/templates/01_lint.yaml +++ b/.azure-pipelines/templates/01_lint.yaml @@ -1,7 +1,7 @@ # @format --- stages: - - stage: Lint + - stage: lint displayName: Lint codebase condition: and( ne(variables['Build.SourceBranch'], 'refs/heads/master'), diff --git a/.azure-pipelines/templates/02_docker_build.yaml b/.azure-pipelines/templates/02_docker_build.yaml index 9d33e54..32233cd 100644 --- a/.azure-pipelines/templates/02_docker_build.yaml +++ b/.azure-pipelines/templates/02_docker_build.yaml @@ -1,13 +1,13 @@ # @format --- stages: - - stage: Build + - stage: docker_build displayName: Build images condition: and( ne(variables['Build.SourceBranch'], 'refs/heads/master'), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/')) ) - dependsOn: [] + dependsOn: [lint] jobs: - job: build_saleor_core displayName: Build saleor-core image diff --git a/.azure-pipelines/templates/03_docker_push.yaml b/.azure-pipelines/templates/03_docker_push.yaml index 495098f..29328d5 100644 --- a/.azure-pipelines/templates/03_docker_push.yaml +++ b/.azure-pipelines/templates/03_docker_push.yaml @@ -1,7 +1,7 @@ # @format --- stages: - - stage: Push + - stage: docker_push displayName: Push images condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') dependsOn: [] diff --git a/.azure-pipelines/templates/04_helm_push.yaml b/.azure-pipelines/templates/04_helm_push.yaml new file mode 100644 index 0000000..f0afd1d --- /dev/null +++ b/.azure-pipelines/templates/04_helm_push.yaml @@ -0,0 +1,53 @@ +# @format +--- +stages: + - stage: helm_push + displayName: Push saleor helm charts + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') + dependsOn: [] + jobs: + - deployment: helm_push_approval + displayName: Approval for push to registry + dependsOn: [] + continueOnError: false + timeoutInMinutes: 1296000 + cancelTimeoutInMinutes: 1296000 + environment: "Push saleor helm charts" + strategy: + runOnce: + deploy: + steps: + - script: echo "approval required" + + - job: push_saleor_helm_charts + displayName: Push saleor helm charts to github pages + dependsOn: [helm_push_approval] + condition: succeeded() + steps: + - template: ../init_step.yaml + + - task: Bash@3 + displayName: Configure git + inputs: + targetType: "inline" + workingDirectory: "$(Build.Repository.LocalPath)" + failOnStderr: false + noProfile: true + noRc: true + script: | + git config --global user.name "eirenauts-infra" + git config --global user.email "eirenauts-infra@users.noreply.github.com" + + - task: Bash@3 + displayName: Push saleor helm charts + inputs: + targetType: "inline" + workingDirectory: "$(Build.Repository.LocalPath)" + failOnStderr: false + noProfile: true + noRc: true + script: | + make push_updated_charts + env: + CR_TOKEN: $(crToken) + diff --git a/.cr.yaml b/.cr.yaml new file mode 100644 index 0000000..a06462b --- /dev/null +++ b/.cr.yaml @@ -0,0 +1,21 @@ +# @format + +owner: eirenauts +git-repo: saleor-k8s +charts-repo: https://eirenauts.github.io/saleor-k8s +# index-path: .packaged/index.yaml +index-path: index.yaml +package-path: .packaged +# sign +# key +# keyring +# passphrase-file +# token +git-base-url: https://api.github.com/ +git-upload-url: https://uploads.github.com/ +# commit +pages-branch: gh-pages +push: true +pr: false +remote: origin +# release-name-template diff --git a/.gitignore b/.gitignore index 1e3b14b..a4a9abd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,9 @@ saleor_core_dev saleor_dashboard saleor_storefront charts/saleor-platform/charts +charts/saleor-platform/tmpcharts +charts/saleor-platform/Chart.lock +downloads +*-x86_64 +index.yaml +.packaged diff --git a/.markdownlintignore b/.markdownlintignore index 155117f..16355b7 100644 --- a/.markdownlintignore +++ b/.markdownlintignore @@ -3,3 +3,4 @@ saleor_core/** saleor_core_dev/** saleor_dashboard/** saleor_storefront/** +downloads/** diff --git a/Makefile b/Makefile index 6db6021..94683b0 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ SHELL := /bin/bash init_docker \ init_docker_compose \ init_hadolint \ + init_chart_releaser \ init_all \ format_all \ lint_all \ @@ -21,7 +22,9 @@ SHELL := /bin/bash push_saleor_dashboard \ push_saleor_storefront \ get_image \ - get_image_version + get_image_version \ + push_image \ + push_updated_charts ## Dependency installation targets @@ -55,6 +58,9 @@ init_docker_compose: init_hadolint: if [ -z "$$(command -v install_hadolint)" ]; then ./scripts/make.sh install_hadolint "${HADOLINT_VERSION}"; fi +init_chart_releaser: + if [ -z "$$(command -v cr)" ]; then ./scripts/make.sh install_helm_chart_releaser "${CHART_RELEASER_VERSION}"; fi + init_all: \ init_yarn \ init_go \ @@ -62,7 +68,8 @@ init_all: \ init_shellcheck \ init_docker \ init_docker_compose \ - init_hadolint + init_hadolint \ + init_chart_releaser ## Code consistency/quality targets @@ -204,7 +211,7 @@ push_saleor_core_dev: "ghcr.io/eirenauts/saleor-core:dev-latest" echo "${REGISTRY_TOKEN}" | docker login ghcr.io -u eirenauts --password-stdin make -s push_image \ - IMAGE_VERSION="$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)" \ + IMAGE_VERSION="dev-$$(make -s get_image_version SALEOR_REPO=https://github.com/mirumee/saleor.git)" \ DOCKER_REPO=saleor-core \ FORCE_PUSH="${FORCE_PUSH_IMAGES}" docker logout ghcr.io @@ -247,3 +254,10 @@ push_saleor_storefront: FORCE_PUSH="${FORCE_PUSH_IMAGES}" docker logout ghcr.io if [[ -e /home/vsts/.docker/config.json ]]; then rm /home/vsts/.docker/config.json; fi + +push_updated_charts: + @if test -z "$(CR_TOKEN)"; then \ + echo "env variable CR_TOKEN is required" && \ + exit 1; \ + fi; + ./scripts/make.sh package_newly_versioned_charts "${CR_TOKEN}" diff --git a/README.md b/README.md index 3dd94df..030cf3a 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,35 @@ # saleor-k8s +[![Build Status](https://dev.azure.com/eirenauts/saleor-k8s/_apis/build/status/eirenauts.saleor-k8s?branchName=master)](https://dev.azure.com/eirenauts/saleor-k8s/_build/latest?definitionId=1&branchName=master) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://choosealicense.com/licenses/apache-2.0/) + ## saleor charts -## saleor containers +The umbrella chart required to deploy the entire saleor ecommerce platform is the `saleor-platform` chart. + +### List of charts + +| Chart Name | Notes | +| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | +| saleor-core | Handles deployment of `saleor-core` application. Includes a number of jobs for initialization tasks, backups and restore. | +| saleor-dashboard | Handles deployment of `saleor-dashboard` application as an nginx application. Required for the front end admin dashboard. | +| saleor-storefront | Handles deployment of `saleor-dashboard` application as an nginx application. Required for the front end UI where customers land. | +| saleor-platform | This is an umbrella chart. It does not deploy any single application but rather is deploys a collection of subcharts required for saleor to function. | + +### Example helm deployment + +There is freedom to deploy the `saleor-platform` chart in a number of different ways - not all of which have been tested out. -[![Build Status](https://dev.azure.com/eirenauts/saleor-k8s/_apis/build/status/eirenauts.saleor-k8s?branchName=master)](https://dev.azure.com/eirenauts/saleor-k8s/_build/latest?definitionId=1&branchName=master) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://choosealicense.com/licenses/apache-2.0/) ![Semver Version](https://img.shields.io/github/v/tag/eirenauts/saleor-k8s?color=blue&sort=semver) +An example deployment is illustrated here. -This repository is a collection of build files for the saleor container images. +TODO ### List of Images -| Image | Version | Base Image | Key Components | Purpose | -| ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -| [saleor-core](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-core) | [![Docker Version](https://img.shields.io/badge/version-1.3.0-blue)](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-core) | `python:3.8.6-slim` | `saleor core application - django, graphql, ecommerce app` | Backend for the saleor platform. Required for k8s deployments. | -| [saleor-dashboard](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-dashboard) | [![Docker Version](https://img.shields.io/badge/version-1.3.0-blue)](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-dashboard) | `nginxinc/nginx-unprivileged:1.19.5` | `javascript, reactjs` | Frontend for the admin dashboard for the saleor platform. Required for k8s deployments. | -| [saleor-storefront](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-storefront) | [![Docker Version](https://img.shields.io/badge/version-1.3.0-blue)](https://github.com/users/eirenauts/packages/saleor-k8s/package/saleor-storefront) | `nginxinc/nginx-unprivileged:1.19.5` | `javascript, reactjs` | Default frontend for the storefront for the saleor platform. Required for k8s deployments. Fork this if it is necessary to create a custom UI. | +| Image | Version | Base Image | Key Components | Purpose | +| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| [saleor-core](https://github.com/users/eirenauts/packages/container/package/saleor-core) | [![Docker Version](https://img.shields.io/badge/version-2.11.1-blue)](https://github.com/users/eirenauts/packages/container/package/saleor-core) | `python:3.8.6-slim` | `saleor core application - django, graphql, ecommerce app` | Backend for the saleor platform. Required for k8s deployments. | +| [saleor-dashboard](https://github.com/users/eirenauts/packages/container/package/saleor-dashboard) | [![Docker Version](https://img.shields.io/badge/version-2.11.1-blue)](https://github.com/users/eirenauts/packages/container/package/saleor-dashboard) | `nginxinc/nginx-unprivileged:1.19.5` | `javascript, reactjs` | Frontend for the admin dashboard for the saleor platform. Required for k8s deployments. | +| [saleor-storefront](https://github.com/users/eirenauts/packages/container/package/saleor-storefront) | [![Docker Version](https://img.shields.io/badge/version-2.11.1-blue)](https://github.com/users/eirenauts/packages/container/package/saleor-storefront) | `nginxinc/nginx-unprivileged:1.19.5` | `javascript, reactjs` | Default frontend for the storefront for the saleor platform. Required for k8s deployments. Fork this if it is necessary to create a custom UI. | ## Licence diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index e83b113..6a1ee49 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -27,8 +27,10 @@ variables: DOCKER_VERSION: 20.10.0 DOCKER_COMPOSE_VERSION: 1.27.4 HADOLINT_VERSION: 1.19.0 + CHART_RELEASER_VERSION: 1.1.1 stages: - template: .azure-pipelines/templates/01_lint.yaml - template: .azure-pipelines/templates/02_docker_build.yaml - template: .azure-pipelines/templates/03_docker_push.yaml + - template: .azure-pipelines/templates/04_helm_push.yaml diff --git a/charts/saleor-core/Chart.yaml b/charts/saleor-core/Chart.yaml index 019624f..b15f351 100644 --- a/charts/saleor-core/Chart.yaml +++ b/charts/saleor-core/Chart.yaml @@ -4,7 +4,7 @@ apiVersion: v2 name: saleor-core description: A Helm chart for deploying the saleor core application in Kubernetes type: application -version: 0.1.0 +version: 0.0.1 appVersion: 2.11.1 kubeVersion: ">=1.9.0" keywords: diff --git a/charts/saleor-dashboard/Chart.yaml b/charts/saleor-dashboard/Chart.yaml index 3409cba..f80537d 100644 --- a/charts/saleor-dashboard/Chart.yaml +++ b/charts/saleor-dashboard/Chart.yaml @@ -4,7 +4,7 @@ apiVersion: v2 name: saleor-dashboard description: A Helm chart for deploying the saleor dashboard application in Kubernetes type: application -version: 0.1.0 +version: 0.0.1 appVersion: 2.11.1 kubeVersion: ">=1.9.0" keywords: diff --git a/charts/saleor-platform/Chart.lock b/charts/saleor-platform/Chart.lock deleted file mode 100644 index c101efb..0000000 --- a/charts/saleor-platform/Chart.lock +++ /dev/null @@ -1,21 +0,0 @@ -dependencies: -- name: postgresql - repository: https://charts.bitnami.com/bitnami - version: 9.8.11 -- name: redis - repository: https://charts.bitnami.com/bitnami - version: 12.0.0 -- name: nfs-server-provisioner - repository: https://kvaps.github.io/charts - version: 1.1.1 -- name: saleor-core - repository: file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-core - version: 1.0.0 -- name: saleor-storefront - repository: file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-storefront - version: 1.0.0 -- name: saleor-dashboard - repository: file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-dashboard - version: 1.0.0 -digest: sha256:0fe5cbcac833cc69562ca8b2d5fb81d16f1c066c38d1b087c87db0086e68715e -generated: "2020-12-06T00:36:44.047306455+01:00" diff --git a/charts/saleor-platform/Chart.yaml b/charts/saleor-platform/Chart.yaml index 906a51f..b09ed83 100644 --- a/charts/saleor-platform/Chart.yaml +++ b/charts/saleor-platform/Chart.yaml @@ -4,7 +4,7 @@ apiVersion: v2 name: saleor-platform description: A Helm chart for deploying the entire umbrella of saleor charts type: application -version: 0.1.0 +version: 0.0.1 appVersion: 2.11.1 kubeVersion: ">=1.9.0" keywords: @@ -54,9 +54,8 @@ dependencies: ## 2. Pods for the web server (for static assets and media assets) if not using cloud storage ## 3. Pods for the celery workers which execute particular tasks on demand - name: saleor-core - version: "1.0.0" - # repository: "https://rg.fr-par.scw.cloud/private-helm-repo-scw-prod/saleor-core" - repository: "file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-core" + version: "0.0.1" + repository: "https://eirenauts.github.io/saleor-k8s" condition: saleor-core.enabled tags: - workers @@ -65,9 +64,8 @@ dependencies: ## Notes: This is a web server of pre-built static assets and emails for the storefront which customers see - name: saleor-storefront - version: "1.0.0" - # repository: "https://rg.fr-par.scw.cloud/private-helm-repo-scw-prod/saleor-storefront" - repository: "file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-storefront" + version: "0.0.1" + repository: "https://eirenauts.github.io/saleor-k8s" condition: saleor-storefront.enabled tags: - ui @@ -75,9 +73,8 @@ dependencies: ## Notes: This is a web server of pre-built static assets for the administrative dashboard - name: saleor-dashboard - version: "1.0.0" - # repository: "https://rg.fr-par.scw.cloud/private-helm-repo-scw-prod/saleor-dashboard" - repository: "file:///home/u1/Documents/repos/saleor-components/saleor-k8s-intermediate/charts/saleor-dashboard" + version: "0.0.1" + repository: "https://eirenauts.github.io/saleor-k8s" condition: saleor-dashboard.enabled tags: - ui diff --git a/charts/saleor-storefront/Chart.yaml b/charts/saleor-storefront/Chart.yaml index 7f10826..8c46f77 100644 --- a/charts/saleor-storefront/Chart.yaml +++ b/charts/saleor-storefront/Chart.yaml @@ -4,7 +4,7 @@ apiVersion: v2 name: saleor-storefront description: A Helm chart for deploying the saleor storefront application in Kubernetes type: application -version: 0.1.0 +version: 0.0.1 appVersion: 2.11.1 kubeVersion: ">=1.9.0" keywords: diff --git a/scripts/charts_ci.sh b/scripts/charts_ci.sh new file mode 100755 index 0000000..721e63a --- /dev/null +++ b/scripts/charts_ci.sh @@ -0,0 +1,198 @@ +#!/bin/bash +# @description +# +# Example Usage +# +# * Set saleor-core chart at 0.1.0 as the chart version and 2.11.1 as the appVersion +# +# version_chart "0.1.0" "2.11.1" "charts/saleor-core" +# +# Example Usage +# +# * Set versions for all the charts +# +# version_chart "0.1.0" "2.11.1" "charts/saleor-core" +# version_chart "0.1.0" "2.11.1" "charts/saleor-dashboard" +# version_chart "0.1.0" "2.11.1" "charts/saleor-storefront" +# version_chart "0.1.0" "2.11.1" "charts/saleor-platform" +# +# Note: appVersion in saleor-platform is inherently ignored + +function get_current_chart_version() { + local chart_dir="${1}" + + if [[ -z "${chart_dir}" ]]; then + echo "Variable chart_dir is required" >>/dev/stderr + return + fi + + helm show chart "${chart_dir}/" | + grep 'version' | + tail -1 | + cut -c 10- +} + +function get_previous_chart_version() { + local chart_dir="${1}" + local previous_release + local previous_checkout_point + + previous_release=$(git tag --list | tail -2 | awk 'NR==1') + + if [[ -z "${chart_dir}" ]]; then + echo "Variable chart_dir is required" >>/dev/stderr + return + fi + + if [[ -z "${previous_release}" ]]; then + previous_checkout_point=HEAD~1 + else + previous_checkout_point="${previous_release}" + fi + + git checkout -q "${previous_checkout_point}" + + previous_chart_version=$( + helm show chart "${chart_dir}/" | + grep 'version' | + tail -1 | + cut -c 10- + ) + + git checkout -q - + + echo "${previous_chart_version}" +} + +function get_current_app_version() { + local chart_dir="${1}" + + helm show chart "${chart_dir}/" | + grep 'appVersion' | + awk '{print $2}' | + tr -d '"' +} + +function version_chart() { + local chart_tag="${1}" + local app_tag=$2 + local chart_dir=$3 + + if [[ "${chart_tag}" != "$(get_current_chart_version "${chart_dir}")" ]]; then + sed -i "s|version: $(get_current_chart_version "${chart_dir}")|version: ${chart_tag}|" "${chart_dir}/Chart.yaml" + fi + + if [[ -n "${app_tag}" ]] && [[ "${app_tag}" != "$(get_current_app_version "${chart_dir}")" ]]; then + sed -i "s|appVersion: \"$(get_current_app_version "${chart_dir}")\"|appVersion: \"${app_tag}\"|" "${chart_dir}/Chart.yaml" + fi +} + +function package_chart() { + local chart_dir="${1}" + + echo "Packaging chart ${chart_dir}..." + cr package \ + "${chart_dir}" \ + --config .cr.yaml +} + +function upload_packaged() { + local token="${1}" + + if [[ -z "${token}" ]]; then + echo "Variable token is required" >>/dev/stderr + return + fi + + if [[ -d .packaged ]]; then + echo 'Uploading charts...' + cr upload \ + --token "${token}" \ + --config .cr.yaml + else + echo "No charts have been packaged, skipping upload" + fi +} + +function reindex() { + local token="${1}" + + if [[ -z "${token}" ]]; then + echo "Variable token is required" >>/dev/stderr + return + fi + + if [[ -d .packaged ]]; then + echo 'Updating repo index...' + cr index \ + --token "${token}" \ + --config .cr.yaml + else + echo "No charts have been packaged, skipping index update" + fi +} + +function add_required_subcharts() { + helm repo add saleor-k8s https://eirenauts.github.io/saleor-k8s + helm repo add kvaps https://kvaps.github.io/charts + helm repo add bitnami https://charts.bitnami.com/bitnami +} + +function package_newly_versioned_charts() { + local token="${1}" + local newly_versioned_charts + + if [[ -z "${token}" ]]; then + echo "Variable token is required" >>/dev/stderr + return + fi + + newly_versioned_charts=() + + for chart in ./charts/*; do + if [[ -d "${chart}" ]]; then + current_chart_version="$(get_current_chart_version "${chart}")" + previous_chart_version="$(get_previous_chart_version "${chart}")" + if [[ "${current_chart_version}" != "${previous_chart_version}" ]]; then + newly_versioned_charts+=("${chart}") + fi + fi + done + + if [[ ${#newly_versioned_charts[@]} -eq 0 ]]; then + echo "No chart version has changed since last release. No action taken." + rm -rf .packaged + else + rm -rf .packaged && mkdir .packaged + for chart in "${newly_versioned_charts[@]}"; do + if [[ -d "${chart}" ]] && [[ "${chart}" != "./charts/saleor-platform" ]]; then + package_chart "${chart}" + fi + done + + upload_packaged "${token}" + sleep 8s + reindex "${token}" + sleep 8s + + for chart in "${newly_versioned_charts[@]}"; do + if [[ -d "${chart}" ]] && [[ "${chart}" == "./charts/saleor-platform" ]]; then + rm -rf .packaged + if [[ -d ./charts/saleor-platform/charts ]]; then + rm -rf ./charts/saleor-platform/charts + fi + if [[ -d ./charts/saleor-platform/tmpcharts ]]; then + rm -rf ./charts/saleor-platform/tmpcharts + fi + add_required_subcharts + helm dep update "${chart}" + package_chart "${chart}" + fi + done + + upload_packaged "${token}" + sleep 8s + reindex "${token}" + sleep 8s + fi +} diff --git a/scripts/ci.sh b/scripts/ci.sh index e272032..f89f00b 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# shellcheck shell=bash disable=SC1090 +# shellcheck shell=bash disable=SC1090,SC2015 function install_yarn() { sudo apt update -y -qq && sudo apt install -y -qq curl gnupg && @@ -130,6 +130,24 @@ function install_hadolint() { hadolint --version } +function install_helm_chart_releaser() { + local release="${1}" + local download_url + download_url=https://github.com/helm/chart-releaser/releases/download + + if [[ -z "${release}" ]]; then + release=1.1.1 + fi + + mkdir -p ./downloads/cr + + wget --quiet "${download_url}/v${release}/chart-releaser_${release}_linux_amd64.tar.gz" && + tar -C ./downloads/cr -xvzf chart-releaser_${release}_linux_amd64.tar.gz && + sudo chmod +x ./downloads/cr/cr && + sudo mv ./downloads/cr/cr /usr/local/bin/cr && + cr version +} + function format_yaml() { yarn prettier --write ./**/*.y*ml } @@ -239,6 +257,10 @@ function get_redacted_git_branch() { sed --regexp-extended 's|\W|-|g' <<<"$(get_git_branch)" } +function get_short_sha() { + git rev-parse --short --quiet HEAD +} + function get_image_version() { local saleor_repo="${1}" local branch @@ -249,11 +271,11 @@ function get_image_version() { fi branch="$(get_redacted_git_branch)" - + short_sha="$(get_short_sha)" required_version="$(get_required_app_version "${saleor_repo}")" if [[ -z "$(get_git_tag)" ]]; then - echo "${branch}-${required_version}" + echo "${branch}-${short_sha}" else echo "${required_version}" fi @@ -348,6 +370,14 @@ function prepare_saleor_source() { cat Dockerfile } +function docker_push() { + local docker_repo="${1}" + local image_version="${2}" + + docker push "ghcr.io/eirenauts/${docker_repo}:${image_version}" && + docker push "ghcr.io/eirenauts/${docker_repo}:latest" +} + function push_image() { local image_version="${1}" local docker_repo="${2}" @@ -365,12 +395,10 @@ function push_image() { if [[ -n "${force_push}" ]]; then echo "Force pushing images" - docker push "ghcr.io/eirenauts/${docker_repo}:${image_version}" && - docker push "ghcr.io/eirenauts/${docker_repo}:latest" + docker_push "${docker_repo}" "${image_version}" else docker manifest inspect "ghcr.io/eirenauts/${docker_repo}:${image_version}" >/dev/null 2>&1 && echo "Image already exists, skipping push" || - docker push "ghcr.io/eirenauts/${docker_repo}:${image_version}" && - docker push "ghcr.io/eirenauts/${docker_repo}:latest" + docker_push "${docker_repo}" "${image_version}" fi } diff --git a/scripts/make.sh b/scripts/make.sh index b6cbb86..1aa5102 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -7,5 +7,6 @@ set -o pipefail source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/ci.sh" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/env.sh" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/charts_ci.sh" "$@" diff --git a/scripts/tag_helpers.sh b/scripts/tag_helpers.sh old mode 100644 new mode 100755 index 0f7b3c6..a9bf588 --- a/scripts/tag_helpers.sh +++ b/scripts/tag_helpers.sh @@ -1,63 +1 @@ #!/bin/bash - -function is_valid_semver_tag() { - local tag=$1 - local tag_regex='([0-9]+\.){2,2}(\*|[0-9]+)(\-.*){0,1}' - - if [[ -z "${tag}" ]]; then - echo "A valid tag must be passed as the first argument" >>/dev/stderr - return 0 - fi - - if [[ "${tag}" =~ $tag_regex ]]; then echo "true"; else echo "false"; fi -} - -function get_current_chart_version() { - local chart_dir=$1 - - helm show chart "${chart_dir}/" | - grep 'version' | - tail -1 | - cut -c 10- -} - -function get_current_app_version() { - local chart_dir=$1 - - helm show chart "${chart_dir}/" | - grep 'appVersion' | - awk '{print $2}' | - tr -d '"' -} - -function version_chart() { - local chart_tag=$1 - local app_tag=$2 - local chart_dir=$3 - - if [[ "${chart_tag}" != "$(get_current_chart_version "${chart_dir}")" ]]; then - sed -i "s|version: $(get_current_chart_version "${chart_dir}")|version: ${chart_tag}|" "${chart_dir}/Chart.yaml" - fi - - if [[ -n "${app_tag}" ]] && [[ "${app_tag}" != "$(get_current_app_version "${chart_dir}")" ]]; then - sed -i "s|appVersion: \"$(get_current_app_version "${chart_dir}")\"|appVersion: \"${app_tag}\"|" "${chart_dir}/Chart.yaml" - fi -} - -function apply_tag() { - local tag=$1 - local app_version=$2 - - if [[ "$(is_valid_semver_tag "${tag}")" != "true" ]]; then - echo "A valid semver tag must be passed as the first argument" >>/dev/stderr - return 0 - fi - - # Tag the chart - echo "Versioning the chart with version ${tag} and appVersion ${app_version}" - version_chart "${tag}" "${app_version}" - - # Tag the git repo - echo "Tagging git repo with version ${tag}" - git tag "${tag}" -}