This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
forked from aramse/k8s-job-reaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·72 lines (61 loc) · 1.67 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
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash -e
export REGION=us-west-2
export REALM=org
export AWS_PROFILE=${REALM}_shared_services_admin
export SHARED_SERVICES_ACCOUNT_NUM=232624534379
rootdir=$(pwd)
tag=$(git rev-parse HEAD)
current_branch=$(git branch | grep \* | cut -d ' ' -f2)
dry_run=false
declare -a images_to_build
if [ "${IMAGE}" != "" ]; then
images_to_build+=(${IMAGE})
fi
if [ ${#images_to_build[@]} -eq 0 ]; then
images_to_build=("k8reaper")
fi
if [ "${current_branch}" == "master" ]; then
dry_run=false
fi
function run_test() {
name=$1
echo "******"
echo "Running functional test for ${name} image. Note that you need to be on the vpn for some of the tests to be successful".
echo "******"
./tests/${name}_test.sh
}
# set dry_run var based on branch name -
# please do not push a new image unless you're doing it from branch master
function build_and_push() {
name=$1
echo "*****"
echo "Building ${name}"
echo "*****"
docker build . --target=${name} -t ${name}:${tag} -t ${name}:latest
run_test ${name}
set -x
if [ "${dry_run}" == false ]; then
echo "pushing ${name} to ecr"
./push_to_docker_registry.sh \
--image-name ${name} \
--tag-value ${tag} \
--build-number $(whoami) \
--branch-name ${current_branch} \
--repo-type ecr \
--aws-account-num ${SHARED_SERVICES_ACCOUNT_NUM} \
--aws-region ${REGION} \
--aws-profile ${AWS_PROFILE}
echo "${name} successfully pushed to ecr"
else
echo "*****"
echo "script is running in dry run mode"
echo "Done building ${name}"
echo "*****"
fi
set +x
}
for image in "${images_to_build[@]}"; do
build_and_push ${image}
done
#clean up the _output directory
rm -rf _output