Skip to content

Instantly share code, notes, and snippets.

@lukegb
Last active August 10, 2020 23:57
Show Gist options
  • Save lukegb/52514684fe3f61b2ece27e2980e32f12 to your computer and use it in GitHub Desktop.
Save lukegb/52514684fe3f61b2ece27e2980e32f12 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
pushd /tmp/src
if [[ `go list -f {{.Incomplete}}` == "true" || ! -z "$IMPORT_URL" ]]; then
INSTALL_URL=${INSTALL_URL:-$IMPORT_URL}
if [[ ! -z "$IMPORT_URL" ]]; then
popd
echo "Assembling GOPATH"
export GOPATH=`realpath $HOME/go`
mkdir -p "$GOPATH/src/$IMPORT_URL"
shopt -s dotglob
mv /tmp/src/* "$GOPATH/src/$IMPORT_URL"
if [[ -d "/tmp/artifacts/pkg" ]] || [[ -d "/tmp/artifacts/go-build" ]]; then
echo "Restoring previous build artifacts"
mv "/tmp/artifacts/pkg" "$GOPATH"
GOCACHE=`go env GOCACHE`
mkdir -p "$GOCACHE"
mv /tmp/artifacts/go-build "$GOCACHE"
fi
# Resolve dependencies, ignore if vendor present
if [[ ! -d "$GOPATH/src/$INSTALL_URL/vendor" ]] && [[ `go list -f {{.Incomplete}} "$INSTALL_URL"` == "true" ]]; then
echo "Resolving dependencies"
pushd "$GOPATH/src/$INSTALL_URL"
go get
popd
fi
# lets build
pushd "$GOPATH/src/$INSTALL_URL"
echo "Building"
go install "$INSTALL_URL"
mv "$GOPATH/bin/*" /opt/app-root/gobinary
setcap cap_net_raw+ep /opt/app-root/gobinary
popd
exit
fi
echo "ERROR: Package is missing dependencies and IMPORT_URL inference failed. Set IMPORT_URL env var."
exec "/$STI_SCRIPTS_PATH/usage"
else
go build -o /opt/app-root/gobinary
setcap cap_net_raw+ep /opt/app-root/gobinary
popd
fi
#!/bin/bash
set -e
exec /opt/app-root/gobinary "$@"
#!/bin/bash
set -e
TOSAVE=""
if [[ -d "$HOME/go/pkg" ]]; then
mv "$HOME/go/pkg" pkg &> /dev/null
TOSAVE="$TOSAVE./pkg "
fi
if [[ -d `go env GOCACHE` ]]; then
mv `go env GOCACHE` go-build &> /dev/null
TOSAVE="$TOSAVE./go-build "
fi
if [[ -n "$TOSAVE" ]]; then
tar -cf - "$TOSAVE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment