-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docker
78 lines (68 loc) · 1.54 KB
/
build_docker
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
#!/usr/bin/env bash
set -e
declare -r current_dir=$(cd "$(dirname "$0")"; pwd)
declare -r image_name="lemur_client"
PREFIX=container.repo.example.com/${image_name}
TAG="${2:-v1}"
GOOS="linux"
run_tests() {
build_image
echo "##### RUNNING TESTS #####"
docker run --rm -v "$PWD":/lemur -w /lemur/src/lemur -e GOPATH=/lemur golang:1.7 go test
echo "####### RAN TESTS #######"
retval=$?
docker rmi -f golang:1.7
cleanup
}
build_image() {
# Per-line:
# mount our repo
# working directory should be in our source
# make sure GOPATH refers to top-level of repo
# build/run on scratch
# disable CGO for a static binary
# -a rebuilds our vendored dependencies
# keep output separate from default builds
# put binary in top-level bin/
docker run --rm \
-v "$PWD":/lemur \
-w /lemur/src/lemur \
-e GOPATH=/lemur \
-e GOOS=${GOOS} \
-e CGO_ENABLED=0 \
-u $(id -u):$(id -g) \
golang:1.7 go build -a \
-installsuffix cgo \
-v -o ../../bin/lemur-client \
# Grab a fresh copy of default root certs
docker run -i centos:7 \
/bin/sh -c \
'cat /etc/ssl/certs/ca-bundle.crt' > ca-certificates.crt
docker build -t ${PREFIX}:${TAG} ${current_dir}
}
push_to_registry() {
docker push ${PREFIX}:${TAG}
}
cleanup() {
docker rmi -f ${PREFIX}:${TAG}
}
case $1 in
tests)
run_tests
exit $retval
;;
push)
build_image
push_to_registry
cleanup
;;
develop)
GOOS="darwin"
run_tests
exit $retval
;;
*)
echo "Nothing to do right now"
;;
esac
exit 0