Skip to content

Commit 98f2f2e

Browse files
author
Cobin Bluth
committed
add build script
1 parent 465c340 commit 98f2f2e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
scratch
2+
.DS_Store
3+
cmd/pbin/build.tgz
4+
cmd/pbin/build
5+
cmd/pbin/build/**

cmd/pbin/build.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
DOCKERFILE="$(cat << EOF
6+
FROM golang:latest as build
7+
SHELL ["/bin/bash", "-c"]
8+
WORKDIR /build
9+
ADD . /build
10+
RUN go mod download
11+
RUN cd cmd/pbin && \
12+
GOOS=darwin \
13+
GOARCH=amd64 \
14+
go build \
15+
-a \
16+
-o /build/pbin-darwin \
17+
.
18+
RUN cd cmd/pbin && \
19+
GOOS=linux \
20+
GOARCH=amd64 \
21+
go build \
22+
-a \
23+
-o /build/pbin-linux \
24+
.
25+
RUN cd cmd/pbin && \
26+
GOOS=windows \
27+
GOARCH=amd64 \
28+
go build \
29+
-a \
30+
-o /build/pbin-windows \
31+
.
32+
RUN tar -cvzf build.tgz \
33+
pbin-linux \
34+
pbin-darwin \
35+
pbin-windows
36+
FROM golang:latest
37+
COPY --from=build /build/build.tgz /opt/
38+
CMD ["cat", "/opt/build.tgz"]
39+
EOF
40+
)"
41+
42+
function build
43+
{
44+
local SCRIPT_PATH="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
45+
pushd "${SCRIPT_PATH}"
46+
while [[ "${PWD}" != '/' && ! -f "go.mod" ]] ; do
47+
cd ..
48+
done
49+
docker build \
50+
-t build:tmp \
51+
-f - \
52+
. <<< "${DOCKERFILE}"
53+
docker run --rm build:tmp > "${SCRIPT_PATH}/build.tgz"
54+
popd
55+
}
56+
57+
build
58+

0 commit comments

Comments
 (0)