-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·55 lines (48 loc) · 2.47 KB
/
deploy.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
#!/bin/bash
# Set present working directory
PWD="file://$(pwd)"
# Set cli variables
CREDENTIALS_FILE_PATH="credentials"
echo "AWS_DEFAULT_REGION=us-east-1" > $CREDENTIALS_FILE_PATH
# Bucket params and template
PARAMS_BUCKET_FILE_PATH="$PWD/IaC/params-artifacts-bucket.json"
TEMPLATE_BUCKET_FILE_PATH="$PWD/IaC/template-artifacts-bucket.yaml"
# Main params and template
PARAMS_MAIN_FILE_PATH="$PWD/IaC/params.json"
TEMPLATE_MAIN_FILE_PATH="$PWD/IaC/template.yaml"
# Stack Name variable
STACK_BUCKET_NAME="nu0087002eis-aid-dev-bucket-test-stack"
STACK_MAIN_NAME="nu0087002eis-aid-dev-main-test-stack"
# Update switch
UPDATE_SWITCH=${1:-"no"}
UPDATE_ARTIFACT=${2:-"si"}
# Now export all credentials aws variables to shell session
echo "Exporting aws credentials to shell session"
echo "credentials_file_path = $CREDENTIALS_FILE_PATH"
sleep 2
export $(grep -v '^#' $CREDENTIALS_FILE_PATH | xargs -0)
# Executing bucket stack first and wait until finish
if [[ $UPDATE_SWITCH == "no" ]]; then
echo "creating mode stack"
aws cloudformation create-stack --stack-name $STACK_BUCKET_NAME --template-body $TEMPLATE_BUCKET_FILE_PATH --parameters $PARAMS_BUCKET_FILE_PATH --capabilities CAPABILITY_IAM --on-failure DELETE
# wait until finish
aws cloudformation wait stack-create-complete --stack-name $STACK_BUCKET_NAME
if [[ $UPDATE_ARTIFACT == "si" ]]; then
# upload artifact to bucket
aws s3 cp --recursive ./carta_laboral s3://nu0087002eis-aid-mlops-artifacts-bucket
bash ./build_deploy_lambda.sh
fi
# create main stack
aws cloudformation create-stack --stack-name $STACK_MAIN_NAME --template-body $TEMPLATE_MAIN_FILE_PATH --parameters $PARAMS_MAIN_FILE_PATH --capabilities CAPABILITY_NAMED_IAM --on-failure DELETE
elif [[ $UPDATE_SWITCH == "si" ]]; then
echo "updating mode stack"
# aws cloudformation update-stack --stack-name $STACK_BUCKET_NAME --template-body $TEMPLATE_BUCKET_FILE_PATH --parameters $PARAMS_BUCKET_FILE_PATH --capabilities CAPABILITY_IAM
# wait until finish
# aws cloudformation wait stack-update-complete --stack-name $STACK_BUCKET_NAME
if [[ $UPDATE_ARTIFACT == "si" ]]; then
# upload artifact to bucket
# aws s3 cp --recursive ./carta_laboral s3://nu0087002eis-aid-mlops-artifacts-bucket
bash ./build_deploy_lambda.sh
fi
aws cloudformation update-stack --stack-name $STACK_MAIN_NAME --template-body $TEMPLATE_MAIN_FILE_PATH --parameters $PARAMS_MAIN_FILE_PATH --capabilities CAPABILITY_NAMED_IAM
fi