-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
61 lines (49 loc) · 2.13 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -euxo pipefail
NOW=$(date +"%x %r %Z")
echo "Time: $NOW"
if [ $# -lt 4 ]; then
echo "Please provide the solution name as well as the base S3 bucket name and the region to run build script."
echo "For example: chmod a+x build.sh && ./build.sh S3_BUCKET_NAME STACK_NAME REGION STUDIO_ROLE_NAME"
echo "STUDIO_ROLE_NAME is just the name not ARN from studio console example: AmazonSageMaker-ExecutionRole-20210112T085906"
exit 1
fi
PREFIX="smsd" # should match the ProjectPrefix parameter in pipeline.yml and studio.yml additional ARN privileges
BUCKET="$1"
STACK_NAME="$2"
REGION=$3
ROLE=$4
aws cloudformation delete-stack --stack-name "$STACK_NAME"
rm -rf build
mkdir build
rsync -av --progress . build \
--exclude build \
--exclude "*.git*" \
--exclude "*mlruns*" \
--exclude "*ml_model*" \
--exclude "*problem*" \
--exclude "*tmp*" \
--exclude "*data*" \
--exclude "*nbs*" \
--exclude .pre-commit-config.yaml
cd build
# binding resources of pipeline.yml and studio.yml together with common PREFIX
sed -i -e "s/PROJECT_PREFIX/$PREFIX/g" assets/*.yml pipeline.yml
sed -i -e "s/S3_BUCKET_NAME/$BUCKET/g" pipeline.yml
find . -type f -iname "*.yml-e" -delete
bash scripts/lint.sh || exit 1
# aws cloudformation validate-template --template-body file://studio.yml
# aws cloudformation validate-template --template-body file://pipeline.yml
# rm -rf scripts # used in development only
zip -r project.zip .
aws s3 mb "s3://$BUCKET" --region "$REGION"
aws s3 cp --region "$REGION" project.zip "s3://$BUCKET/" --acl public-read
aws s3 cp --region "$REGION" pipeline.yml "s3://$BUCKET/" --acl public-read
aws s3 cp --region "$REGION" studio.yml "s3://$BUCKET/" --acl public-read
aws cloudformation wait stack-delete-complete --stack-name "$STACK_NAME"
aws cloudformation create-stack --stack-name "$STACK_NAME" \
--template-url "https://$BUCKET.s3.$REGION.amazonaws.com/studio.yml" \
--capabilities CAPABILITY_IAM \
--parameters ParameterKey=ProjectPrefix,ParameterValue="$PREFIX" \
ParameterKey=SageMakerStudioRoleName,ParameterValue="$ROLE" \
ParameterKey=PipelineBucket,ParameterValue="$BUCKET"