From 49339797df71949a942a542c8a8d1a8080400254 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 10:53:40 +0000 Subject: [PATCH 01/10] use LDFLAGS instead of GOFLAGS --- masher/mash.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/masher/mash.sh b/masher/mash.sh index 80ab2b4..c976815 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -180,9 +180,9 @@ fi PROJECT="${PWD##*/}" if [[ -n $BUILDSTAMP ]]; then DEPS=$( go list -f "{{.Deps}}" | grep -c -e "\" ) - GOFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" + LDFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" if [[ $DEPS -ne 0 ]]; then - GOFLAGS="$GOFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP" + LDFLAGS="$LDFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP" fi fi @@ -196,7 +196,7 @@ if [[ $LINUX == "true" ]]; then OUT="bin/linux.x86_64" echo Compiling ${OUT}/${PROJECT} [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=linux GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${GOFLAGS}" || exit 1 + GOOS=linux GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${LDFLAGS}" || exit 1 [[ "$DEB" != "false" ]] && DEB="true" fi @@ -205,14 +205,14 @@ if [[ $DARWIN == "true" ]]; then OUT="bin/darwin.x86_64" echo Compiling ${OUT}/${PROJECT} [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=darwin GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${GOFLAGS}" || exit 1 + GOOS=darwin GOARCH=amd64 go build -o "${OUT}/${PROJECT}" "${LDFLAGS}" || exit 1 fi if [[ $WINDOWS == "true" ]]; then OUT="bin/windows.x86_64" echo Compiling ${OUT}/${PROJECT}.exe [ -d "$OUT" ] || mkdir -p $OUT || exit 1 - GOOS=windows GOARCH=amd64 go build -o "${OUT}/${PROJECT}.exe" "${GOFLAGS}" || exit 1 + GOOS=windows GOARCH=amd64 go build -o "${OUT}/${PROJECT}.exe" "${LDFLAGS}" || exit 1 fi if [[ ( $DEB == "true" ) && ( -r debian/control ) && ( -x bin/linux.x86_64/${PROJECT} ) ]]; then From 4b96df1c68e273cedadc3bb8405f7e304969b159 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 10:55:01 +0000 Subject: [PATCH 02/10] support vendoring --- masher/mash.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/masher/mash.sh b/masher/mash.sh index c976815..5dbd995 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -68,6 +68,11 @@ while [[ "$#" -gt 0 ]]; do shift done +if [[ -d ./vendor ]]; then + export GOFLAGS="-mod=vendor" + VENDOR="true" +fi + if [[ $ESCAPE == "true" ]]; then exec /bin/bash "$@" exit 1 @@ -162,7 +167,7 @@ if [[ $NOCOMPILE != "true" ]]; then fi dep ensure $DEP_UP - else + elif [[ $VENDOR != "true" ]]; then go get -v -d || exit 1 fi fi From 75a046fb9113a5e63d4f2d0ef31444495b03c0b0 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 10:55:49 +0000 Subject: [PATCH 03/10] support GOPRIVATE passed in --- masher/mash.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/masher/mash.sh b/masher/mash.sh index 5dbd995..8deb059 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -14,6 +14,9 @@ while [[ "$#" -gt 0 ]]; do --id=*) ID="$val" ;; + --private=*) + export GOPRIVATE="$val" + ;; --linux) LINUX="true" From 46c15f54f61b26de31014ff2a546519b07942b4e Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 10:58:33 +0000 Subject: [PATCH 04/10] support GOPRIVATE passthrough --- masher/masher | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/masher/masher b/masher/masher index 212b4f5..82193f0 100755 --- a/masher/masher +++ b/masher/masher @@ -143,6 +143,8 @@ while [[ $# -gt 0 ]]; do shift done +[[ -n "${GOPRIVATE}" ]] && PRIVATE="--private=${GOPRIVATE}" + if [[ -n ${PROD} ]]; then LINUXFLAG="--linux" DARWINFLAG="--darwin" @@ -246,11 +248,12 @@ echo "PRJPATH='$PRJPATH'" echo "PROJECT='$PROJECT'" echo "BRANCH='$BRANCH'" echo "HASHID='$HASHID'" +[[ -n "$PRIVATE" ]] && echo "PRIVATE='$PRIVATE'" TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S") echo Using image: $IMAGE -echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE --timestamp=$TIMESTAMP --id=$HASHID $@ +echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE --timestamp=$TIMESTAMP --id=$HASHID $@ DOCKER_VERSION="$(docker --version)" DOCKER_VERSION=${DOCKER_VERSION%%,*} @@ -348,7 +351,7 @@ ${EXEC} docker run ${FLAGS} --rm \ $LIBS \ --workdir "${SRCROOT}/${PRJPATH}" \ ${IMAGE} \ - /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 + /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 if [[ $PROD == "true" ]]; then make push || exit 1 From 4a8de95d5e44db696013b13e19fba142a22d9060 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:00:13 +0000 Subject: [PATCH 05/10] need a sumdb store --- masher/masher | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/masher/masher b/masher/masher index 82193f0..33cc768 100755 --- a/masher/masher +++ b/masher/masher @@ -287,8 +287,9 @@ LIBS="" [[ -d "${BASE}/.mash/cache" ]] || mkdir -p "${BASE}/.mash/cache" CACHE="--cache=${SRCROOT}/.mash/cache" -# vgo +# go modules [[ -d "${BASE}/.mash/mod" ]] || mkdir -p "${BASE}/.mash/mod" +[[ -d "${BASE}/.mash/sumdb" ]] || mkdir -p "${BASE}/.mash/sumdb" # godep stuff DEP_CACHE="" @@ -347,6 +348,7 @@ ${EXEC} docker run ${FLAGS} --rm \ --user "${RUNAS}" \ --volume "${BASE}:${SRCROOT}:rw" \ --volume "${BASE}/.mash/mod:/go/pkg/mod:rw" \ + --volume "${BASE}/.mash/sumdb:/go/pkg/sumdb:rw" \ $DEP_CACHE \ $LIBS \ --workdir "${SRCROOT}/${PRJPATH}" \ From 84b352b56f73b3226c892aa2c1a1f3b24f50607f Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:04:47 +0000 Subject: [PATCH 06/10] better reporting of private value --- masher/masher | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/masher/masher b/masher/masher index 33cc768..19e2917 100755 --- a/masher/masher +++ b/masher/masher @@ -143,8 +143,6 @@ while [[ $# -gt 0 ]]; do shift done -[[ -n "${GOPRIVATE}" ]] && PRIVATE="--private=${GOPRIVATE}" - if [[ -n ${PROD} ]]; then LINUXFLAG="--linux" DARWINFLAG="--darwin" @@ -248,7 +246,10 @@ echo "PRJPATH='$PRJPATH'" echo "PROJECT='$PROJECT'" echo "BRANCH='$BRANCH'" echo "HASHID='$HASHID'" -[[ -n "$PRIVATE" ]] && echo "PRIVATE='$PRIVATE'" +if [[ -n "$GOPRIVATE" ]]; then + echo "PRIVATE='$GOPRIVATE'" + PRIVATE="--private=$GOPRIVATE" +fi TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S") From 939690964cec041ba1bbb9a6c4a289c9083687d6 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:09:32 +0000 Subject: [PATCH 07/10] if vendor already exists do not attempt to repopulate at all --- masher/mash.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/masher/mash.sh b/masher/mash.sh index 8deb059..95c70a9 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -161,7 +161,7 @@ if [[ $PACKAGE != "main" ]]; then exit 0 fi -if [[ $NOCOMPILE != "true" ]]; then +if [[ $VENDOR != "true" && $NOCOMPILE != "true" ]]; then echo getting dependencies... if [[ -r Gopkg.toml ]]; then DEP_UP="" @@ -170,7 +170,7 @@ if [[ $NOCOMPILE != "true" ]]; then fi dep ensure $DEP_UP - elif [[ $VENDOR != "true" ]]; then + else go get -v -d || exit 1 fi fi From 34b7400055932f037dbbd21449435485965110bd Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:22:46 +0000 Subject: [PATCH 08/10] allow --buildver version injection --- masher/mash.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/masher/mash.sh b/masher/mash.sh index 95c70a9..0129c24 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -8,6 +8,9 @@ while [[ "$#" -gt 0 ]]; do --cache=*) export GOCACHE="$val" ;; + --buildver=*) + VERSION="$val" + ;; --timestamp=*) TIMESTAMP="$val" ;; @@ -189,6 +192,9 @@ PROJECT="${PWD##*/}" if [[ -n $BUILDSTAMP ]]; then DEPS=$( go list -f "{{.Deps}}" | grep -c -e "\" ) LDFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" + if [[ $VERSION != "" ]]; then + LDFLAGS="$LDFLAGS -X main.Version=$VERSION" + fi if [[ $DEPS -ne 0 ]]; then LDFLAGS="$LDFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP" fi From 09c11e2f243e1c619b62812f1f48fa854e4724f9 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:25:19 +0000 Subject: [PATCH 09/10] add version detection from git tags --- masher/masher | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/masher/masher b/masher/masher index 19e2917..77f83d1 100755 --- a/masher/masher +++ b/masher/masher @@ -169,6 +169,7 @@ if [[ $? -eq 0 ]]; then HASHID=$(git rev-parse --short HEAD) HEAD=$(git symbolic-ref HEAD 2>> /dev/null || git rev-parse HEAD) BRANCH=$(basename ${HEAD}) + BUILD_VERSION=$(git describe --tag --abbrev=2 2> /dev/null) ;; esac else @@ -246,6 +247,10 @@ echo "PRJPATH='$PRJPATH'" echo "PROJECT='$PROJECT'" echo "BRANCH='$BRANCH'" echo "HASHID='$HASHID'" +if [[ -n "$BUILD_VERSION" ]]; then + echo "BUILD_VERSION='$BUILD_VERSION'" + BUILD_VERSION="--buildver=$BUILD_VERSION" +fi if [[ -n "$GOPRIVATE" ]]; then echo "PRIVATE='$GOPRIVATE'" PRIVATE="--private=$GOPRIVATE" @@ -254,7 +259,7 @@ fi TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S") echo Using image: $IMAGE -echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE --timestamp=$TIMESTAMP --id=$HASHID $@ +echo /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE $BUILD_VERSION --timestamp=$TIMESTAMP --id=$HASHID $@ DOCKER_VERSION="$(docker --version)" DOCKER_VERSION=${DOCKER_VERSION%%,*} @@ -354,7 +359,7 @@ ${EXEC} docker run ${FLAGS} --rm \ $LIBS \ --workdir "${SRCROOT}/${PRJPATH}" \ ${IMAGE} \ - /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 + /bin/mash.sh $ESCAPE $DARWIN $LINUX $WINDOWS $TEST $PROTO $BUILD $CACHE $PRIVATE $BUILD_VERSION --timestamp=$TIMESTAMP --id=$HASHID "$@" || exit 1 if [[ $PROD == "true" ]]; then make push || exit 1 From 2d44a0a571824aac5354e2254b052ac7028b13d5 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Thu, 26 Sep 2019 11:26:47 +0000 Subject: [PATCH 10/10] rename BUILDVER from VERSION --- masher/mash.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/masher/mash.sh b/masher/mash.sh index 0129c24..f9622ec 100755 --- a/masher/mash.sh +++ b/masher/mash.sh @@ -9,7 +9,7 @@ while [[ "$#" -gt 0 ]]; do export GOCACHE="$val" ;; --buildver=*) - VERSION="$val" + BUILDVER="$val" ;; --timestamp=*) TIMESTAMP="$val" @@ -192,8 +192,8 @@ PROJECT="${PWD##*/}" if [[ -n $BUILDSTAMP ]]; then DEPS=$( go list -f "{{.Deps}}" | grep -c -e "\" ) LDFLAGS="-ldflags=-X main.VersionBuild=$BUILDSTAMP -X main.Buildstamp=$BUILDSTAMP" - if [[ $VERSION != "" ]]; then - LDFLAGS="$LDFLAGS -X main.Version=$VERSION" + if [[ $BUILDVER != "" ]]; then + LDFLAGS="$LDFLAGS -X main.Version=$BUILDVER" fi if [[ $DEPS -ne 0 ]]; then LDFLAGS="$LDFLAGS -X github.com/puellanivis/breton/lib/util.BUILD=$BUILDSTAMP"