2023-05-02 03:13:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-10-28 11:18:13 +00:00
|
|
|
mkdir -p dist
|
2019-01-30 22:37:16 +00:00
|
|
|
|
2022-07-14 23:09:38 +00:00
|
|
|
# populate tool versions
|
2024-01-25 05:41:33 +00:00
|
|
|
|
2023-10-24 10:30:33 +00:00
|
|
|
BUILDNUMBER=${BUILDNUMBER:-"N/A"}
|
|
|
|
CONTAINER_IMAGE_TAG=${CONTAINER_IMAGE_TAG:-"N/A"}
|
2024-01-25 05:41:33 +00:00
|
|
|
NODE_VERSION=${NODE_VERSION:-$(node -v)}
|
|
|
|
YARN_VERSION=${YARN_VERSION:-$(yarn --version))}
|
|
|
|
WEBPACK_VERSION=${WEBPACK_VERSION:-$(yarn list webpack --depth=0 | grep webpack | awk -F@ '{print $2}')}
|
|
|
|
GO_VERSION=${GO_VERSION:-$(go version | awk '{print $3}')}
|
|
|
|
GIT_COMMIT_HASH=${GIT_COMMIT_HASH:-$(git rev-parse --short HEAD)}
|
2022-07-14 23:09:38 +00:00
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
# copy templates
|
|
|
|
cp -r "./mustache-templates" "./dist"
|
|
|
|
|
2023-05-02 03:13:37 +00:00
|
|
|
|
|
|
|
cd api || exit 1
|
2021-10-28 11:18:13 +00:00
|
|
|
# the go get adds 8 seconds
|
2019-01-30 22:37:16 +00:00
|
|
|
go get -t -d -v ./...
|
|
|
|
|
2023-05-03 05:13:28 +00:00
|
|
|
|
|
|
|
ldflags="-s -X 'github.com/portainer/liblicense.LicenseServerBaseURL=https://api.portainer.io' \
|
2023-11-01 22:04:11 +00:00
|
|
|
-X 'github.com/portainer/portainer/api/build.BuildNumber=${BUILDNUMBER}' \
|
|
|
|
-X 'github.com/portainer/portainer/api/build.ImageTag=${CONTAINER_IMAGE_TAG}' \
|
|
|
|
-X 'github.com/portainer/portainer/api/build.NodejsVersion=${NODE_VERSION}' \
|
|
|
|
-X 'github.com/portainer/portainer/api/build.YarnVersion=${YARN_VERSION}' \
|
|
|
|
-X 'github.com/portainer/portainer/api/build.WebpackVersion=${WEBPACK_VERSION}' \
|
2024-01-25 05:41:33 +00:00
|
|
|
-X 'github.com/portainer/portainer/api/build.GitCommit=${GIT_COMMIT_HASH}' \
|
2023-11-01 22:04:11 +00:00
|
|
|
-X 'github.com/portainer/portainer/api/build.GoVersion=${GO_VERSION}'"
|
2023-05-03 05:13:28 +00:00
|
|
|
|
|
|
|
BINARY_VERSION_FILE="../binary-version.json"
|
|
|
|
|
|
|
|
echo "$ldflags"
|
|
|
|
|
2021-10-28 11:18:13 +00:00
|
|
|
# the build takes 2 seconds
|
2023-05-03 05:13:28 +00:00
|
|
|
GOOS=${1:-$(go env GOOS)} GOARCH=${2:-$(go env GOARCH)} CGO_ENABLED=0 go build \
|
2022-10-11 16:00:50 +00:00
|
|
|
-trimpath \
|
2021-10-28 11:18:13 +00:00
|
|
|
--installsuffix cgo \
|
2023-05-03 05:13:28 +00:00
|
|
|
--ldflags "$ldflags" \
|
|
|
|
-o "../dist/portainer" \
|
|
|
|
./cmd/portainer/
|