Skip to content

Commit

Permalink
add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobin Bluth committed May 10, 2021
1 parent 465c340 commit 98f2f2e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
scratch
.DS_Store
cmd/pbin/build.tgz
cmd/pbin/build
cmd/pbin/build/**
58 changes: 58 additions & 0 deletions cmd/pbin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -e

DOCKERFILE="$(cat << EOF
FROM golang:latest as build
SHELL ["/bin/bash", "-c"]
WORKDIR /build
ADD . /build
RUN go mod download
RUN cd cmd/pbin && \
GOOS=darwin \
GOARCH=amd64 \
go build \
-a \
-o /build/pbin-darwin \
.
RUN cd cmd/pbin && \
GOOS=linux \
GOARCH=amd64 \
go build \
-a \
-o /build/pbin-linux \
.
RUN cd cmd/pbin && \
GOOS=windows \
GOARCH=amd64 \
go build \
-a \
-o /build/pbin-windows \
.
RUN tar -cvzf build.tgz \
pbin-linux \
pbin-darwin \
pbin-windows
FROM golang:latest
COPY --from=build /build/build.tgz /opt/
CMD ["cat", "/opt/build.tgz"]
EOF
)"

function build
{
local SCRIPT_PATH="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
pushd "${SCRIPT_PATH}"
while [[ "${PWD}" != '/' && ! -f "go.mod" ]] ; do
cd ..
done
docker build \
-t build:tmp \
-f - \
. <<< "${DOCKERFILE}"
docker run --rm build:tmp > "${SCRIPT_PATH}/build.tgz"
popd
}

build

0 comments on commit 98f2f2e

Please sign in to comment.