-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·142 lines (124 loc) · 4.5 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
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
#!/bin/sh
set -e
GORELEASER_VERSION="v2.8.2"
USER_UID=$(id -u)
rm -fr work
case "$1" in
"")
;;
"go")
ONLY_GO=1
;;
"race")
ONLY_GO=1
WITH_RACE=1
;;
"no-js")
SKIP_JS=1
;;
"only-js")
ONLY_JS=1
;;
"docker-fast")
ONLY_DOCKER_FAST=1
SKIP_JS=1
;;
*)
echo "Usage: $0 [go|race|no-js|only-js|docker-fast]"
echo " go: only compile Go"
echo " race: only compile Go with -race"
echo " no-js: skip building JS"
echo " only-js: just JS (and go generate)"
echo " docker-fast: build a docker from ./glouton (so you should run ./build.sh go before)"
exit 1
esac
if [ "$2" != "" ]; then
echo "This script doesn't support multiple options"
exit 1
fi
if docker volume ls | grep -q glouton-buildcache; then
GO_MOUNT_CACHE="-v glouton-buildcache:/go/pkg"
NODE_MOUNT_CACHE="-v glouton-buildcache:/go/pkg"
fi
if [ "${ONLY_GO}" = "1" ] || [ "${ONLY_DOCKER_FAST}" = "1" ] || [ "${SKIP_JS}" = "1" ]; then
echo "Skip cleaning workspace because only Go binary build is enabled, or Docker fast is enabled, or JS skipping is enabled"
else
echo "Cleanup workspace"
rm -fr webui/dist webui/node_modules api/static/assets/css/ api/static/assets/js/ api/api-bindata.go api/api-packr.go api/packrd/
fi
if [ "${SKIP_JS}" != "1" ] && [ "${ONLY_GO}" != "1" ]; then
echo "Building webui"
mkdir -p api/static/assets/css/ api/static/assets/js/ webui/node_modules
docker run --rm -e HOME=/go/pkg/node \
-v $(pwd):/src --tmpfs /src/webui/node_modules:exec -w /src/webui ${NODE_MOUNT_CACHE} \
node:22 \
sh -exc "
mkdir -p /go/pkg/node
chown node -R /go/pkg/node
npm install
npm run deploy
chown -R $USER_UID dist ../api/static/assets/js/ ../api/static/assets/css/
"
fi
if [ -z "${GLOUTON_VERSION}" ]; then
GLOUTON_VERSION=$(date -u +%y.%m.%d.%H%M%S)
fi
if [ -z "${GLOUTON_BUILDX_OPTION}" ]; then
GLOUTON_BUILDX_OPTION="-t glouton:latest --load"
fi
export GLOUTON_VERSION
COMMIT=$(git rev-parse --short HEAD || echo "unknown")
if [ "${ONLY_JS}" = "1" ]; then
exit 0
fi
echo "Building Go binary"
if [ "${ONLY_DOCKER_FAST}" = "1" ]; then
echo "Building a Docker image using ./glouton"
sed 's@COPY dist/glouton_linux_.*/glouton /glouton.@COPY glouton /glouton.@' Dockerfile | docker buildx build ${GLOUTON_BUILDX_OPTION} -f - .
elif [ "${ONLY_GO}" = "1" ] && [ "${WITH_RACE}" != "1" ]; then
docker run --rm -e HOME=/go/pkg -e CGO_ENABLED=0 \
-v $(pwd):/src -w /src ${GO_MOUNT_CACHE} \
--entrypoint '' \
goreleaser/goreleaser:${GORELEASER_VERSION} \
tini -g -- sh -exc "
git config --global --add safe.directory /src
go build -ldflags='-X main.version=${GLOUTON_VERSION} -X main.commit=${COMMIT}' .
chown $USER_UID glouton
"
elif [ "${ONLY_GO}" = "1" ] && [ "${WITH_RACE}" = "1" ]; then
docker run --rm -e HOME=/go/pkg -e CGO_ENABLED=1 \
-v $(pwd):/src -w /src ${GO_MOUNT_CACHE} \
--entrypoint '' \
goreleaser/goreleaser:${GORELEASER_VERSION} \
tini -g -- sh -exc "
git config --global --add safe.directory /src
go build -ldflags='-X main.version=${GLOUTON_VERSION} -X main.commit=${COMMIT} -linkmode external -extldflags=-static' -race .
chown $USER_UID glouton
"
else
docker run --rm -e HOME=/go/pkg -e CGO_ENABLED=0 \
-v $(pwd):/src -w /src ${GO_MOUNT_CACHE} \
-v /var/run/docker.sock:/var/run/docker.sock \
--entrypoint '' \
-e GLOUTON_VERSION \
-e GORELEASER_PREVIOUS_TAG=0.1.0 \
-e GORELEASER_CURRENT_TAG=0.1.1 \
goreleaser/goreleaser:${GORELEASER_VERSION} \
tini -g -- sh -exc "
mkdir -p /go/pkg
git config --global --add safe.directory /src
goreleaser check
go generate ./...
go test ./...
goreleaser --clean --snapshot --parallelism 2 --timeout 45m
chown -R $USER_UID dist
"
echo $GLOUTON_VERSION > dist/VERSION
# Build Docker image using buildx. We use docker buildx instead of goreleaser because
# goreleaser use "docker manifest" which require to push image to a registry. This means we ends with 4 tags:
# 3 for each of the 3 supported architectures and 1 for the multi-architecture image.
# Using buildx only generate 1 tag on the Docker Hub.
docker buildx build ${GLOUTON_BUILDX_OPTION} .
sed "s@image: bleemeo/bleemeo-agent:latest@image: bleemeo/bleemeo-agent:${GLOUTON_VERSION}@" k8s.yaml > dist/k8s.yaml
./packaging/windows/generate_installer.sh
fi