forked from DNUM-SocialGouv/champollion-front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
83 lines (73 loc) · 2.56 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
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
Help()
{
# Display Help
echo "Build and push docker images of the repository."
echo
echo "Syntax: bash build.sh [-h|e|p|i]"
echo "options:"
echo "h display this help and exit"
echo "e env file"
echo "p optional, push images to Nexus"
echo "i optional, ignore image to build and push ('app', 'oauth2-proxy' or 'reverse-proxy')"
}
while getopts "he:pi:" flag
do
case "${flag}" in
h) Help && exit 1;;
e) env=${OPTARG};;
p) push=${OPTARG:-"enable"};;
i) ignore+=(${OPTARG});;
esac
done
# export environment variables
if [[ -z $env ]]; then
echo "-e argument is required. Help:" && Help && exit 0
elif ! [[ -f $env ]]; then
echo "file specified with -e argument does not exists. Help:" && Help && exit 0
else
export $(grep -v "#" $env | xargs)
fi
# ignore images
if [ ${#ignore[@]} -ge 1 ]; then
for image in "${ignore[@]}"; do
if [[ $image == "app" ]]; then
ignore_app=true
elif [[ $image == "oauth2-proxy" ]]; then
ignore_oauth2_proxy=true
elif [[ $image == "reverse-proxy" ]]; then
ignore_reverse_proxy=true
else
echo "unavailable images specified by -i argument." && Help && exit 0
fi
done
fi
# build and push
if [[ -z $ignore_app ]]; then
docker build --rm --file ${HOME}/${APP_BUILD_CONTEXT}/Dockerfile \
--build-arg HTTP_PROXY=${HTTP_PROXY} \
--build-arg HTTPS_PROXY=${HTTPS_PROXY} \
--build-arg VITE_API_BASE_URL=${VITE_API_BASE_URL} \
--build-arg VITE_LOGOUT_URL=${VITE_LOGOUT_URL} \
--tag ${NEXUS_CHAMPOLLION_URL}/front/app:${APP_IMAGE_TAG} \
${HOME}/${APP_BUILD_CONTEXT}
if ! [[ -z $push ]]; then
docker image push ${NEXUS_CHAMPOLLION_URL}/front/app:${APP_IMAGE_TAG}
fi
fi
if [[ -z $ignore_oauth2_proxy ]]; then
docker build --rm --file ${HOME}/${OAUTH2_PROXY_BUILD_CONTEXT}/Dockerfile \
--tag ${NEXUS_CHAMPOLLION_URL}/front/oauth2-proxy:${OAUTH2_PROXY_IMAGE_TAG} \
${HOME}/${OAUTH2_BUILD_CONTEXT}
if ! [[ -z $push ]]; then
docker image push ${NEXUS_CHAMPOLLION_URL}/front/oauth2-proxy:${OAUTH2_PROXY_IMAGE_TAG}
fi
fi
if [[ -z $ignore_reverse_proxy ]];then
docker build --rm --file ${HOME}/${REVERSE_PROXY_BUILD_CONTEXT}/Dockerfile \
--tag ${NEXUS_CHAMPOLLION_URL}/front/reverse-proxy:${REVERSE_PROXY_IMAGE_TAG} \
${HOME}/${REVERSE_PROXY_BUILD_CONTEXT}
if ! [[ -z $push ]]; then
docker image push ${NEXUS_CHAMPOLLION_URL}/front/reverse-proxy:${REVERSE_PROXY_IMAGE_TAG}
fi
fi