Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Adding build flags to inject the version and commit #173

Merged
merged 7 commits into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ RC_MUTABLE_IMAGE_NAME = $(DOCKER_REPO)$(BASE_IMAGE_NAME):canary
REL_IMAGE_NAME = $(DOCKER_REPO)$(BASE_IMAGE_NAME):$(REL_VERSION)
REL_MUTABLE_IMAGE_NAME = $(DOCKER_REPO)$(BASE_IMAGE_NAME):latest

ifeq ($(REL_VERSION),)
BROKER_VERSION="devel"
else
BROKER_VERSION=$(REL_VERSION)
endif

LDFLAGS = -w -X main.commit=$(COMMIT) -X main.commit=$(GIT_VERSION) -X main.version=$(BROKER_VERSION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-X main.commit=$(COMMIT) doesn't look right... it seems to write the same property as -X main.commit=$(GIT_VERSION), and appears to use an undefined value. Guessing this was a copy/paste error.


# Checks for the existence of a docker client and prints a nice error message
# if it isn't present
.PHONY: check-docker
Expand Down Expand Up @@ -167,7 +175,7 @@ stop-test-redis: check-docker-compose
.PHONY: build
build: check-docker-compose
docker-compose run --rm dev \
go build -o ${BINARY_DIR}/${BINARY_NAME} ./cmd/broker
go build -o ${BINARY_DIR}/${BINARY_NAME} -ldflags '$(LDFLAGS)' ./cmd/broker

# (Re)Build the Docker image for the osba and run it
.PHONY: run
Expand Down Expand Up @@ -229,16 +237,19 @@ CLI_BINARY_NAME := broker-cli
build-mac-broker-cli: check-docker-compose
docker-compose run --rm -e GOOS=darwin -e GOARCH=amd64 dev \
go build -o ${CONTRIB_BINARY_DIR}/${CLI_BINARY_NAME} \
-ldflags '$(LDFLAGS)' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to set this on the CLI builds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still think we don't need these flags here.

Copy link
Contributor Author

@arschles arschles Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the CLI is not supposed to be a first-class citizen, it couldn't hurt, right? I could add a version command to the CLI also, if you're ok with keeping the version in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with it. Should this PR include the necessary modification to contrib/cmd/cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating what @krancour and I talked about offline: I am going to remove this and submit a low-priority issue to:

  • Add the flag back
  • Implement the version command

./contrib/cmd/cli

.PHONY: build-linux-broker-cli
build-linux-broker-cli: check-docker-compose
docker-compose run --rm -e GOOS=linux -e GOARCH=amd64 dev \
go build -o ${CONTRIB_BINARY_DIR}/${CLI_BINARY_NAME} \
-ldflags '$(LDFLAGS)' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need these flags here.

./contrib/cmd/cli

.PHONY: build-win-broker-cli
build-win-broker-cli: check-docker-compose
docker-compose run --rm -e GOOS=windows -e GOARCH=amd64 dev \
go build -o ${CONTRIB_BINARY_DIR}/${CLI_BINARY_NAME} \
-ldflags '$(LDFLAGS)' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need these flags here.

./contrib/cmd/cli
5 changes: 5 additions & 0 deletions cmd/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/go-redis/redis"
)

var (
version string
commit string
)

func init() {
// Initialize logging
// Split log output across stdout and stderr, depending on severity
Expand Down