|
| 1 | +#!/bin/bash |
| 2 | +#----------------------------------------------------------------------------------------------------------------------- |
| 3 | +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance |
| 6 | +# with the License. A copy of the License is located at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES |
| 11 | +# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions |
| 12 | +# and limitations under the License. |
| 13 | +#----------------------------------------------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +# |
| 16 | +# This assumes all of the OS-level configuration has been completed and git repo has already been cloned |
| 17 | +# |
| 18 | +# This script should be run from the repo's deployment directory |
| 19 | +# cd deployment |
| 20 | +# ./build-s3-dist.sh source-bucket-base-name solution-name version-code |
| 21 | +# |
| 22 | +# Parameters: |
| 23 | +# - source-bucket-base-name: Name for the S3 bucket location where the template will source the Lambda |
| 24 | +# code from. The template will append '-[region_name]' to this bucket name. |
| 25 | +# For example: ./build-s3-dist.sh solutions my-solution v1.0.0 |
| 26 | +# The template will then expect the source code to be located in the solutions-[region_name] bucket |
| 27 | +# |
| 28 | +# - solution-name: name of the solution for consistency |
| 29 | +# |
| 30 | +# - version-code: version of the package |
| 31 | + |
| 32 | +# Check to see if input has been provided: |
| 33 | +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] ; then |
| 34 | + echo "Please provide the base source bucket name, trademark approved solution name and version where the lambda code will eventually reside." |
| 35 | + echo "For example: ./build-s3-dist.sh solutions trademarked-solution-name v1.0.0" |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +# Get reference for all important folders |
| 40 | +template_dir="$PWD" |
| 41 | +template_dist_dir="$template_dir/global-s3-assets" |
| 42 | +build_dist_dir="$template_dir/regional-s3-assets" |
| 43 | +source_dir="$template_dir/../source" |
| 44 | + |
| 45 | +echo "------------------------------------------------------------------------------" |
| 46 | +echo "[Init] Clean old dist, node_modules and bower_components folders" |
| 47 | +echo "------------------------------------------------------------------------------" |
| 48 | +echo "rm -rf $template_dist_dir" |
| 49 | +rm -rf $template_dist_dir |
| 50 | +echo "mkdir -p $template_dist_dir" |
| 51 | +mkdir -p $template_dist_dir |
| 52 | +echo "rm -rf $build_dist_dir" |
| 53 | +rm -rf $build_dist_dir |
| 54 | +echo "mkdir -p $build_dist_dir" |
| 55 | +mkdir -p $build_dist_dir |
| 56 | + |
| 57 | + |
| 58 | +echo "------------------------------------------------------------------------------" |
| 59 | +echo "[Packing] Templates" |
| 60 | +echo "------------------------------------------------------------------------------" |
| 61 | + |
| 62 | +# copy all the cfn templates in the source/infrastructure dir |
| 63 | +cp $source_dir/infrastructure/cfn-sample-tenant-component.yaml $template_dist_dir/ |
| 64 | +# copy all the cfn templates in source/infrastructure/lambdaLayers/openssl/infrastructure |
| 65 | +cp $source_dir/infrastructure/lambdaLayers/openssl/infrastructure/cfn-*.yml $template_dist_dir/ |
| 66 | +# copy all the cfn templates ending in yml in source/package/*/infrastructure |
| 67 | +cp $source_dir/packages/services/*/infrastructure/cfn-command-and-control.yml $template_dist_dir/ |
| 68 | +# copy all cfn template snippets |
| 69 | +cp -a $source_dir/infrastructure/cloudformation/snippets/ $template_dist_dir/snippets/ |
| 70 | +# copy all cfn templates in libraries/core |
| 71 | +cp $source_dir/packages/libraries/core/*/infrastructure/cfn-deployment-helper.yaml $template_dist_dir/ |
| 72 | + |
| 73 | +cd "$template_dist_dir" |
| 74 | +# Rename all *.yaml to *.template |
| 75 | +for f in *.yaml; do |
| 76 | + mv -- "$f" "${f%.yaml}.template" |
| 77 | +done |
| 78 | + |
| 79 | +# Rename all *.yml to *.template |
| 80 | +for f in *.yml; do |
| 81 | + mv -- "$f" "${f%.yml}.template" |
| 82 | +done |
| 83 | + |
| 84 | +# remove non-release templates |
| 85 | +rm "$template_dist_dir"/cfn-auth-jwt.template |
| 86 | +rm "$template_dist_dir"/cfn-auth-devicecert.template |
| 87 | +rm "$template_dist_dir"/cfn-cdf-core* |
| 88 | +rm "$template_dist_dir"/cfn-bastion-host.template |
| 89 | + |
| 90 | +# override the S3 Code Uri and TemplateURL for the cfn templates to point to a S3 location |
| 91 | +for f in *.template; do |
| 92 | + if [ -f "../transforms/${f%.*}.yaml" ]; then |
| 93 | + # Below only works in yq version 3.4.1 |
| 94 | + yq w -i -s "../transforms/${f%.*}.yaml" "$f" |
| 95 | + fi |
| 96 | +done |
| 97 | + |
| 98 | +cd .. |
| 99 | +echo "Updating code source bucket in template with $1" |
| 100 | +replace="s/%%BUCKET_NAME%%/$1/g" |
| 101 | +echo "sed -i '' -e $replace $template_dist_dir/*.template" |
| 102 | +sed -i '' -e $replace $template_dist_dir/*.template |
| 103 | +replace="s/%%SOLUTION_NAME%%/$2/g" |
| 104 | +echo "sed -i '' -e $replace $template_dist_dir/*.template" |
| 105 | +sed -i '' -e $replace $template_dist_dir/*.template |
| 106 | +replace="s/%%VERSION%%/$3/g" |
| 107 | +echo "sed -i '' -e $replace $template_dist_dir/*.template" |
| 108 | +sed -i '' -e $replace $template_dist_dir/*.template |
| 109 | + |
| 110 | +replace="s/%%TEMPLATE_BUCKET_NAME%%/$4/g" |
| 111 | +sed -i '' -e $replace $template_dist_dir/*.template |
| 112 | + |
| 113 | + |
| 114 | +echo "------------------------------------------------------------------------------" |
| 115 | +echo "[Rebuild] Package Dists" |
| 116 | +echo "------------------------------------------------------------------------------" |
| 117 | + |
| 118 | +# Copy and rename dists |
| 119 | +cd $build_dist_dir |
| 120 | +cp $source_dir/packages/libraries/core/deployment-helper/bundle.zip $build_dist_dir/cdf-deployment-helper.zip |
| 121 | +cp $source_dir/infrastructure/lambdaLayers/openssl/build/build.zip $build_dist_dir/cdf-openssl-layer.zip |
| 122 | +cp $source_dir/packages/services/provisioning/bundle.zip $build_dist_dir/cdf-provisioning.zip |
| 123 | +cp $source_dir/packages/services/command-and-control/bundle.zip $build_dist_dir/cdf-command-and-control.zip |
| 124 | + |
0 commit comments