-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-build.sh
executable file
·116 lines (95 loc) · 3.14 KB
/
docker-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
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
#!/bin/bash
# set -x
export DOCKER_BUILD_KIT=1
if [ ! -d .git ]; then
echo "Must be run from a git directory"
exit 1
fi
NAME=$1
TARGET=
# POD
if [[ "${NAME}" == "pod" || "${NAME}" == "p" ]]; then
TARGET="pod"
fi
# Directory service
if [[ "${NAME}" == "dir" || "${NAME}" == "byoda-directory" || "${NAME}" == "d" ]]; then
TARGET="directory"
fi
# BYODA Service
if [[ "${NAME}" == "svc" || "${NAME}" == "byoda-svc" || "${NAME}" == "s" ]]; then
TARGET="service"
fi
# BYO.Tube service
if [[ "${NAME}" == "b" || "${NAME}" == "t" || "${NAME}" == "byotube" || "${NAME}" == "tube" ]]; then
TARGET="byotube-service"
fi
# BYO.Tube asset updates worker
if [[ "${NAME}" == "svcassetupdatesworker" || "${NAME}" == "updates" || "${NAME}" == "u" ]]; then
TARGET="service-asset-updates-worker"
fi
# BYO.Tube asset refresh worker
if [[ "${NAME}" == "svcassetrefreshworker" || "${NAME}" == "refresh" || "${NAME}" == "r" ]]; then
TARGET="service-asset-refresh-worker"
fi
# BYO.Tube channel refresh worker
if [[ "${NAME}" == "svcchannelrefreshworker" || "${NAME}" == "channel" || "${NAME}" == "cr" || "${NAME}" == "c" ]]; then
TARGET="service-channel-refresh-worker"
fi
# BYO.Tube email worker
if [[ "${NAME}" == "e" || "${NAME}" == "email" ]]; then
TARGET="service-email-worker"
fi
# Generic BYODA application server
if [[ "${NAME}" == "a" || "${NAME}" == "byoda-app" || "${NAME}" == "app" || "${NAME}" == "w" ]]; then
TARGET="app"
fi
# Angie
if [[ "${NAME}" == "angie" ]]; then
TARGET="angie"
docker build . --file Dockerfile-${TARGET} --tag byoda/${TARGET}:${TAG} --build-arg TAG=${TAG}
if [ "$?" -eq "0" ]; then
export IMAGE_ID=$(docker images --format='{{.ID}}' | head -1)
echo "Pushing image: $IMAGE_ID"
docker image tag ${IMAGE_ID} byoda/${TARGET}:${TAG}
docker push byoda/${TARGET}:${TAG}
echo "Docker build of Angie completed"
exit 0
else
echo "Docker build of Angie failed"
exit 1
fi
fi
if [ -z "${TARGET}" ]; then
echo "Must specify a target: ${NAME}"
exit 1
fi
if [ -z "${TAG}" ]; then
RESULT=$(git status | grep 'branch main')
if [ "$?" -eq "0" ]; then
export TAG=latest
else
if [[ "${TARGET}" == "pod" || "${TARGET}" == "p" ]]; then
export TAG=dev
else
export TAG=latest
fi
fi
fi
echo "Using tag: ${TAG}"
TARGETS="pod service service-asset-updates-worker service-asset-refresh-worker service-email-worker directory service-channel-refresh-worker byotube-service app"
if echo "${TARGETS}" | grep -qw "${TARGET}"; then
echo "Building docker container for byoda-${TARGET} with TAG ${TAG} with docker file Dockerfile-${TARGET}"
else
echo "Invalid target: ${TARGET}"
exit 1
fi
docker build . --file Dockerfile-${TARGET} --tag byoda/byoda-${TARGET}:${TAG} --build-arg TAG=${TAG}
if [ "$?" -eq "0" ]; then
export IMAGE_ID=$(docker images --format='{{.ID}}' | head -1)
echo "Pushing image: $IMAGE_ID"
docker image tag ${IMAGE_ID} byoda/byoda-${TARGET}:${TAG}
docker push byoda/byoda-${TARGET}:${TAG}
echo "Docker build completed"
else
echo "Docker build failed"
fi