Skip to content

Commit

Permalink
Merge pull request #2 from blackskad/version-env-var
Browse files Browse the repository at this point in the history
Add a build-time app version variable
  • Loading branch information
blackskad authored Aug 19, 2024
2 parents 3646fa7 + f808e7d commit 17f2027
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# try to keep the debian version in sync with the distroless version
FROM golang:1.23-bookworm as base

ARG VERSION=development

WORKDIR /work

COPY go.mod ./
COPY go.sum ./
RUN go mod download
Expand All @@ -18,12 +22,12 @@ RUN go test -v
# Stage to build the binary
FROM base as build

RUN CGO_ENABLED=0 go build -o /go/bin/app .
RUN CGO_ENABLED=0 go build -ldflags="-X 'github.com/blackskad/go-web-scaffold/environment.Version=${VERSION}'" -o app .

# Stage with the production binary
FROM gcr.io/distroless/static-debian12 as production

COPY --from=build /go/bin/app /
COPY --from=build /work/app /

# port for pprof
EXPOSE 6060
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
quasar:
go-web-scaffold:
build:
dockerfile: Dockerfile
target: production
Expand Down
3 changes: 2 additions & 1 deletion pkg/environment/environment.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package environment

const Name = "quasar"
const Name = "go-web-scaffold"
const Version = "development"
1 change: 1 addition & 0 deletions pkg/o11y/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func initTracer(ctx context.Context) (*sdktrace.TracerProvider, error) {
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(environment.Name),
semconv.ServiceVersion(environment.Version),
),
),
}
Expand Down

0 comments on commit 17f2027

Please sign in to comment.