Skip to content

Commit 9d5f143

Browse files
committed
feat: set chart's & its app's version auto-deploy
use 'postgresql' instead of 'postgres' for naming convention Signed-off-by: Siddharth Tiwari <[email protected]>
1 parent fbe3a77 commit 9d5f143

File tree

1 file changed

+45
-27
lines changed

1 file changed

+45
-27
lines changed

auto-deploy

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@ set -e
66

77
export AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE=/tmp/auto-deploy-environment-values.yaml
88
export RELEASE_NAME=${HELM_RELEASE_NAME:-$CI_ENVIRONMENT_SLUG}
9-
export POSTGRESQL_RELEASE_NAME="${RELEASE_NAME}-postgresql"
10-
export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.16"}"
11-
export POSTGRES_CHART_VERSION=${POSTGRES_CHART_VERSION:-"10.2.1"}
9+
10+
export POSTGRESQL_VERSION=${POSTGRESQL_VERSION:-"11.10.0"};
11+
export REDIS_VERSION=${REDIS_VERSION:-"6.0.9"};
12+
export MYSQL_VERSION=${MYSQL_VERSION:-"8.0.22"};
13+
export MONGODB_VERSION=${MONGODB_VERSION:-"4.4.3"};
14+
export MARIADB_VERSION=${MARIADB_VERSION:-"10.5.8"};
15+
16+
export POSTGRESQL_CHART_VERSION=${POSTGRESQL_CHART_VERSION:-"10.2.1"};
17+
export REDIS_CHART_VERSION=${REDIS_CHART_VERSION:-"12.4.0"};
18+
export MYSQL_CHART_VERSION=${MYSQL_CHART_VERSION:-"8.2.4"};
19+
export MONGODB_CHART_VERSION=${MONGODB_CHART_VERSION:-"10.3.6"};
20+
export MARIADB_CHART_VERSION=${MARIADB_CHART_VERSION:-"9.2.2"};
21+
22+
APPS=(mariadb mongodb mysql redis postgresql)
23+
for i in "${APPS[@]}"; do
24+
source <(echo "
25+
export ${i^^}_RELEASE_NAME=${RELEASE_NAME}-${i};
26+
"
27+
)
28+
done
29+
1230
export ROLLOUT_RESOURCE_TYPE=${ROLLOUT_RESOURCE_TYPE:-"deployment"}
1331
export ASSETS_DIR='/assets'
1432
export CHART='lambda'
@@ -35,10 +53,10 @@ function download_chart() {
3553
elif [[ -n "$AUTO_DEVOPS_CHART" ]]; then
3654
# user specified a custom chart to use, but it can be a local directory or a remote chart
3755
if [[ -d "$AUTO_DEVOPS_CHART" ]]; then
38-
echo "Download skipped. Using the chart at local path '$AUTO_DEVOPS_CHART' (moving to 'chart/' first)..."
56+
echo "Download skipped. Using the chart at local path ${AUTO_DEVOPS_CHART@Q} (moving to 'chart/' first)..."
3957
mv "$AUTO_DEVOPS_CHART" chart/
4058
else
41-
echo "Downloading remote chart '$AUTO_DEVOPS_CHART'..."
59+
echo "Downloading remote chart ${AUTO_DEVOPS_CHART@Q}..."
4260
helm pull "$AUTO_DEVOPS_CHART" --untar
4361

4462
local auto_chart_name
@@ -75,7 +93,7 @@ function add_custom_chart_repository() {
7593
return
7694
fi
7795

78-
echo "Adding Helm chart repository '$AUTO_DEVOPS_CHART_REPOSITORY_NAME'"
96+
echo "Adding Helm chart repository ${AUTO_DEVOPS_CHART_REPOSITORY_NAME@Q}"
7997

8098
# repo should always be added when present, because any chart can have external dependencies
8199
local helm_repo_auth=()
@@ -108,9 +126,9 @@ function write_environment_values_file() {
108126

109127
# Helm 3 does not like `--set image.secrets[0]=""`
110128
if [[ "$CI_PROJECT_VISIBILITY" != "public" ]]; then
111-
echo "image: { secrets: [ { name: gitlab-registry-${CI_PROJECT_PATH_SLUG} } ] }" >>"$AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE"
129+
echo "image: { secrets: [ { name: gitlab-registry-${CI_PROJECT_PATH_SLUG} } ] }" >>$AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE
112130
else
113-
echo "image: { secrets: null }" >>"$AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE"
131+
echo "image: { secrets: null }" >>$AUTO_DEPLOY_ENVIRONMENT_VALUES_FILE
114132
fi
115133
}
116134

@@ -136,15 +154,15 @@ function persist_environment_url() {
136154

137155
function auto_database_url() {
138156
local auto_database_url
139-
auto_database_url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRESQL_RELEASE_NAME}:5432/${POSTGRES_DB}"
157+
auto_database_url="postgres://${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_RELEASE_NAME}:5432/${POSTGRESQL_DB}"
140158

141159
echo "${DATABASE_URL-$auto_database_url}"
142160
}
143161

144162
function install_postgresql() {
145163

146-
if [[ "$POSTGRES_VERSION" == "9.6.2" ]]; then
147-
echo "The minimum supported POSTGRES_VERSION is 9.6.16"
164+
if [[ "$POSTGRESQL_VERSION" == "9.6.2" ]]; then
165+
echo "The minimum supported POSTGRESQL_VERSION is 9.6.16"
148166

149167
exit 1
150168
fi
@@ -156,28 +174,28 @@ function install_postgresql() {
156174
debug_flag=('--debug')
157175
fi
158176

159-
local postgres_helm_values_args=()
160-
local postgres_helm_values_file=${POSTGRES_HELM_UPGRADE_VALUES_FILE:-.gitlab/auto-deploy-postgres-values.yaml}
161-
if [[ -f "${postgres_helm_values_file}" ]]; then
162-
echo "Using PostgreSQL helm values file ${postgres_helm_values_file@Q}"
163-
postgres_helm_values_args=(--values "${postgres_helm_values_file}")
177+
local postgresql_helm_values_args=()
178+
local postgresql_helm_values_file=${POSTGRESQL_HELM_UPGRADE_VALUES_FILE:-.gitlab/auto-deploy-postgresql-values.yaml}
179+
if [[ -f "${postgresql_helm_values_file}" ]]; then
180+
echo "Using PostgreSQL helm values file ${postgresql_helm_values_file@Q}"
181+
postgresql_helm_values_args=(--values "${postgresql_helm_values_file}")
164182
else
165-
echo "No PostgreSQL helm values file found at ${postgres_helm_values_file@Q}"
183+
echo "No PostgreSQL helm values file found at ${postgresql_helm_values_file@Q}"
166184
fi
167185

168-
# shellcheck disable=SC2086 # POSTGRES_HELM_UPGRADE_EXTRA_ARGS -- double quote variables to prevent globbing
186+
# shellcheck disable=SC2086 # POSTGRESQL_HELM_UPGRADE_EXTRA_ARGS -- double quote variables to prevent globbing
169187
helm upgrade --install \
170188
--atomic \
171189
"${debug_flag[@]}" \
172190
--wait \
173-
--version "${POSTGRES_CHART_VERSION}" \
191+
--version "${POSTGRESQL_CHART_VERSION}" \
174192
--set fullnameOverride="$name" \
175-
--set postgresqlUsername="$POSTGRES_USER" \
176-
--set postgresqlPassword="$POSTGRES_PASSWORD" \
177-
--set postgresqlDatabase="$POSTGRES_DB" \
178-
--set image.tag="$POSTGRES_VERSION" \
179-
"${postgres_helm_values_args[@]}" \
180-
$POSTGRES_HELM_UPGRADE_EXTRA_ARGS \
193+
--set postgresqlUsername="$POSTGRESQL_USER" \
194+
--set postgresqlPassword="$POSTGRESQL_PASSWORD" \
195+
--set postgresqlDatabase="$POSTGRESQL_DB" \
196+
--set image.tag="$POSTGRESQL_VERSION" \
197+
"${postgresql_helm_values_args[@]}" \
198+
$POSTGRESQL_HELM_UPGRADE_EXTRA_ARGS \
181199
--namespace="$KUBE_NAMESPACE" \
182200
"$name" \
183201
bitnami/postgresql
@@ -195,7 +213,7 @@ function deploy() {
195213
local stable_name
196214
stable_name=$(deploy_name stable)
197215

198-
if [[ "$POSTGRES_ENABLED" == "true" ]]; then
216+
if [[ "$POSTGRESQL_ENABLED" == "true" ]]; then
199217
install_postgresql
200218
fi
201219

@@ -291,7 +309,7 @@ function deploy() {
291309
chart/
292310
fi
293311

294-
echo "Deploying new $track release..."
312+
echo "Deploying new ${track@Q} release..."
295313
# shellcheck disable=SC2086 # HELM_UPGRADE_EXTRA_ARGS -- double quote variables to prevent globbing
296314
helm upgrade --install \
297315
"${atomic_flag[@]}" \

0 commit comments

Comments
 (0)