-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·239 lines (191 loc) · 6.39 KB
/
build.sh
File metadata and controls
executable file
·239 lines (191 loc) · 6.39 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
: '
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'
versions=("2_4" "2_5" "2_6" "2_7" "2_8", "2_9")
v_2_4="2.4.3"
v_2_5="2.5.1"
v_2_6="2.6.3"
v_2_7="2.7.2"
v_2_8="2.8.1"
v_2_9="2.9.2"
previous_branch=""
current_branch=""
prompt() {
echo "MWAA Disaster Recovery Build Script"
echo "====================================="
echo "Syntax: build.sh <commmand> <arg1> ... <argn>"
echo "Commands:"
echo " clean: Removes build artifacts"
echo " e.g. $./build.sh clean"
echo " lint: Runs linter"
echo " e.g. $./build.sh lint"
echo " unit: Runs all unit tests by default. Takes a path as an optional argument to run test cases in the supplied path."
echo " e.g. $./build.sh unit"
echo " e.g. $./build.sh unit tests/unit/mwaa_dr"
echo " integration: Runs all integration tests. (Under Development)"
echo " e.g. $./build.sh integration"
echo " setup: Setups up integration test environment by starting mwaa local runner container. Takes mwaa version as an argument -- one of [2_5, 2_6, 2_7, 2_8]."
echo " e.g. $./build.sh setup 2_8"
echo " teardown: Teardowns integration test environment by stopping mwaa local runner container. Takes mwaa version as an argument -- one of [2_5, 2_6, 2_7, 2_8]."
echo " e.g. $./build.sh teardown 2_8"
echo " publish: Publishes the package to a pypi repo. Assumes the ~/.pypirc file has publishing credentials"
echo " e.g. $./build.sh publish"
echo " help: Presents the build options"
echo " e.g. $./build.sh help"
echo "====================================="
}
clean() {
rm -rf .venv
rm -rf .pytest_cache
rm -rf build
rm -rf cdk.out
find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$|\.DS_Store$)" | xargs rm -rf
}
lint() {
pre-commit run --all-files
}
unit_test() {
path="${1:-tests/unit}"
rm -rf coverage
mkdir -p coverage
coverage run -m pytest $path && coverage report -m
result=$?
find . | grep -E "(/__pycache__$|\.pyc$|\.pyo$|\.DS_Store$)" | xargs rm -rf
return $result
}
check_image() {
version=$1
# Check if version is valid
if [[ ! " ${versions[@]} " =~ " ${version} " ]]; then
echo "Unsupported MWAA version: $version! Currently supported version are: ${versions[@]}!"
return 2
fi
# Check if image exists locally
semver="v_$version"
echo "Checking docker image for MWAA version ${!semver} ..."
image="amazon/mwaa-local:$version"
if docker image inspect $image > /dev/null 2>&1; then
echo "Image $image found locally!"
return 0
fi
echo "Image $image not found locally!"
return 1
}
build_image() {
version=$1
semver="v_$version"
echo "Building docker image for MWAA version ${!semver} ..."
cd aws-mwaa-local-runner
git fetch
previous_branch=$(git rev-parse --abbrev-ref HEAD)
current_branch="v${!semver}"
echo "Switching from branch $previous_branch to $current_branch ..."
git checkout $current_branch
cp -f ../assets/requirements.txt ./requirements
./mwaa-local-env build-image
echo "Switching from branch $current_branch to $previous_branch ..."
git reset --hard
git checkout $previous_branch
cd ..
echo "Completed building docker image for MWAA version ${!semver} ..."
}
start_mwaa() {
version=$1
semver="v_$version"
echo "Starting MWAA version ${!semver} locally ..."
cd aws-mwaa-local-runner
echo "Resetting the MWAA local runner project for integration testing ..."
git reset --hard
git fetch
previous_branch=$(git rev-parse --abbrev-ref HEAD)
current_branch="v${!semver}"
echo "Switching from branch $previous_branch to $current_branch ..."
git checkout $current_branch
rm -rf db-data
rm -rf dags/*
cp -f ../assets/requirements.txt ./requirements
cp -r ../assets/dags/* ./dags
cp -r ../tests/integration/dags/* ./dags
cp -r ../tests/integration/startup_script/startup.sh ./startup_script
mkdir -p dags/data
cp -r ../tests/integration/data/v_$version/* ./dags/data
DOCKER_COMPOSE_PROJECT_NAME=aws-mwaa-local-runner-$version
docker-compose -p $DOCKER_COMPOSE_PROJECT_NAME -f ./docker/docker-compose-local.yml up -d
}
stop_mwaa() {
version=$1
semver="v_$version"
echo "Stopping local MWAA version ${!semver} ..."
cd aws-mwaa-local-runner
DOCKER_COMPOSE_PROJECT_NAME=aws-mwaa-local-runner-$version
docker-compose -p $DOCKER_COMPOSE_PROJECT_NAME -f ./docker/docker-compose-local.yml down
cd ..
echo "MWAA version ${!semver} stopped!"
}
integration_test_setup() {
version=$1
echo "Setting up integration tests for MWAA version $version ..."
check_image $version
local result=$?
if [ "$result" -eq 2 ]; then
return 2
elif [ "$result" -eq 1 ]; then
build_image $version
fi
start_mwaa $version
}
integration_test_teardown() {
version=$1
stop_mwaa $version
}
integration_test() {
echo "Integration test feature is under development!"
# pytest -rP tests/integration
}
trigger_dag() {
dag_name=$1
}
publish() {
rm -rf dist
./versioning
python -m build
twine upload --repository testpypi dist/*
}
# Driver
case "$1" in
clean)
clean
;;
lint)
lint
;;
unit)
unit_test $2
;;
integration)
integration_test
;;
setup)
integration_test_setup $2
;;
teardown)
integration_test_teardown $2
;;
publish)
publish
;;
*)
prompt
esac