-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·146 lines (123 loc) · 4.26 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -eo pipefail
if [ $# == 0 ] || [ $# -gt 3 ]
then
echo 'please provide 1-3 arguments. Use -h or --help for usage information.'
exit 0
fi
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help | help )
echo '''
Usage: deploy.sh [-h] [-d] environment deploy/build/loadup/loaddown
Light weight version of cdk.sh in cloud-base
positional arguments:
deploy builds and deploys the stack to target environment, environment must be supplied.
build only builds the Lambda & synthesizes CDK (useful when developing)
loadup create load testing instance, environment must be supplied.
loaddown destroy load testing instance, environment must be supplied.
environment Environment name (e.g. pallero)
optional arguments:
-h, --help Show this help message and exit
-d, --dependencies Clean and install dependencies before deployment (i.e. run npm ci)
'''
exit 0
;;
loadup)
loadup="true"
shift
;;
loaddown)
loaddown="true"
shift
;;
-d | --dependencies)
dependencies="true"
shift
;;
build)
build="true"
shift
;;
deploy)
deploy="true"
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
git_root=$(git rev-parse --show-toplevel)
if [[ "${loadup}" == "true" ]]; then
environment=${POSITIONAL[~-1]}
if [[ "${environment}" =~ ^(sade)$ ]]; then
echo "Let's not deploy load testing instance to production account"
exit
fi
echo "Deploying load testing instance"
cd "${git_root}/cdk/"
aws-vault exec oph-dev -- cdk deploy LoadtestStack --require-approval never -c "environment=$environment"
fi
if [[ "${loaddown}" == "true" ]]; then
environment=${POSITIONAL[~-1]}
echo "Destroying load testing instance"
cd "${git_root}/cdk/"
aws-vault exec oph-dev -- cdk destroy LoadtestStack -f -c "environment=$environment"
fi
if [[ "${build}" == "true" ]]; then
echo "Building Lambda code and synthesizing CDK template"
npx cdk synth
fi
if [[ -n "${dependencies}" ]]; then
echo "Installing CDK dependencies.."
cd "${git_root}/cdk/" && npm ci
echo "Installing app dependencies.."
cd "${git_root}/viestinvalitys-raportointi/" && npm ci
fi
if [[ "${build}" == "true" ]]; then
echo "Building Lambda code and synthesizing CDK template"
npx cdk synth
fi
if [[ "${deploy}" == "true" ]]; then
environment=${POSITIONAL[~-1]}
## Profiles are defined in user's .aws/config
if [[ "${environment}" =~ ^(sade)$ ]]; then
aws_profile="oph-prod"
elif [[ "${environment}" =~ ^(untuva)$ ]]; then
aws_profile="oph-dev"
elif [[ "${environment}" =~ ^(hahtuva)$ ]]; then
aws_profile="oph-dev"
elif [[ "${environment}" =~ ^(pallero)$ ]]; then
aws_profile="oph-dev"
else
echo "Unknown environment: ${environment}"
exit 0
fi
echo "Build project"
mvn install
cd viestinvalitys-raportointi
npm run build
cd "${git_root}"
echo "Copying artefacts to deployment folder"
rm -rf ./target
mkdir -p ./target/lambdat
cp ./lambdat/vastaanotto/target/vastaanotto.zip ./target/lambdat/vastaanotto.zip
cp ./lambdat/raportointi/target/raportointi.zip ./target/lambdat/raportointi.zip
cp ./lambdat/ajastus/target/ajastus.zip ./target/lambdat/ajastus.zip
cp ./lambdat/lahetys/target/lahetys.zip ./target/lambdat/lahetys.zip
cp ./lambdat/skannaus/target/skannaus.zip ./target/lambdat/skannaus.zip
cp ./lambdat/tilapaivitys/target/tilapaivitys.zip ./target/lambdat/tilapaivitys.zip
cp ./lambdat/siivous/target/siivous.zip ./target/lambdat/siivous.zip
cp ./lambdat/migraatio/target/migraatio.zip ./target/lambdat/migraatio.zip
cp -R ./static ./target/static
echo "Building Lambda code, synhesizing CDK code and deploying to environment: $environment"
cd "${git_root}/cdk/"
aws-vault exec $aws_profile -- cdk deploy PersistenssiStack -c "environment=$environment"
aws-vault exec $aws_profile -- cdk deploy MigraatioStack -c "environment=$environment"
aws-vault exec $aws_profile -- cdk deploy SovellusStack -c "environment=$environment"
fi