Skip to content

Commit

Permalink
Add debug commit info
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthb committed Jan 2, 2023
1 parent 1756f8c commit 72386a7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
ARG GO_VERSION="1.19"

FROM docker.io/library/golang:${GO_VERSION}-alpine as builder
RUN apk add --quiet --no-cache --update git
FROM docker.io/library/golang:${GO_VERSION} as builder
WORKDIR /src
COPY . .
ENV GOPRIVATE="github.com/RealImage/*"
RUN mkdir /build
RUN go build -o /build ./...

FROM gcr.io/distroless/static as bouncer
FROM gcr.io/distroless/base-debian11 as bouncer
COPY --from=builder /build/bouncer /
ENV PORT=8080
ENTRYPOINT ["/bouncer"]

FROM gcr.io/distroless/static as issuer
FROM gcr.io/distroless/base-debian11 as issuer
# uses lambda-web-adapter to run our standard HTTP app in a lambda
# https://github.com/awslabs/aws-lambda-web-adapter
# for configuration see https://github.com/awslabs/aws-lambda-web-adapter#configurations
Expand Down
4 changes: 4 additions & 0 deletions cmd/bouncer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var spec = struct {

func main() {
envconfig.MustProcess(config.Prefix, &spec)
if sha, timestamp, ok := config.GetBuildInfo(); ok {
log.Println("commit sha: ", sha)
log.Println("commit time: ", timestamp)
}
stats.MaybePushMetrics(spec.MetricsPushUrl, spec.MetricsPushInterval)
go serveMetrics(spec.MetricsHost, spec.MetricsPort)

Expand Down
4 changes: 4 additions & 0 deletions cmd/issuer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var spec = struct {

func main() {
envconfig.MustProcess(config.Prefix, &spec)
if sha, timestamp, ok := config.GetBuildInfo(); ok {
log.Println("commit sha: ", sha)
log.Println("commit time: ", timestamp)
}
stats.MaybePushMetrics(spec.MetricsPushUrl, spec.MetricsPushInterval)

ctx, cancel := context.WithCancel(context.Background())
Expand Down
22 changes: 22 additions & 0 deletions internal/config/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package config

import (
"runtime/debug"
"time"
)

func GetBuildInfo() (sha string, timestamp time.Time, ok bool) {
var bi *debug.BuildInfo
bi, ok = debug.ReadBuildInfo()
for _, b := range bi.Settings {
switch b.Key {
case "vcs.revision":
sha = b.Value
case "vcs.time":
if ts, err := time.Parse(time.RFC3339, b.Value); err == nil {
timestamp = ts
}
}
}
return
}

0 comments on commit 72386a7

Please sign in to comment.