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

refactor: use $environment_type & $environment_name

Deprecated $appname and $env dynamic variables with $environment_name & $environment_type
With backward compatibility (legacy vars still usable)
parent 61900bb8
No related branches found
No related tags found
No related merge requests found
...@@ -152,8 +152,6 @@ Here are variables supported to configure review environments: ...@@ -152,8 +152,6 @@ Here are variables supported to configure review environments:
| `HELM_REVIEW_ENVIRONMENT_SCHEME` | The review environment protocol scheme | `https` | | `HELM_REVIEW_ENVIRONMENT_SCHEME` | The review environment protocol scheme | `https` |
| `HELM_REVIEW_ENVIRONMENT_DOMAIN` | The review environment domain | _none_ | | `HELM_REVIEW_ENVIRONMENT_DOMAIN` | The review environment domain | _none_ |
Note: By default review `environment.url` will be built as `${HELM_REVIEW_ENVIRONMENT_SCHEME}://${$CI_PROJECT_NAME}-${CI_ENVIRONMENT_SLUG}.${HELM_REVIEW_ENVIRONMENT_DOMAIN}`
#### Integration environment #### Integration environment
The integration environment is the environment associated to your integration branch (`develop` by default). The integration environment is the environment associated to your integration branch (`develop` by default).
...@@ -222,9 +220,9 @@ In order to be able to implement some **genericity** in your scripts and templat ...@@ -222,9 +220,9 @@ In order to be able to implement some **genericity** in your scripts and templat
2. you should use available environment variables: 2. you should use available environment variables:
* any [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/#predefined-environment-variables) * any [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
(ex: `${CI_ENVIRONMENT_URL}` to retrieve the actual environment exposed route) (ex: `${CI_ENVIRONMENT_URL}` to retrieve the actual environment exposed route)
* any [custom variable](https://docs.gitlab.com/ee/ci/variables/#custom-environment-variables) * any [custom variable](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project)
(ex: `${SECRET_TOKEN}` that you have set in your project CI/CD variables) (ex: `${SECRET_TOKEN}` that you have set in your project CI/CD variables)
> :warning: > :warning:
......
...@@ -368,19 +368,28 @@ stages: ...@@ -368,19 +368,28 @@ stages:
# deploy application # deploy application
function deploy() { function deploy() {
export env=$1 export environment_type=$1
export appname=$2 export environment_name=$2
namespace=$3
values_files=$4
# backwards compatibility
export env=$environment_type
export appname=$environment_name
# extract hostname from $CI_ENVIRONMENT_URL # extract hostname from $CI_ENVIRONMENT_URL
hostname=$(echo "$CI_ENVIRONMENT_URL" | awk -F[/:] '{print $4}') hostname=$(echo "$CI_ENVIRONMENT_URL" | awk -F[/:] '{print $4}')
export hostname export hostname
namespace=$3 log_info "--- \\e[32mdeploy\\e[0m"
values_files=$4 log_info "--- \$namespace: \\e[33;1m${namespace}\\e[0m"
log_info "--- \$environment_type: \\e[33;1m${environment_type}\\e[0m"
log_info "--- \$environment_name: \\e[33;1m${environment_name}\\e[0m"
log_info "--- \$hostname: \\e[33;1m${hostname}\\e[0m"
log_info "--- \\e[32mdeploy\\e[0m (env: \\e[33;1m${env}\\e[0m)" # unset any upstream deployment env & artifacts
log_info "--- appname: \\e[33;1m${appname}\\e[0m" rm -f helm.env
log_info "--- env: \\e[33;1m${env}\\e[0m" rm -f environment_url.txt
log_info "--- hostname: \\e[33;1m${hostname}\\e[0m"
helm_opts=$(get_helm_config_opt) helm_opts=$(get_helm_config_opt)
...@@ -415,24 +424,28 @@ stages: ...@@ -415,24 +424,28 @@ stages:
fi fi
log_info "--- using \\e[32mpackage\\e[0m: \\e[33;1m${package}\\e[0m" log_info "--- using \\e[32mpackage\\e[0m: \\e[33;1m${package}\\e[0m"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $helm_values_opt --set "${HELM_ENV_VALUE_NAME}=$env,${HELM_HOSTNAME_VALUE_NAME}=$hostname" $HELM_DEPLOY_ARGS $appname $package helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $helm_values_opt --set "${HELM_ENV_VALUE_NAME}=$environment_type,${HELM_HOSTNAME_VALUE_NAME}=$hostname" $HELM_DEPLOY_ARGS $environment_name $package
# finally persist environment url # finally persist environment url
echo "$CI_ENVIRONMENT_URL" > environment_url.txt echo "$CI_ENVIRONMENT_URL" > environment_url.txt
echo -e "environment_type=$env\\nenvironment_name=$appname\\nenvironment_url=$CI_ENVIRONMENT_URL" > helm.env echo -e "environment_type=$environment_type\\nenvironment_name=$environment_name\\nenvironment_url=$CI_ENVIRONMENT_URL" > helm.env
} }
# delete application (and dependencies) # delete application (and dependencies)
function delete() { function delete() {
export env=$1 export environment_type=$1
export appname=$2 export environment_name=$2
namespace=$3 namespace=$3
log_info "--- \\e[32mdelete\\e[0m (env: ${env})" # backwards compatibility
log_info "--- appname: \\e[33;1m${appname}\\e[0m" export env=$environment_type
log_info "--- env: \\e[33;1m${env}\\e[0m" export appname=$environment_name
log_info "--- \\e[32mdelete"
log_info "--- \$namespace: \\e[33;1m${namespace}\\e[0m"
log_info "--- \$environment_type: \\e[33;1m${environment_type}\\e[0m"
log_info "--- \$environment_name: \\e[33;1m${environment_name}\\e[0m"
helm_opts=$(get_helm_config_opt) helm_opts=$(get_helm_config_opt)
...@@ -447,18 +460,19 @@ stages: ...@@ -447,18 +460,19 @@ stages:
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $HELM_DELETE_ARGS $appname helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $HELM_DELETE_ARGS $environment_name
} }
# test application (and dependencies) # test application (and dependencies)
function test() { function test() {
export env=$1 export environment_type=$1
export appname=$2 export environment_name=$2
namespace=$3 namespace=$3
log_info "--- \\e[32mtest\\e[0m (env: ${env})" log_info "--- \\e[32mtest\\e[0m (env: ${environment_type})"
log_info "--- appname: \\e[33;1m${appname}\\e[0m" log_info "--- \$namespace: \\e[33;1m${namespace}\\e[0m"
log_info "--- env: \\e[33;1m${env}\\e[0m" log_info "--- \$environment_name: \\e[33;1m${environment_name}\\e[0m"
log_info "--- \$environment_type: \\e[33;1m${environment_type}\\e[0m"
helm_opts=$(get_helm_config_opt) helm_opts=$(get_helm_config_opt)
...@@ -473,7 +487,7 @@ stages: ...@@ -473,7 +487,7 @@ stages:
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $HELM_TEST_ARGS $appname helm ${TRACE+--debug} $helm_opts $helm_namespace_opt $HELM_TEST_ARGS $environment_name
} }
function maybe_install_curl() { function maybe_install_curl() {
......
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