Skip to content

Commit

Permalink
Add the version to the binary
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Buil <[email protected]>
  • Loading branch information
manuelbuil committed Oct 26, 2021
1 parent 99a0a47 commit 355716c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import (
"github.com/containernetworking/cni/pkg/version"
)

var (
Version = "v1.0.0"
StringVersion = fmt.Sprintf("Flannel binary %s", Version)
)

const (
defaultSubnetFile = "/run/flannel/subnet.env"
defaultDataDir = "/var/lib/cni/flannel"
Expand Down Expand Up @@ -267,7 +272,7 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, "flannel version unknown")
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, StringVersion)
}

func cmdCheck(args *skel.CmdArgs) error {
Expand Down
16 changes: 14 additions & 2 deletions scripts/build_flannel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
set -e
cd $(dirname "$0")/..

if [ -z "$VERSION" ]; then
set +e
git describe --tags --abbrev=0 > /dev/null 2>&1
if [ "$?" != "0" ]; then
VERSION="master"
else
VERSION=$(git describe --tags --abbrev=0)
fi
set -e
fi

export GOOS="${GOOS:-linux}"
export GOARCH="${GOARCH:-amd64}"
export GOFLAGS="${GOFLAGS} -mod=vendor"
export GLDFLAGS+="-X main.Version=${VERSION:-master}"

mkdir -p "${PWD}/dist"

echo "Building flannel for ${GOOS} in ${GOARCH}"

if [ "$GOOS" == "linux" ]; then
go build -o "${PWD}/dist/flannel-${GOARCH}" "$@" .
go build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o "${PWD}/dist/flannel-${GOARCH}" "$@" .
else
go build -o "${PWD}/dist/flannel.exe" "$@" .
go build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o "${PWD}/dist/flannel.exe" "$@" .
fi

0 comments on commit 355716c

Please sign in to comment.