diff --git a/helm_deploy_example b/helm_deploy_example new file mode 100644 index 0000000..9a673f7 --- /dev/null +++ b/helm_deploy_example @@ -0,0 +1,69 @@ +#!/bin/bash + +# helm_deploy configuration checklist: +# If the ./hyrax chart directory exists, move the contents to the ./chart directory +# Set the ENCODED_ENV_FILE, +# Substitute the $TAG variable in the values file for each +# service (web/solr/worker,etc.) with a specified image, example: +# web: +# image: +# tag: $TAG + + +# Local setup for deploys: Uncomment to enable Helm dry-run and debug mode +# Documentation: https://helm.sh/docs/chart_template_guide/debugging/#helm +# DRY_RUN_DEBUG="--dry-run --debug" + +# Deployment logic and usage examples for GitHub Actions +# Naming convention: reponame-environment, repo-name-environment, or repo_name_environment +# Use-case #1 : ./bin/helm_deploy arce-staging arce-staging +# Use-case #2 : ./bin/helm_deploy atla-omeka-staging atla-omeka-staging +# Use-case #3 : ./bin/helm_deploy hykuup_knapsack-staging hykuup_knapsack-staging +if [ -z "$1" ] || [ -z "$2" ] +then + echo './bin/helm_deploy RELEASE_NAME NAMESPACE (ENVIRONMENT)' + exit 1 +fi + +# Replaces underscores with hyphens in input arguments for use-case #3 +release_name="${1//_/-}" +namespace="${2//_/-}" +environment="${3}" + +TAG="${TAG:-latest}" +deploy_file="${environment}-deploy" +HELM_EXTRA_ARGS="--values ops/${deploy_file}.yaml" +ENV_FILE="./.env.${environment}" + +# Deploying through CI: Handling encrypted environment variables +# If the specified environment file does not exist, create and decode the encrypted content +if [ ! -f "$ENV_FILE" ]; then + touch "./.env.${environment}" + echo "$ENCODED_ENV_FILE" | base64 -d > "./.env.${environment}" +fi + +# Export key-value pairs from the env file to use with envsubst during deployment +while IFS='=' read -r key value; do + export "$key=${value//\"/}" +done < <(grep -v '^#' "$ENV_FILE") + +DOLLAR=$ envsubst <"ops/${deploy_file}.tmpl.yaml" >"ops/${deploy_file}.yaml" + +# Ensure availability of necessary Hyku/Hyrax charts in the "chart" directory +# for standardized Kubernetes deployment. +if [ ! -d chart ]; then + CHART_VERSION="${CHART_VERSION:-2.0.0}" + helm pull --untar oci://ghcr.io/samvera/charts/hyrax --version $CHART_VERSION + mv hyrax chart +fi + +helm upgrade \ + --install \ + --atomic \ + --timeout 15m0s \ + $HELM_EXTRA_ARGS \ + $DRY_RUN_DEBUG \ + --namespace="$namespace" \ + --create-namespace \ + "$release_name" \ + chart