Skip to content

Commit

Permalink
Merge branch 'ntr/2024-05-16-1133-fix-deployment-prep' into 'trunk'
Browse files Browse the repository at this point in the history
NEXT-00000 - base64 encode environment variables before passing them on to...

See merge request shopware/6/product/platform!13865
  • Loading branch information
pweyck committed May 16, 2024
2 parents db41494 + 32c165d commit 9104fce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
25 changes: 19 additions & 6 deletions .gitlab/bin/compile_deployment_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if [ -n "${DEBUG:-}" ]; then
set -x
fi

GITLAB_TOKEN="${GITLAB_TOKEN:-$CI_JOB_TOKEN}"
CI_JOB_TOKEN="${CI_JOB_TOKEN}"
CI_CURRENT_MAJOR_ALIAS="${CI_CURRENT_MAJOR_ALIAS:-}"

Expand Down Expand Up @@ -55,7 +56,6 @@ commit_date() {
local project="${1}"
local branch="${2}"

export GITLAB_TOKEN="${CI_JOB_TOKEN}"
export GITLAB_HOST="gitlab.shopware.com"

glab api "projects/${project}/repository/commits/${branch}" | jq -r '.committed_date' | xargs -I '{}' date -R --date="{}"
Expand Down Expand Up @@ -88,8 +88,12 @@ deployment_env() {
local update_extensions="${1:-}"

local deployment_branch_name="$(deployment_branch_name)"
local ci_update_dependency="1"
local gitlab_mr_description="$(gitlab_mr_description)"
local custom_version=""
local gitlab_mr_title="Deployment - ${deployment_branch_name}"
local gitlab_mr_labels="workflow::development"
local gitlab_mr_assignees="shopwarebot"

if [ -n "${update_extensions}" ]; then
custom_version="$(custom_version_core);$(custom_version_extensions)"
Expand All @@ -99,13 +103,22 @@ deployment_env() {

cat <<EOF
DEPLOYMENT_BRANCH_NAME="${deployment_branch_name}"
CI_UPDATE_DEPENDENCY="1"
CUSTOM_VERSION=${custom_version}
GITLAB_MR_TITLE="Deployment - ${deployment_branch_name}"
CI_UPDATE_DEPENDENCY="${ci_update_dependency}"
CUSTOM_VERSION="${custom_version}"
GITLAB_MR_TITLE="${gitlab_mr_title}"
GITLAB_MR_DESCRIPTION_TEXT="${gitlab_mr_description}"
GITLAB_MR_LABELS="workflow::development"
GITLAB_MR_ASSIGNEES="shopwarebot"
GITLAB_MR_LABELS="${gitlab_mr_labels}"
GITLAB_MR_ASSIGNEES="${gitlab_mr_assignees}"
EOF
}

deployment_env_b64() {
local target_var="${1}"
local update_extensions="${2:-}"

printf "%s=%s\n" "${target_var}" "$(deployment_env ${update_extensions} | base64 -w0)"
printf "CUSTOM_VERSION=1\n"
printf "CI_UPDATE_DEPENDENCY=1\n"
}

"$@"
13 changes: 12 additions & 1 deletion .gitlab/stages/41-saas-deployment-prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ variables:
DEPLOYMENT_BRANCH_BASE_REF:
value: 'trunk'
description: 'The base branch from which the deployment branch should be split off of. This also determines, which branch is checked for successful scheduled pipeline runs.'
CI_PREPARE_SAAS_DEPLOYMENT_B64_ENCODE:
value: 'true'
description: 'Whether to base64 encode the deployment environment variables for the downstream SaaS template pipeline.'

.rules_deployment_preparation: &rules_deployment_preparation
- if: '$CI_PREPARE_SAAS_DEPLOYMENT == "true"'
Expand Down Expand Up @@ -40,8 +43,14 @@ compile deployment info:
CI_CURRENT_MAJOR_ALIAS: '6.6.x-dev'
GITLAB_HOST: 'gitlab.shopware.com'
GITLAB_TOKEN: '${CI_GITLAB_API_TOKEN}'
CI_B64_ENVIRONMENT_TARGET_VAR: 'CI_B64_ENVIRONMENT'
script:
- .gitlab/bin/compile_deployment_info.sh deployment_env "${CI_PREPARE_SAAS_DEPLOYMENT_EXTENSION_UPDATES}" | tee deployment.env
- >
if [ -n "${CI_PREPARE_SAAS_DEPLOYMENT_B64_ENCODE}" ]; then
.gitlab/bin/compile_deployment_info.sh deployment_env_b64 "${CI_B64_ENVIRONMENT_TARGET_VAR}" "${CI_PREPARE_SAAS_DEPLOYMENT_EXTENSION_UPDATES}" | tee deployment.env
else
.gitlab/bin/compile_deployment_info.sh deployment_env "${CI_PREPARE_SAAS_DEPLOYMENT_EXTENSION_UPDATES}" | tee deployment.env
fi
artifacts:
paths:
- deployment.env
Expand All @@ -65,6 +74,7 @@ create deployment merge request:
GITLAB_MR_DESCRIPTION_TEXT: '${GITLAB_MR_DESCRIPTION_TEXT}'
GITLAB_MR_LABELS: '${GITLAB_MR_LABELS}'
GITLAB_MR_ASSIGNEES: '${GITLAB_MR_ASSIGNEES}'
CI_B64_ENVIRONMENT: '${CI_B64_ENVIRONMENT}'
inherit:
default: false
variables:
Expand All @@ -75,6 +85,7 @@ create deployment merge request:
- GITLAB_MR_DESCRIPTION_TEXT
- GITLAB_MR_LABELS
- GITLAB_MR_ASSIGNEES
- CI_B64_ENVIRONMENT
allow_failure: false
trigger:
project: 'shopware/6/product/saas'
Expand Down

0 comments on commit 9104fce

Please sign in to comment.