-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
63 lines (50 loc) · 1.85 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
#!/usr/bin/env bash
set -e
export GO111MODULE=on
export GOFLAGS=-mod=vendor
PROVIDER_ROOT=$(git rev-parse --show-toplevel)
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
DATE=$(date "+%Y-%m-%d")
BUILD_PLATFORM=$(uname -a | awk '{print tolower($1);}')
echo "Current working directory is $(pwd)"
echo "PATH is $PATH"
echo "GOPATH is $GOPATH"
if [[ "$(pwd)" != "${PROVIDER_ROOT}" ]]; then
echo "you are not in the root of the repo" 1>&2
echo "please cd to ${PROVIDER_ROOT} before running this script" 1>&2
exit 1
fi
GO_BUILD_CMD="go build"
GO_BUILD_LDFLAGS="-s -w"
if [[ -z "${PROVIDER_BUILD_PLATFORMS}" ]]; then
PROVIDER_BUILD_PLATFORMS="linux windows darwin"
fi
if [[ -z "${PROVIDER_BUILD_ARCHS}" ]]; then
PROVIDER_BUILD_ARCHS="amd64 arm64"
fi
# Create the release directory
mkdir -p "${PROVIDER_ROOT}/release"
for OS in ${PROVIDER_BUILD_PLATFORMS[@]}; do
for ARCH in ${PROVIDER_BUILD_ARCHS[@]}; do
NAME="devpod-provider-vultr-${OS}-${ARCH}"
if [[ "${OS}" == "windows" ]]; then
NAME="${NAME}.exe"
fi
# darwin 386 is deprecated and shouldn't be used anymore
if [[ "${ARCH}" == "386" && "${OS}" == "darwin" ]]; then
echo "Building for ${OS}/${ARCH} not supported."
continue
fi
# arm64 build is only supported for darwin
if [[ "${ARCH}" == "arm64" && "${OS}" == "windows" ]]; then
echo "Building for ${OS}/${ARCH} not supported."
continue
fi
echo "Building for ${OS}/${ARCH}"
GOARCH=${ARCH} GOOS=${OS} ${GO_BUILD_CMD} -ldflags "${GO_BUILD_LDFLAGS}"\
-o "${PROVIDER_ROOT}/release/${NAME}" main.go
shasum -a 256 "${PROVIDER_ROOT}/release/${NAME}" | cut -d ' ' -f 1 > "${PROVIDER_ROOT}/release/${NAME}".sha256
done
done
# generate provider.yaml
go run -mod vendor "${PROVIDER_ROOT}/hack/provider/main.go" ${RELEASE_VERSION} > "${PROVIDER_ROOT}/release/provider.yaml"