Skip to content

Commit 90edc63

Browse files
committed
[sdlf-cicd] generic: loop over list of prefixes instead of duplicating code
1 parent d6551de commit 90edc63

File tree

2 files changed

+21
-53
lines changed

2 files changed

+21
-53
lines changed

sdlf-cicd/deploy-generic.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ aws cloudformation deploy \
152152
--parameter-overrides \
153153
pCodebuildBootstrap="$DEPLOY_CODEBUILD_BOOTSTRAP" \
154154
pCodeBuildSuffix="$1" \
155+
pTemplatePrefixes="foundations dataset pipeline team" \
155156
--tags Framework=sdlf \
156157
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
157158
${REGION:+--region "$REGION"} \

sdlf-cicd/template-cicd-generic-git.yaml

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Parameters:
1414
Description: Suffix appended to the CodeBuild project name
1515
Type: String
1616
AllowedPattern: '[A-Za-z0-9\-_]{1,139}'
17+
pTemplatePrefixes:
18+
Description: Prefixes of CloudFormation template files (in YAML)
19+
Type: String
1720

1821
Conditions:
1922
UseCustomBucketPrefix: !Not [!Equals [!Ref pCustomBucketPrefix, sdlf]]
@@ -309,6 +312,9 @@ Resources:
309312
- Name: ARTIFACTS_BUCKET
310313
Type: PLAINTEXT
311314
Value: !Ref rArtifactsBucket
315+
- Name: TEMPLATE_PREFIXES
316+
Type: PLAINTEXT
317+
Value: !Ref pTemplatePrefixes
312318
ServiceRole: !GetAtt rDatalakeCodeBuildServiceRole.Arn
313319
Source:
314320
Type: NO_SOURCE
@@ -332,62 +338,23 @@ Resources:
332338
- |-
333339
CLOUDFORMATION_ENDPOINT_URL="https://cloudformation.$AWS_REGION.amazonaws.com"
334340
USER_ROLE_NAME=$(aws sts get-caller-identity --query 'Arn' --output text | sed 's/:sts:/:iam:/g' | sed 's/:assumed-role/:role/g' | rev | cut -d'/' -f 2- | rev | cut -d'/' -f 2-)
335-
for foundations_template in foundations-*.yaml
336-
do
337-
foundations_template_basename=$(basename "$foundations_template" .yaml)
338-
sed -i "s|pCicdRole: Admin|pCicdRole: $USER_ROLE_NAME|g" "$foundations_template"
339-
cat "$foundations_template"
340-
aws cloudformation --endpoint-url "$CLOUDFORMATION_ENDPOINT_URL" package --template "$foundations_template" --s3-bucket "$ARTIFACTS_BUCKET" --s3-prefix codebuild --output-template-file "packaged-$foundations_template_basename.yaml"
341-
342-
STACK_NAME="sdlf-$foundations_template_basename"
343-
aws cloudformation deploy \
344-
--stack-name "$STACK_NAME" \
345-
--template-file "packaged-$foundations_template_basename.yaml" \
346-
--tags Framework=sdlf \
347-
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
348-
--region "$AWS_REGION" || exit 1
349-
done
350-
351-
for dataset_template in dataset-*.yaml
352-
do
353-
dataset_template_basename=$(basename "$dataset_template" .yaml)
354-
aws cloudformation --endpoint-url "$CLOUDFORMATION_ENDPOINT_URL" package --template "$dataset_template" --s3-bucket "$ARTIFACTS_BUCKET" --s3-prefix codebuild --output-template-file "packaged-$dataset_template_basename.yaml"
355-
356-
STACK_NAME="sdlf-$dataset_template_basename"
357-
aws cloudformation deploy \
358-
--stack-name "$STACK_NAME" \
359-
--template-file "packaged-$dataset_template_basename.yaml" \
360-
--tags Framework=sdlf \
361-
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
362-
--region "$AWS_REGION" || exit 1
363-
done
364-
365-
for pipeline_template in pipeline-*.yaml
366-
do
367-
pipeline_template_basename=$(basename "$pipeline_template" .yaml)
368-
aws cloudformation --endpoint-url "$CLOUDFORMATION_ENDPOINT_URL" package --template "$pipeline_template" --s3-bucket "$ARTIFACTS_BUCKET" --s3-prefix codebuild --output-template-file "packaged-$pipeline_template_basename.yaml"
369-
370-
STACK_NAME="sdlf-$pipeline_template_basename"
371-
aws cloudformation deploy \
372-
--stack-name "$STACK_NAME" \
373-
--template-file "packaged-$pipeline_template_basename.yaml" \
374-
--tags Framework=sdlf \
375-
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
376-
--region "$AWS_REGION" || exit 1
377-
done
378341
379-
for team_template in team-*.yaml
342+
for template_prefix in $TEMPLATE_PREFIXES
380343
do
381-
team_template_basename=$(basename "$team_template" .yaml)
382-
aws cloudformation --endpoint-url "$CLOUDFORMATION_ENDPOINT_URL" package --template "$team_template" --s3-bucket "$ARTIFACTS_BUCKET" --s3-prefix codebuild --output-template-file "packaged-$team_template_basename.yaml"
344+
for template in "$template_prefix"-*.yaml
345+
do
346+
sed -i "s|pCicdRole: Admin|pCicdRole: $USER_ROLE_NAME|g" "$template"
347+
template_basename=$(basename "$template" .yaml)
348+
aws cloudformation --endpoint-url "$CLOUDFORMATION_ENDPOINT_URL" package --template "$template" --s3-bucket "$ARTIFACTS_BUCKET" --s3-prefix codebuild --output-template-file "packaged-$template_basename.yaml"
383349
384-
STACK_NAME="sdlf-$team_template_basename"
385-
aws cloudformation deploy \
386-
--stack-name "$STACK_NAME" \
387-
--template-file "packaged-$team_template_basename.yaml" \
388-
--tags Framework=sdlf \
389-
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
390-
--region "$AWS_REGION" || exit 1
350+
STACK_NAME="sdlf-$template_basename"
351+
aws cloudformation deploy \
352+
--stack-name "$STACK_NAME" \
353+
--template-file "packaged-$template_basename.yaml" \
354+
--tags Framework=sdlf \
355+
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
356+
--region "$AWS_REGION" || exit 1
357+
done
391358
done
392359
artifacts:
393360
files:

0 commit comments

Comments
 (0)