-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.sh
executable file
·106 lines (90 loc) · 2.79 KB
/
docker.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
#!/usr/bin/env bash
set -e
cd $(dirname "$0")
TARGET=()
export TAG=${TAG:-$(git describe --tags)-$(git rev-parse --short HEAD)}
# Set defaults, allow env val to override
BUILD_AND_RELEASE=${BUILD_AND_RELEASE:-"false"}
DO_PUSH=${DO_PUSH:-"false"}
DO_TEST=${DO_TEST:-"true"}
DO_VERIFY=${DO_VERIFY:-"true"}
DO_VET=${DO_VET:-"true"}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--fast)
DO_TEST="false"
DO_VERIFY="false"
DO_VET="false"
shift
;;
--push)
DO_PUSH="true"
shift
;;
--no-test)
DO_TEST="false"
shift
;;
--no-verify)
DO_VERIFY="false"
shift
;;
--no-vet)
DO_VET="false"
shift
;;
*)
TARGET+=("$1")
shift
;;
esac
done
# Let this run the `go mod verify` task, so that we don't have to in every
# docker build.
TARGETS=$(IFS=","; echo "${TARGET[*]}")
time docker build --build-arg DO_TEST=$DO_TEST --build-arg DO_VET=$DO_VET --build-arg DO_VERIFY=$DO_VERIFY --build-arg TARGET="$TARGETS" --build-arg BUILD_AND_RELEASE=$BUILD_AND_RELEASE --tag gobuild:local -f build_tools/Dockerfile .
DOCKER_IMAGES=()
echo "Targets length: ${#TARGET[@]}"
if [ ${#TARGET[@]} -eq 0 ]; then
echo "No targets specified for docker images; searching directory."
TARGET=($(ls apps))
fi
for D in ${TARGET[@]}; do
if ! [ -d "./apps/$D" ]; then
continue
fi
if [ ! -z $TARGET ] && [[ ! " ${TARGET[@]} " =~ " ${D} " ]]; then
continue
fi
if [ -f "./apps/$D/docker-targets.ini" ]; then
echo ""
echo "Found apps/$D/docker-targets.ini..."
IFS=$'\n'
for LINE in $(cat < "./apps/$D/docker-targets.ini"); do
DOCKER_FILENAME="$(echo -e "${LINE%=*}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
DOCKER_IMAGENAME="$(echo -e "${LINE#*=}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo ""
echo "Building targetted docker image for '$D' using '$DOCKER_FILENAME' to build '$DOCKER_IMAGENAME'..."
time docker build -t "object88/$DOCKER_IMAGENAME:latest" -f apps/$D/$DOCKER_FILENAME .
docker tag "object88/$DOCKER_IMAGENAME:latest" "object88/$DOCKER_IMAGENAME:$TAG"
DOCKER_IMAGES+=("$DOCKER_IMAGENAME:$TAG")
done
elif [ -f "./apps/$D/Dockerfile" ]; then
DOCKER_IMAGENAME="$D"
echo ""
echo "Building docker image for '$D'..."
time docker build -t "object88/$DOCKER_IMAGENAME:latest" -f apps/$D/Dockerfile .
docker tag "object88/$DOCKER_IMAGENAME:latest" "object88/$DOCKER_IMAGENAME:$TAG"
DOCKER_IMAGES+=("$DOCKER_IMAGENAME:$TAG")
fi
done
if [[ $DO_PUSH == "true" ]]; then
echo "Pushing build images..."
for I in "${DOCKER_IMAGES[@]}"; do
echo "Pushing docker image 'object88/$I'"
time docker push "object88/$I"
done
echo "Pushed images."
fi
echo "Finished building the docker images"