-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild_image.sh
executable file
·81 lines (70 loc) · 2.09 KB
/
build_image.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
#!/bin/bash
action="$1"
env="$2"
debug="False"
if [[ ( $@ == "--help") || $@ == "-h" ]]; then
echo "$0 all prod"
exit 1
fi
if [[ "$env" = "prod" ]]; then
tag="$3"
if [[ "$tag" = "" ]]; then
echo "Version tag is missing"
tag=$(date +%Y.%m.%d.%H.%M%S)
#exit 1
fi
disttype="release"
debug="False"
elif [[ "$env" = "uat" ]]; then
tag="latest"
disttype="dev"
debug="True"
elif [[ "$env" = "dev" ]]; then
tag="dev"
disttype="dev"
debug="True"
elif [[ "$env" = "" ]]; then
echo "Please choose the environment where the image will be running? release , uat or dev"
exit 1
else
echo "Only release, uat and dev environment are supported."
exit 1
fi
BUILD_TAG=dbcawa/bfrs:$tag
echo "Begin to build bfrs with tag '${BUILD_TAG}' for '$env' environment"
if [[ "$action" = "all" ]] || [[ "$action" = "build" ]]; then
docker image build -t ${BUILD_TAG} -f Dockerfile .
if [[ $? -ne 0 ]]; then
echo "Build docker image failed"
exit 1
fi
fi
if [[ "$action" = "all_ignore" ]] || [[ "$action" = "test_ignore" ]]; then
docker container run --publish 30019:8080 --env DEBUG=debug --env ENV_TYPE=${env} --env DIST_TYPE=${disttype} dbcawa/bfrs:${tag}
if [[ $? -ne 0 ]]; then
echo "Run the image in local container failed"
exit 1
fi
echo "Image is running in local container which is listening on 30019 port, please test it..."
if [[ "$action" = "all" ]] ; then
printf "Test successfully, (Y)es (N)o (Y):"
read isOk
isOk="${isOk^^}"
if [[ "$isOk" != "Y" ]] && [[ "$isOk" != "" ]] ; then
echo "Test failed."
exit 1
fi
fi
fi
echo $BUILD_TAG
if [[ "$action" = "all" ]] || [[ "$action" = "push" ]]; then
pass show docker-credential-helpers/docker-pass-initialized-check
docker login
docker image push dbcawa/bfrs:${tag}
if [[ $? -ne 0 ]]; then
echo "Failed to push imgage to docker hub"
exit 1
fi
echo "Succeed to publish imgage to docker hub"
echo "Please logon to the docker runtime server to run the image "
fi