Skip to content

Commit

Permalink
Update Theatre go ldflags
Browse files Browse the repository at this point in the history
It seems that we created v3, these settings aren't working. It's very
clear since the last release that I added a metric that shows this in
Prometheus.

This are the required changes to fix this:

- In Dockefile, override two variables: VERSION and GIT_REVISION. The
  last one is a build argument that is injected on build time.

- Fixed the path in the go package by adding the version, and update
  these references in goreleaser and the Makefile
  • Loading branch information
rnaveiras committed Jun 19, 2023
1 parent 2589933 commit 5ca8e5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ builds:
- goos: linux
goarch: arm64
ldflags: >
-X github.com/gocardless/theatre/cmd.Version={{.Version}}
-X github.com/gocardless/theatre/cmd.Commit={{.Commit}}
-X github.com/gocardless/theatre/cmd.Date={{.Date}}
-X github.com/gocardless/theatre/v3/cmd.Version={{.Version}}
-X github.com/gocardless/theatre/v3/cmd.Commit={{.Commit}}
-X github.com/gocardless/theatre/v3/cmd.Date={{.Date}}
-a
-installsuffix cgo
env:
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ FROM golang:1.20.5 as builder
WORKDIR /go/src/github.com/gocardless/theatre

COPY . /go/src/github.com/gocardless/theatre
ARG git_revision=unset
RUN echo $git_revision > REVISION
RUN set -x \
&& make VERSION="$(cat VERSION)" build
&& make VERSION="$(cat VERSION)" GIT_REVISION="$(cat REVISION)" build

# Use ubuntu as our base package to enable generic system tools
FROM ubuntu:jammy-20230522
Expand All @@ -20,4 +22,6 @@ RUN set -x \

WORKDIR /
COPY --from=builder /go/src/github.com/gocardless/theatre/bin/* /usr/local/bin/
ARG git_revision=unset
RUN echo $git_revision > REVISION
ENTRYPOINT ["/bin/bash"]
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
PROG=bin/rbac-manager bin/vault-manager bin/theatre-secrets bin/workloads-manager bin/theatre-consoles
PROJECT=github.com/gocardless/theatre
IMAGE=eu.gcr.io/gc-containers/gocardless/theatre
VERSION=$(shell git rev-parse --short HEAD)-dev
BUILD_COMMAND=go build -ldflags "-s -w -X main.Version=$(VERSION)"
VERSION=$(shell git describe --tags --dirty --long)
GIT_REVISION=$(shell git rev-parse HEAD)
DATE=$(shell date +"%Y%m%d.%H%M%S")
LDFLAGS=-ldflags "-s -X github.com/gocardless/theatre/v3/cmd.Version=$(VERSION) -X github.com/gocardless/theatre/v3/cmd.Commit=$(GIT_REVISION) -X github.com/gocardless/theatre/v3/cmd.Date=$(DATE)"
BUILD_COMMAND=go build $(LDFLAGS)

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down

0 comments on commit 5ca8e5d

Please sign in to comment.