From a505c9b25105d9d5584ca5679c55bf87b551b7ab Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 14 Nov 2019 16:32:03 +0700 Subject: [PATCH 1/3] make build-release.sh works on Mac OSX --- Dockerfile | 2 +- build-release.sh | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7ed9cc237b4..a6220f8cf72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.13-alpine as builder WORKDIR $GOPATH/src/github.com/loadimpact/k6 ADD . . RUN apk --no-cache add git -RUN CGO_ENABLED=0 go install -a -ldflags "-s -w -X github.com/loadimpact/k6/lib/consts.VersionDetails=$(date --utc -Is)/$(git describe --always --long --dirty)" +RUN CGO_ENABLED=0 go install -a -ldflags "-s -w -X github.com/loadimpact/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" FROM alpine:3.10 RUN apk add --no-cache ca-certificates diff --git a/build-release.sh b/build-release.sh index 40e91c87efb..e7589165762 100755 --- a/build-release.sh +++ b/build-release.sh @@ -8,7 +8,7 @@ eval "$(go env)" VERSION=${1:-$(git describe --tags --always --dirty)} # To overwrite the version details, pass something as the second arg. Empty string disables it. -VERSION_DETAILS=${2-"$(date --utc --iso-8601=s)/$(git describe --always --long --dirty)"} +VERSION_DETAILS=${2-"$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"} make_archive() { local FMT="$1" DIR="$2" @@ -39,6 +39,7 @@ build_dist() { # Clean out any old remnants of failed builds. rm -rf "dist/$DIR" mkdir -p "dist/$DIR" + trap "rm -rf \"dist/$DIR\"" INT TERM # Subshell to not mess with the current env vars or CWD ( @@ -60,16 +61,16 @@ checksum() { local CHECKSUM_FILE="k6-${VERSION}-checksums.txt" if command -v sha256sum > /dev/null; then - CHECKSUM_CMD="sha256sum" + CHECKSUM_CMD=("sha256sum") elif command -v shasum > /dev/null; then - CHECKSUM_CMD="shasum -a 256" + CHECKSUM_CMD=("shasum" "-a" "256") else echo "ERROR: unable to find a command to compute sha-256 hash" return 1 fi rm -f "dist/$CHECKSUM_FILE" - ( cd dist && for x in *; do "$CHECKSUM_CMD" "$x" >> "$CHECKSUM_FILE"; done ) + ( cd dist && for x in *; do "${CHECKSUM_CMD[@]}" -- "$x" >> "$CHECKSUM_FILE"; done ) } echo "--- Building Release: ${VERSION}" From 3fb745acdbb9a793d33cba3a9a793b4e0107b867 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 14 Nov 2019 22:36:37 +0700 Subject: [PATCH 2/3] build-release.sh: only checksum files --- build-release.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build-release.sh b/build-release.sh index e7589165762..8de91966c3a 100755 --- a/build-release.sh +++ b/build-release.sh @@ -39,7 +39,6 @@ build_dist() { # Clean out any old remnants of failed builds. rm -rf "dist/$DIR" mkdir -p "dist/$DIR" - trap "rm -rf \"dist/$DIR\"" INT TERM # Subshell to not mess with the current env vars or CWD ( @@ -70,7 +69,7 @@ checksum() { fi rm -f "dist/$CHECKSUM_FILE" - ( cd dist && for x in *; do "${CHECKSUM_CMD[@]}" -- "$x" >> "$CHECKSUM_FILE"; done ) + ( cd dist && for x in *; do [ -f "$x" ] && "${CHECKSUM_CMD[@]}" -- "$x" >> "$CHECKSUM_FILE"; done ) } echo "--- Building Release: ${VERSION}" From 83a5337ce98387de70128d92b06f426680673da2 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 14 Nov 2019 22:40:57 +0700 Subject: [PATCH 3/3] build binary with -trimpath --- .circleci/config.yml | 2 +- Dockerfile | 2 +- appveyor.yml | 2 +- build-release.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 49e9a8a1c81..06d09c9f706 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -139,7 +139,7 @@ jobs: cd $GOPATH/src/github.com/loadimpact/k6 echo "Building k6..." - CGO_ENABLED=0 GOARCH=$ARCH go build -a -ldflags '-s -w' -o /tmp/k6 + CGO_ENABLED=0 GOARCH=$ARCH go build -a -trimpath -ldflags '-s -w' -o /tmp/k6 echo "Done!" VERSION=${CIRCLE_TAG:1} ./packaging/gen-packages.sh diff --git a/Dockerfile b/Dockerfile index a6220f8cf72..852b7e59786 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.13-alpine as builder WORKDIR $GOPATH/src/github.com/loadimpact/k6 ADD . . RUN apk --no-cache add git -RUN CGO_ENABLED=0 go install -a -ldflags "-s -w -X github.com/loadimpact/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" +RUN CGO_ENABLED=0 go install -a -trimpath -ldflags "-s -w -X github.com/loadimpact/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" FROM alpine:3.10 RUN apk add --no-cache ca-certificates diff --git a/appveyor.yml b/appveyor.yml index ee9835cc72d..5b1700e4718 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,7 +52,7 @@ build_script: - cd %APPVEYOR_BUILD_FOLDER% - pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md - go version - - go build -a -ldflags "-s -w" -o packaging\k6.exe + - go build -a -trimpath -ldflags "-s -w" -o packaging\k6.exe - cd %APPVEYOR_BUILD_FOLDER%\packaging - candle.exe -arch x64 -dVERSION=%VERSION% k6.wxs - light.exe -ext WixUIExtension k6.wixobj diff --git a/build-release.sh b/build-release.sh index 8de91966c3a..57f76a70340 100755 --- a/build-release.sh +++ b/build-release.sh @@ -28,7 +28,7 @@ build_dist() { local DIR="k6-${VERSION}-${ALIAS}" local BUILD_ENV=("${@:4}") - local BUILD_ARGS=(-o "dist/$DIR/k6${SUFFIX}") + local BUILD_ARGS=(-o "dist/$DIR/k6${SUFFIX}" -trimpath) if [ -n "$VERSION_DETAILS" ]; then BUILD_ARGS+=(-ldflags "-X github.com/loadimpact/k6/lib/consts.VersionDetails=$VERSION_DETAILS")