Skip to content

Commit 11873b2

Browse files
chore: [SVLS-6279] make publish_layer(s).sh a bit more reusable
1 parent 4950f90 commit 11873b2

File tree

3 files changed

+49
-34
lines changed

3 files changed

+49
-34
lines changed

.gitlab/datasources/environments.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ environments:
33
external_id: sandbox-publish-externalid
44
role_to_assume: sandbox-layer-deployer
55
account: 425362996713
6+
add_permissions: 0
7+
automatically_bump_version: 1
68
- name: prod
79
external_id: prod-publish-externalid
810
role_to_assume: dd-serverless-layer-deployer-role
911
account: 464622532012
12+
add_permissions: 1
13+
automatically_bump_version: 0
Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@
77

88
set -e
99

10+
11+
if [ -z "$ADD_PERMISSIONS" ]; then
12+
printf "[ERROR]: ADD_PERMISSIONS not specified."
13+
exit 1
14+
fi
15+
16+
if [ -z "$AUTOMATICALLY_BUMP_VERSION" ]; then
17+
printf "[ERROR]: AUTOMATICALLY_BUMP_VERSION not specified."
18+
exit 1
19+
fi
20+
21+
if [ -z "$ARCHITECTURE" ]; then
22+
printf "[ERROR]: ARCHITECTURE not specified."
23+
exit 1
24+
fi
25+
26+
if [ -z "$LAYER_NAME_BASE_SUFFIX" ]; then
27+
printf "[ERROR]: LAYER_NAME_BASE_SUFFIX not specified."
28+
exit 1
29+
fi
30+
31+
if [ -z "$LAYER_FILE" ]; then
32+
printf "[ERROR]: LAYER_FILE not specified."
33+
exit 1
34+
fi
35+
36+
1037
LAYER_DIR=".layers"
1138
VALID_ACCOUNTS=("sandbox" "prod")
1239

@@ -25,7 +52,7 @@ publish_layer() {
2552
)
2653

2754
# Add permissions only for prod
28-
if [ "$STAGE" == "prod" ]; then
55+
if [ "$ADD_PERMISSIONS" = "1" ]; then
2956
permission=$(aws lambda add-layer-version-permission --layer-name $layer \
3057
--version-number $version_nbr \
3158
--statement-id "release-$version_nbr" \
@@ -39,22 +66,6 @@ publish_layer() {
3966
}
4067

4168

42-
if [ -z "$ARCHITECTURE" ]; then
43-
printf "[ERROR]: ARCHITECTURE not specified."
44-
exit 1
45-
fi
46-
47-
48-
if [ -z "$LAYER_NAME_BASE_SUFFIX" ]; then
49-
printf "[ERROR]: LAYER_NAME_BASE_SUFFIX not specified."
50-
exit 1
51-
fi
52-
53-
54-
if [ -z "$LAYER_FILE" ]; then
55-
printf "[ERROR]: LAYER_FILE not specified."
56-
exit 1
57-
fi
5869

5970
LAYER_PATH="${LAYER_DIR}/${LAYER_FILE}"
6071
# Check that the layer files exist
@@ -85,28 +96,26 @@ else
8596
fi
8697
fi
8798

88-
if [ -z "$STAGE" ]; then
89-
printf "[ERROR]: STAGE not specified.\n"
90-
exit 1
91-
fi
92-
9399
printf "[$REGION] Starting publishing layers...\n"
94100

95-
if [[ "$STAGE" =~ ^(staging|sandbox)$ ]]; then
96-
# Deploy latest version
101+
if [ "$AUTOMATICALLY_BUMP_VERSION" = "1" ]; then
97102
latest_version=$(aws lambda list-layer-versions --region $REGION --layer-name $LAYER_NAME --query 'LayerVersions[0].Version || `0`')
98103
VERSION=$(($latest_version + 1))
104+
99105
else
100-
# Running on prod
101106
if [ -z "$CI_COMMIT_TAG" ]; then
102-
printf "[ERROR]: No CI_COMMIT_TAG found.\n"
103-
printf "Exiting script...\n"
104-
exit 1
107+
if (( VERSION )); then
108+
printf "VERSION is numeric so we should be okay to continue\n"
109+
else
110+
printf "[ERROR]: No CI_COMMIT_TAG found and VERSION is not nuymeric.\n"
111+
printf "Exiting script...\n"
112+
exit 1
113+
fi
105114
else
106115
printf "Tag found in environment: $CI_COMMIT_TAG\n"
107-
fi
108116

109-
VERSION="${CI_COMMIT_TAG//[!0-9]/}"
117+
VERSION="${CI_COMMIT_TAG//[!0-9]/}"
118+
fi
110119
printf "Version: ${VERSION}\n"
111120
fi
112121

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ publish layer {{ $environment.name }} ({{ $flavor.name }}):
187187
LAYER_NAME_BASE_SUFFIX: {{ $flavor.layer_name_base_suffix }}
188188
ARCHITECTURE: {{ $flavor.arch }}
189189
LAYER_FILE: datadog_extension-{{ $flavor.suffix }}.zip
190-
STAGE: {{ $environment.name }}
190+
ADD_PERMISSIONS: {{ $environment.add_permissions }}
191+
AUTOMATICALLY_BUMP_VERSION: {{ $environment.automatically_bump_version }}
191192
before_script:
192193
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
193194
script:
194-
- .gitlab/scripts/publish_layers.sh
195+
- .gitlab/scripts/publish_layer.sh
195196

196197
{{ if eq $environment.name "sandbox" }}
197198

@@ -214,11 +215,12 @@ publish layer sandbox [us-east-1] ({{ $flavor.name }}):
214215
REGION: us-east-1
215216
ARCHITECTURE: {{ $flavor.arch }}
216217
LAYER_FILE: datadog_extension-{{ $flavor.suffix }}.zip
217-
STAGE: {{ $environment.name }}
218+
ADD_PERMISSIONS: {{ $environment.add_permissions }}
219+
AUTOMATICALLY_BUMP_VERSION: {{ $environment.automatically_bump_version }}
218220
before_script:
219221
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
220222
script:
221-
- .gitlab/scripts/publish_layers.sh
223+
- .gitlab/scripts/publish_layer.sh
222224

223225
{{ end }} # if environment sandbox
224226

0 commit comments

Comments
 (0)