-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·67 lines (56 loc) · 1.13 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
#!/bin/bash
APP_NAME=tattle
TMP_DIR=$PWD/tmp
IMAGE_NAME=local/$APP_NAME
build_on_docker() {
docker build --tag $IMAGE_NAME:built .
}
build_on_local() {
env GOOS=linux go build -a -tags netgo -installsuffix cgo -ldflags '-w' -o "${TMP_DIR}/${APP_NAME}" .
}
copy() {
cp $TMP_DIR/$APP_NAME entrypoint/
}
init() {
rm -rf $TMP_DIR/ \
&& mkdir -p $TMP_DIR/
}
package() {
docker build --tag $IMAGE_NAME:latest entrypoint
}
run() {
docker run --rm \
--volume $TMP_DIR:/export/ \
$IMAGE_NAME:built \
cp $APP_NAME /export
}
panic() {
local message=$1
echo $message
exit 1
}
docker_build() {
init || panic "init failed"
build_on_docker || panic "build_on_docker failed"
run || panic "run failed"
copy || panic "copy failed"
package || panic "package failed"
}
local_build() {
init || panic "init failed"
build_on_local || panic "build_on_local failed"
copy || panic "copy failed"
package || panic "package failed"
}
main() {
local mode="$1"
if [ "$mode" == "local" ]; then
echo "Local Build"
local_build
else
echo "Docker Build"
docker_build
fi
exit $?
}
main $@