|
20 | 20 | # Check to see if input has been provided: |
21 | 21 | if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then |
22 | 22 | echo "Please provide the base source bucket name, template-bucket, trademark approved solution name, and version" |
23 | | - echo "For example: ./build-s3-dist.sh solutions template-bucket trademarked-solution-name v1.0.0" |
| 23 | + echo "For example: ./build-s3-dist.sh solutions template-bucket trademarked-solution-name v1.0.0" |
24 | 24 | exit 1 |
25 | 25 | fi |
26 | 26 |
|
27 | | -# Get reference for all important folders |
| 27 | +# declare variables |
28 | 28 | template_dir="$PWD" |
29 | 29 | template_dist_dir="$template_dir/deployment/global-s3-assets" |
30 | 30 | build_dist_dir="$template_dir/deployment/regional-s3-assets" |
| 31 | +CODE_BUCKET_NAME=$1 |
| 32 | +TEMPLATE_BUCKET_NAME=$2 |
| 33 | +SOLUTION_NAME=$3 |
| 34 | +VERSION_NUMBER=$4 |
31 | 35 |
|
32 | 36 | echo "------------------------------------------------------------------------------" |
33 | 37 | echo "[Init] Clean old dist and recreate directories" |
34 | 38 | echo "------------------------------------------------------------------------------" |
35 | 39 | echo "rm -rf $template_dist_dir" |
36 | | - rm -rf $template_dist_dir |
| 40 | + rm -rf "$template_dist_dir" |
37 | 41 | echo "mkdir -p $template_dist_dir" |
38 | | - mkdir -p $template_dist_dir |
| 42 | + mkdir -p "$template_dist_dir" |
39 | 43 | echo "rm -rf $build_dist_dir" |
40 | | - rm -rf $build_dist_dir |
| 44 | + rm -rf "$build_dist_dir" |
41 | 45 | echo "mkdir -p $build_dist_dir" |
42 | | - mkdir -p $build_dist_dir |
| 46 | + mkdir -p "$build_dist_dir" |
43 | 47 |
|
44 | 48 | # Create zip file for AWS Lambda functions |
45 | 49 | echo -e "\n Creating all lambda functions for Custom Control Tower Solution" |
46 | 50 | python source/bin/build_scripts/lambda_build.py state_machine_lambda deployment_lambda build_scripts lifecycle_event_handler state_machine_trigger |
47 | 51 | #python source/bin/build_scripts/lambda_build.py state_machine_lambda deployment_lambda build_scripts lifecycle_event_handler |
48 | 52 |
|
49 | 53 | echo -e "\n Cleaning up the tests folder from the lambda zip files" |
50 | | -zip -d $build_dist_dir/custom-control-tower-config-deployer.zip tests/* |
51 | | -zip -d $build_dist_dir/custom-control-tower-state-machine.zip tests/* |
52 | | -zip -d $build_dist_dir/custom-control-tower-scripts.zip tests/* |
53 | | -zip -d $build_dist_dir/custom-control-tower-lifecycle-event-handler.zip tests/* |
54 | | -zip -d $build_dist_dir/custom-control-tower-state-machine-trigger.zip tests/* |
| 54 | +zip -d "$build_dist_dir"/custom-control-tower-config-deployer.zip tests/* |
| 55 | +zip -d "$build_dist_dir"/custom-control-tower-state-machine.zip tests/* |
| 56 | +zip -d "$build_dist_dir"/custom-control-tower-scripts.zip tests/* |
| 57 | +zip -d "$build_dist_dir"/custom-control-tower-lifecycle-event-handler.zip tests/* |
| 58 | +zip -d "$build_dist_dir"/custom-control-tower-state-machine-trigger.zip tests/* |
55 | 59 |
|
56 | 60 | # Move custom-control-tower-initiation.template to global-s3-assets |
57 | 61 | echo "cp -f deployment/custom-control-tower-initiation.template $template_dist_dir" |
58 | | -cp -f deployment/custom-control-tower-initiation.template $template_dist_dir |
| 62 | +cp -f deployment/custom-control-tower-initiation.template "$template_dist_dir" |
59 | 63 |
|
60 | 64 | #COPY deployment/add-on to $build_dist_dir/add-on |
61 | | -mkdir $template_dist_dir/add-on/ |
62 | | -cp -f -R deployment/add-on/. $template_dist_dir/add-on |
| 65 | +mkdir "$template_dist_dir"/add-on/ |
| 66 | +cp -f -R deployment/add-on/. "$template_dist_dir"/add-on |
63 | 67 |
|
64 | 68 | #COPY custom_control_tower_configuration to global-s3-assets |
65 | 69 | #Please check to see if this is the correct location or template_dist_dir |
66 | | -cp -f -R deployment/custom_control_tower_configuration $build_dist_dir/custom_control_tower_configuration/ |
| 70 | +cp -f -R deployment/custom_control_tower_configuration "$build_dist_dir"/custom_control_tower_configuration/ |
67 | 71 |
|
68 | | -echo -e "\n Updating code source bucket in the template with $1" |
69 | | -replace="s/%DIST_BUCKET_NAME%/$1/g" |
| 72 | +echo -e "\n Updating code source bucket in the template with $CODE_BUCKET_NAME" |
| 73 | +replace="s/%DIST_BUCKET_NAME%/$CODE_BUCKET_NAME/g" |
70 | 74 | echo "sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template" |
71 | | -sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template |
| 75 | +sed -i -e "$replace" "$template_dist_dir"/custom-control-tower-initiation.template |
72 | 76 |
|
73 | | -cd $template_dist_dir/add-on |
74 | | -for y in `find . -name "*.template"`; |
75 | | - do |
76 | | - echo "sed -i -e $replace $y" |
77 | | - sed -i -e $replace $y |
78 | | - done |
79 | | -cd ../../.. |
80 | | - |
81 | | -echo -e "\n Updating template bucket in the template with $2" |
82 | | -replace="s/%TEMPLATE_BUCKET_NAME%/$2/g" |
| 77 | +echo -e "\n Updating template bucket in the template with $TEMPLATE_BUCKET_NAME" |
| 78 | +replace="s/%TEMPLATE_BUCKET_NAME%/$TEMPLATE_BUCKET_NAME/g" |
83 | 79 | echo "sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template" |
84 | | -sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template |
85 | | -echo "sed -i -e $replace $build_dist_dir/$rss_file_name" |
86 | | -sed -i -e $replace $build_dist_dir/$rss_file_name |
87 | | - |
88 | | -cd $template_dist_dir/add-on |
89 | | -for y in `find . -name "*.template"`; |
90 | | - do |
91 | | - echo "sed -i -e $replace $y" |
92 | | - sed -i -e $replace $y |
93 | | - done |
94 | | -cd ../../.. |
| 80 | +sed -i -e "$replace" "$template_dist_dir"/custom-control-tower-initiation.template |
95 | 81 |
|
96 | 82 | # Replace solution name with real value |
97 | | -echo -e "\n >> Updating solution name in the template with $3" |
98 | | -replace="s/%SOLUTION_NAME%/$3/g" |
| 83 | +echo -e "\n Updating solution name in the template with $SOLUTION_NAME" |
| 84 | +replace="s/%SOLUTION_NAME%/$SOLUTION_NAME/g" |
99 | 85 | echo "sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template" |
100 | | -sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template |
| 86 | +sed -i -e "$replace" "$template_dist_dir"/custom-control-tower-initiation.template |
101 | 87 |
|
102 | | -cd $template_dist_dir/add-on |
103 | | -for y in `find . -name "*.template"`; |
104 | | - do |
105 | | - echo "sed -i -e $replace $y" |
106 | | - sed -i -e $replace $y |
107 | | - done |
108 | | -cd ../../.. |
109 | | - |
110 | | -echo -e "\n Updating version number in the template with $4" |
111 | | -replace="s/%VERSION%/$4/g" |
| 88 | +echo -e "\n Updating version number in the template with $VERSION_NUMBER" |
| 89 | +replace="s/%VERSION%/$VERSION_NUMBER/g" |
112 | 90 | echo "sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template" |
113 | | -sed -i -e $replace $template_dist_dir/custom-control-tower-initiation.template |
114 | | - |
115 | | -echo "sed -i -e $replace $template_dist_dir/$rss_file_name" |
116 | | -sed -i -e $replace $template_dist_dir/$rss_file_name |
117 | | - |
118 | | -cd $template_dist_dir/add-on |
119 | | -for y in `find . -name "*.template"`; |
120 | | - do |
121 | | - echo "sed -i -e $replace $y" |
122 | | - sed -i -e $replace $y |
123 | | - done |
124 | | -cd ../../.. |
| 91 | +sed -i -e "$replace" "$template_dist_dir"/custom-control-tower-initiation.template |
125 | 92 |
|
126 | 93 | # Create configuration zip file |
127 | 94 | echo -e "\n Creating zip file with Custom Control Tower configuration" |
128 | | -cd $build_dist_dir/custom_control_tower_configuration/; zip -Xr $build_dist_dir/custom-control-tower-configuration.zip ./* ; cd - |
129 | | - |
| 95 | +cd "$build_dist_dir"/custom_control_tower_configuration/ |
| 96 | +zip -Xr "$build_dist_dir"/custom-control-tower-configuration.zip ./* |
| 97 | + |
| 98 | +# build regional config zip file |
| 99 | +echo -e "\n*** Build regional config zip file" |
| 100 | +declare -a region_list=( "ap-northeast-2" "ap-southeast-2" "ca-central-1" "eu-west-1" "eu-west-2" "me-south-1" "us-east-1" "us-west-1" "ap-east-1" "ap-south-1" "eu-central-1" "eu-north-1" "eu-west-3" "sa-east-1" "us-east-2" "us-west-2" "ap-northeast-1" "ap-southeast-1" ) |
| 101 | +for region in "${region_list[@]}" |
| 102 | +do |
| 103 | + echo -e "\n Building config zip for $region region" |
| 104 | + echo -e " Updating region name in the manifest to: $region \n" |
| 105 | + replace="s/{{ region }}/$region/g" |
| 106 | + cp ./manifest.yaml.j2 ./manifest.yaml |
| 107 | + echo "sed -i -e $replace ./manifest.yaml" |
| 108 | + sed -i -e "$replace" ./manifest.yaml |
| 109 | + echo -e "\n Zipping configuration..." |
| 110 | + zip -Xr "$build_dist_dir"/custom-control-tower-configuration-"$region".zip ./manifest.yaml ./example-configuration/* |
| 111 | +done |
| 112 | +cd - |
130 | 113 | #Copy Lambda Zip Files to the Global S3 Assets |
131 | 114 | echo -e "\n Copying lambda zip files to Global S3 Assets" |
132 | | -cp $build_dist_dir/*.zip $template_dist_dir/ |
133 | | - |
| 115 | +cp "$build_dist_dir"/*.zip "$template_dist_dir"/ |
0 commit comments