Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: NOT WORKING: add-helm-deploy-example #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions helm_deploy_example
Original file line number Diff line number Diff line change
@@ -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