Skip to content

Commit

Permalink
feat: show application version in logs at startup (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimdre authored Aug 16, 2024
1 parent fddabbc commit d29d72f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
with:
context: .
provenance: false
args: |
APP_VERSION=${{ github.ref_name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28
FROM golang:1.23.0@sha256:613a108a4a4b1dfb6923305db791a19d088f77632317cfc3446825c54fb862cd AS build-stage

ARG APP_VERSION=dev

# Set destination for COPY
WORKDIR /app

Expand All @@ -24,7 +26,7 @@ ENV GOCACHE=/root/.cache/go-build \
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target="/root/.cache/go-build" \
--mount=type=bind,target=. \
go build -ldflags="-s -w" -o / ./...
go build -ldflags="-s -w -X main.Version=${APP_VERSION}" -o / ./...

FROM gcr.io/distroless/base-debian12@sha256:1aae189e3baecbb4044c648d356ddb75025b2ba8d14cdc9c2a19ba784c90bfb9 AS build-release-stage

Expand Down
7 changes: 5 additions & 2 deletions cmd/doco-cd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const (
healthPath = "/v1/health"
)

var errMsg string
var (
Version string
errMsg string
)

func main() {
// Set default log level to debug
Expand All @@ -38,7 +41,7 @@ func main() {
// Set the actual log level
log = logger.New(logLevel)

log.Info("starting application", slog.String("log_level", c.LogLevel))
log.Info("starting application", slog.String("version", Version), slog.String("log_level", c.LogLevel))

// Test/verify the connection to the docker socket
err = docker.VerifySocketConnection(c.DockerAPIVersion)
Expand Down
8 changes: 6 additions & 2 deletions dev.compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
services:
app:
container_name: doco-cd
build: .
build:
context: .
dockerfile: Dockerfile
args:
- APP_VERSION=dev
restart: no
ports:
- "80:80"
Expand All @@ -16,6 +20,6 @@ services:
# Use `user: root` to run the app as root, or use `group_add` to use the non-root user and add the docker group id to it
#user: root
group_add:
- "971" # change to the docker group id shown in the app error logs or in the output of `ls -l /var/run/docker.sock`
- "0" # change to the docker group id shown in the app error logs or in the output of `ls -l /var/run/docker.sock`
volumes:
- /var/run/docker.sock:/var/run/docker.sock

0 comments on commit d29d72f

Please sign in to comment.