forked from vouch/vouch-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo.sh
executable file
·158 lines (131 loc) · 3.28 KB
/
do.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -e
# change dir to where this script is running
CURDIR=${PWD}
SCRIPT=$(readlink -f "$0")
SDIR=$(dirname "$SCRIPT")
cd $SDIR
export VOUCH_ROOT=${GOPATH}/src/github.com/vouch/vouch-proxy/
IMAGE=voucher/vouch-proxy
GOIMAGE=golang:1.10
NAME=vouch-proxy
HTTPPORT=9090
GODOC_PORT=5050
run () {
go run main.go
}
build () {
local VERSION=$(git describe --always --long)
local DT=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # ISO-8601
local FQDN=$(hostname --fqdn)
local SEMVER=$(git tag --list --sort="v:refname" | tail -n -1)
local BRANCH=$(git rev-parse --abbrev-ref HEAD)
go build -i -v -ldflags=" -X main.version=${VERSION} -X main.builddt=${DT} -X main.host=${FQDN} -X main.semver=${SEMVER} -X main.branch=${BRANCH}" .
}
install () {
cp ./vouch-proxy ${GOPATH}/bin/vouch-proxy
}
gogo () {
docker run --rm -i -t -v /var/run/docker.sock:/var/run/docker.sock -v ${SDIR}/go:/go --name gogo $GOIMAGE $*
}
dbuild () {
docker build -f Dockerfile -t $IMAGE .
}
gobuildstatic () {
export CGO_ENABLED=0
export GOOS=linux
build
}
drun () {
if [ "$(docker ps | grep $NAME)" ]; then
docker stop $NAME
docker rm $NAME
fi
CMD="docker run --rm -i -t
-p ${HTTPPORT}:${HTTPPORT}
--name $NAME
-v ${SDIR}/config:/config
-v ${SDIR}/data:/data
$IMAGE $* "
echo $CMD
$CMD
}
watch () {
CMD=$@;
if [ -z "$CMD" ]; then
CMD="go run main.go"
fi
clear
echo -e "starting watcher for:\n\t$CMD"
# TODO: add *.tmpl and *.css
# find . -type f -name '*.css' | entr -cr $CMD
find . -name '*.go' | entr -cr $CMD
}
goget () {
# install all the things
go get -t -v ./...
}
coverage() {
export EXTRA_TEST_ARGS='-cover'
test
go tool cover -html=coverage.out -o coverage.html
}
test () {
if [ -z "$VOUCH_CONFIG" ]; then
export VOUCH_CONFIG="$SDIR/config/test_config.yml"
fi
# test all the things
if [ -n "$*" ]; then
go test -v -race $EXTRA_TEST_ARGS $*
else
go test -v -race $EXTRA_TEST_ARGS ./...
fi
}
loc () {
find . -name '*.go' | xargs wc -l | grep total | cut -d' ' -f2
}
DB=data/vouch_bolt.db
browsebolt() {
${GOPATH}/bin/boltbrowser $DB
}
usage() {
cat <<EOF
usage:
$0 run - go run main.go
$0 build - go build
$0 install - move binary to ${GOPATH}/bin/vouch
$0 goget - get all dependencies
$0 dbuild - build docker container
$0 drun [args] - run docker container
$0 coverage - code coverage report
$0 test [./pkg_test.go] - run go tests (defaults to all tests)
$0 coverage - coverage report
$0 browsebolt - browse the boltdb at ${DB}
$0 gogo [gocmd] - run, build, any go cmd
$0 loc - lines of code in project
$0 watch [cmd]] - watch the $CWD for any change and re-reun the [cmd]
do is like make
EOF
exit 1
}
ARG=$1;
case "$ARG" in
'run'|'build'|'browsebolt'|'dbuild'|'drun'|'install'|'test'|'goget'|'gogo'|'watch'|'gobuildstatic'|'coverage'|'loc'|'usage')
shift
$ARG $*
;;
'godoc')
echo "godoc running at http://${GODOC_PORT}"
godoc -http=:${GODOC_PORT}
;;
'all')
shift
gobuildstatic
dbuild
drun $*
;;
*)
usage
;;
esac
exit;