diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7b0d8bc..74f8a31 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 0a6c973..a1298fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 diff --git a/cmd/doco-cd/main.go b/cmd/doco-cd/main.go index f9a4c2a..a84b3a3 100644 --- a/cmd/doco-cd/main.go +++ b/cmd/doco-cd/main.go @@ -17,7 +17,10 @@ const ( healthPath = "/v1/health" ) -var errMsg string +var ( + Version string + errMsg string +) func main() { // Set default log level to debug @@ -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) diff --git a/dev.compose.yaml b/dev.compose.yaml index 6867829..a01a4ca 100644 --- a/dev.compose.yaml +++ b/dev.compose.yaml @@ -1,7 +1,11 @@ services: app: container_name: doco-cd - build: . + build: + context: . + dockerfile: Dockerfile + args: + - APP_VERSION=dev restart: no ports: - "80:80" @@ -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 \ No newline at end of file