Skip to content
Snippets Groups Projects
Commit fcd186e8 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

refactor: manage Helm config and cache with env

parent 698111e6
No related branches found
No related tags found
No related merge requests found
...@@ -325,10 +325,6 @@ stages: ...@@ -325,10 +325,6 @@ stages:
done done
} }
function get_helm_opts() {
echo "${TRACE+--debug} --registry-config $CI_PROJECT_DIR/.config/helm/registry.json --repository-cache $CI_PROJECT_DIR/.cache/helm/repository --repository-config $CI_PROJECT_DIR/.config/helm/repositories.yaml"
}
function setup_kubeconfig() { function setup_kubeconfig() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
export KUBECONFIG="$CI_PROJECT_DIR/.kubeconfig" export KUBECONFIG="$CI_PROJECT_DIR/.kubeconfig"
...@@ -345,10 +341,6 @@ stages: ...@@ -345,10 +341,6 @@ stages:
# Use cacheable folders # Use cacheable folders
mkdir -p "$CI_PROJECT_DIR/.config/helm/" mkdir -p "$CI_PROJECT_DIR/.config/helm/"
mkdir -p "$CI_PROJECT_DIR/.cache/helm/repository/" mkdir -p "$CI_PROJECT_DIR/.cache/helm/repository/"
ln -s "$CI_PROJECT_DIR/.cache" ~/.cache
ln -s "$CI_PROJECT_DIR/.config" ~/.config
helm_opts=$(get_helm_opts)
# Install helm repositories # Install helm repositories
for repo in $HELM_REPOS for repo in $HELM_REPOS
...@@ -367,7 +359,7 @@ stages: ...@@ -367,7 +359,7 @@ stages:
log_info "--- login to OCI-registry \\e[32m${repo_name}\\e[0m: \\e[33;1m${registry_host}\\e[0m" log_info "--- login to OCI-registry \\e[32m${repo_name}\\e[0m: \\e[33;1m${registry_host}\\e[0m"
export HELM_EXPERIMENTAL_OCI=1 export HELM_EXPERIMENTAL_OCI=1
# shellcheck disable=SC2086 # shellcheck disable=SC2086
echo "$repo_password" | helm $helm_opts registry login "$registry_host" --username "$repo_user" --password-stdin echo "$repo_password" | helm ${TRACE+--debug} registry login "$registry_host" --username "$repo_user" --password-stdin
else else
log_warn "--- OCI-registry \\e[32m${repo_name}\\e[0m (\\e[33;1m${repo_url}\\e[0m) defined, but no credentials found (\$HELM_REPO_${repo_name_ssc}_USER/\$HELM_REPO_${repo_name_ssc}_PASSWORD)" log_warn "--- OCI-registry \\e[32m${repo_name}\\e[0m (\\e[33;1m${repo_url}\\e[0m) defined, but no credentials found (\$HELM_REPO_${repo_name_ssc}_USER/\$HELM_REPO_${repo_name_ssc}_PASSWORD)"
fi fi
...@@ -376,17 +368,17 @@ stages: ...@@ -376,17 +368,17 @@ stages:
then then
log_info "--- add repository \\e[32m${repo_name}\\e[0m: \\e[33;1m${repo_url}\\e[0m (with user/password auth)" log_info "--- add repository \\e[32m${repo_name}\\e[0m: \\e[33;1m${repo_url}\\e[0m (with user/password auth)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
echo "$repo_password" | helm $helm_opts repo add "$repo_name" "$repo_url" --username "$repo_user" --password-stdin echo "$repo_password" | helm ${TRACE+--debug} repo add "$repo_name" "$repo_url" --username "$repo_user" --password-stdin
else else
log_info "--- add repository \\e[32m${repo_name}\\e[0m: \\e[33;1m${repo_url}\\e[0m (unauthenticated)" log_info "--- add repository \\e[32m${repo_name}\\e[0m: \\e[33;1m${repo_url}\\e[0m (unauthenticated)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts repo add "$repo_name" "$repo_url" helm ${TRACE+--debug} repo add "$repo_name" "$repo_url"
fi fi
fi fi
done done
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts repo update helm ${TRACE+--debug} repo update
} }
function awkenvsubst() { function awkenvsubst() {
...@@ -438,7 +430,7 @@ stages: ...@@ -438,7 +430,7 @@ stages:
log_info "--- \\e[32mpre-deploy hook\\e[0m (\\e[33;1m${prescript}\\e[0m) not found: skip" log_info "--- \\e[32mpre-deploy hook\\e[0m (\\e[33;1m${prescript}\\e[0m) not found: skip"
fi fi
helm_opts=$(get_helm_opts) helm_opts=${TRACE+--debug}
helm_opts="$helm_opts --set ${HELM_ENV_VALUE_NAME}=$environment_type" helm_opts="$helm_opts --set ${HELM_ENV_VALUE_NAME}=$environment_type"
helm_opts="$helm_opts --set ${HELM_HOSTNAME_VALUE_NAME}=$hostname" helm_opts="$helm_opts --set ${HELM_HOSTNAME_VALUE_NAME}=$hostname"
...@@ -517,7 +509,7 @@ stages: ...@@ -517,7 +509,7 @@ stages:
log_info "--- \\e[32mpre-delete hook\\e[0m (\\e[33;1m${prescript}\\e[0m) not found: skip" log_info "--- \\e[32mpre-delete hook\\e[0m (\\e[33;1m${prescript}\\e[0m) not found: skip"
fi fi
helm_opts=$(get_helm_opts) helm_opts=${TRACE+--debug}
if [ -f "$CI_PROJECT_DIR/.kubeconfig" ]; then if [ -f "$CI_PROJECT_DIR/.kubeconfig" ]; then
log_info "--- using \\e[32mkubeconfig\\e[0m: \\e[33;1m$CI_PROJECT_DIR/.kubeconfig\\e[0m" log_info "--- using \\e[32mkubeconfig\\e[0m: \\e[33;1m$CI_PROJECT_DIR/.kubeconfig\\e[0m"
...@@ -553,7 +545,7 @@ stages: ...@@ -553,7 +545,7 @@ stages:
log_info "--- \$environment_name: \\e[33;1m${environment_name}\\e[0m" log_info "--- \$environment_name: \\e[33;1m${environment_name}\\e[0m"
log_info "--- \$environment_type: \\e[33;1m${environment_type}\\e[0m" log_info "--- \$environment_type: \\e[33;1m${environment_type}\\e[0m"
helm_opts=$(get_helm_opts) helm_opts=${TRACE+--debug}
if [ -f "$CI_PROJECT_DIR/.kubeconfig" ]; then if [ -f "$CI_PROJECT_DIR/.kubeconfig" ]; then
log_info "--- using \\e[32mkubeconfig\\e[0m: \\e[33;1m$CI_PROJECT_DIR/.kubeconfig\\e[0m" log_info "--- using \\e[32mkubeconfig\\e[0m: \\e[33;1m$CI_PROJECT_DIR/.kubeconfig\\e[0m"
...@@ -584,16 +576,13 @@ stages: ...@@ -584,16 +576,13 @@ stages:
fi fi
add_helm_repositories add_helm_repositories
helm_opts=$(get_helm_opts)
# helm package # helm package
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts $HELM_PACKAGE_ARGS $helm_version_opts $HELM_CHART_DIR --destination helm_packages helm ${TRACE+--debug} $HELM_PACKAGE_ARGS $helm_version_opts $HELM_CHART_DIR --destination helm_packages
} }
function helm_publish() { function helm_publish() {
helm_opts=$(get_helm_opts)
helm_package=$(ls -1 ./helm_packages/*.tgz 2>/dev/null || echo "") helm_package=$(ls -1 ./helm_packages/*.tgz 2>/dev/null || echo "")
if [[ -z "$helm_package" ]]; then if [[ -z "$helm_package" ]]; then
log_error "No package found to deploy" log_error "No package found to deploy"
...@@ -633,17 +622,17 @@ stages: ...@@ -633,17 +622,17 @@ stages:
then then
registry_host=$(echo "$HELM_PUBLISH_URL" | awk -F[/:] '{print $4}') registry_host=$(echo "$HELM_PUBLISH_URL" | awk -F[/:] '{print $4}')
# shellcheck disable=SC2086 # shellcheck disable=SC2086
echo "$password" | helm $helm_opts registry login "$registry_host" --username "$username" --password-stdin echo "$password" | helm ${TRACE+--debug} registry login "$registry_host" --username "$username" --password-stdin
# enable OCI support prior to v3.8.0 # enable OCI support prior to v3.8.0
export HELM_EXPERIMENTAL_OCI=1 export HELM_EXPERIMENTAL_OCI=1
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts push "$helm_package" "$HELM_PUBLISH_URL" helm ${TRACE+--debug} push "$helm_package" "$HELM_PUBLISH_URL"
else else
log_info "Installing cm-push plugin (version ${HELM_CM_PUSH_PLUGIN_VERSION:-latest})..." log_info "Installing cm-push plugin (version ${HELM_CM_PUSH_PLUGIN_VERSION:-latest})..."
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts plugin install ${HELM_CM_PUSH_PLUGIN_VERSION:+--version "$HELM_CM_PUSH_PLUGIN_VERSION"} https://github.com/chartmuseum/helm-push || true helm ${TRACE+--debug} plugin install ${HELM_CM_PUSH_PLUGIN_VERSION:+--version "$HELM_CM_PUSH_PLUGIN_VERSION"} https://github.com/chartmuseum/helm-push || true
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm $helm_opts cm-push --username "$username" --password "$password" "$helm_package" "$HELM_PUBLISH_URL" helm ${TRACE+--debug} cm-push --username "$username" --password "$password" "$helm_package" "$HELM_PUBLISH_URL"
fi fi
;; ;;
post) post)
...@@ -683,6 +672,9 @@ stages: ...@@ -683,6 +672,9 @@ stages:
services: services:
- name: "$TBC_TRACKING_IMAGE" - name: "$TBC_TRACKING_IMAGE"
command: ["--service", "helm", "3.3.2" ] command: ["--service", "helm", "3.3.2" ]
variables:
HELM_CACHE_HOME: $CI_PROJECT_DIR/.cache/helm
HELM_CONFIG_HOME: $CI_PROJECT_DIR/.config/helm
before_script: before_script:
- *helm-scripts - *helm-scripts
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment