build.sh
1.7 KB
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
#!/bin/bash
set -e
declare -a images=(moqui-jdbc-drivers moqui-app)
TOP_DIR="$(cd "$(dirname "$0")"; pwd -P)"
_build() {
for image in "${images[@]}"; do
docker buildx build --progress plain --build-context "moqui-builder=$TOP_DIR" -f "${TOP_DIR}/Dockerfile" --tag "${PREFIX}${image}:${TAG}" --target "${image}" "${APP}"
done
}
_push() {
for image in "${images[@]}"; do
echo "Pushing ${PREFIX}${image}:${TAG} to ${PUSH_TO}/${image}:${TAG}"
skopeo copy --dest-tls-verify=false "docker-daemon:${PREFIX}${image}:${TAG}" "${PUSH_TO}/${image}:${TAG}"
done
}
APP=moqui-app
OVERRIDE_TAG=
DEVELOPER=
PUSH_TO=
PREFIX=
while [[ $# -gt 0 ]]; do
case "$1" in
(--app)
APP="$2"
shift 2
;;
(--prefix)
PREFIX="$2"
shift 2
;;
(--push-to)
PUSH_TO="$2"
shift 2
;;
(--tag)
OVERRIDE_TAG="$2"
shift 2
;;
(--developer)
DEVELOPER="$2"
shift 2
;;
(*)
break
;;
esac
done
declare -A build_env=()
if [[ -f $APP/.build.env ]]; then
set -x
while read line; do
[[ $line = ^"#".* ]] && continue
if [[ $line =~ ^\s*(.*?)\s*=\s*(.*?)\s*$ ]]; then
build_env[${BASH_REMATCH[1]}]="${BASH_REMATCH[2]}"
fi
done < "$APP/.build.env"
set +x
fi
[[ -z $OVERRIDE_TAG ]] && OVERRIDE_TAG="${build_env["override-tag"]}"
[[ -z $DEVELOPER ]] && DEVELOPER="${build_env["developer"]}"
[[ -z $PREFIX ]] && PREFIX="${build_env["prefix"]}"
[[ -z $PUSH_TO ]] && PUSH_TO="${build_env["push-to"]}"
if [[ $OVERRIDE_TAG ]]; then
TAG="$OVERRIDE_TAG"
elif [[ -e $APP/.git ]]; then
TAG="$(GIT_DIR="$APP/.git" git branch --show-current)"
else
TAG=test-latest
fi
if [[ $DEVELOPER ]]; then
TAG+="-$DEVELOPER"
fi
case "$1" in
(build)
_build
;;
(push)
_push
;;
("")
_build
_push
;;
esac