-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·84 lines (77 loc) · 1.82 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
#!/usr/bin/env bash
#
# builds the project in temp docker env
#
set -e
PROJECT="$(grep module go.mod | awk '{print $2}')"
SCRIPTPATH="$(dirname "$(readlink -f "${0}")")"
DOCKERTAG="${PROJECT}-build:tmp"
BINARY="${PROJECT}"
SILENT="${1}" # ./build.sh -s
DOCKERFILE="$(cat << EOF
FROM golang:latest as build
SHELL ["/bin/bash", "-c"]
WORKDIR /build
ADD . /build
RUN GOOS=linux GOARCH=amd64 go build \
-a \
-o /build/${PROJECT}-linux \
.
RUN GOOS=darwin GOARCH=amd64 go build \
-a \
-o /build/${PROJECT}-darwin \
.
FROM golang:latest
COPY --from=build /build/${PROJECT}-linux /build/
COPY --from=build /build/${PROJECT}-darwin /build/
CMD ["bash", "-c", "tar -cv /build/ | gzip"]
EOF
)"
spinner()
{
# http://fitnr.com/showing-a-bash-spinner.html
local pid=$1
local delay=0.15
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
build()
{
pushd "${SCRIPTPATH}/" > /dev/null 2>&1
echo
echo "Using temporary docker build environment..."
echo
docker build \
-t "${DOCKERTAG}" \
-f - \
. <<< "${DOCKERFILE}"
docker run --rm "${DOCKERTAG}" > "release.tgz"
# docker rmi "${DOCKERTAG}"
# chmod a+rx "${BINARY}"
echo
# echo "Removed temporary build environment"
# echo
popd > /dev/null 2>&1
echo -n "Build time:"
}
echo -n "Building... "
if [[ ! "${SILENT}" == "-s" ]] ; then
(
time build
echo
# echo "${PROJECT^^} project executable: ${HOME}/.local/bin/${BINARY}"
# echo
) &
else
(build) > /dev/null 2>&1 &
fi
spinner $!
# cp "${BINARY}" "${HOME}/.local/bin/"
echo "Done!"