Skip to content

Commit

Permalink
version and commit information now are printed at the startup
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
  • Loading branch information
developer-guy authored and alexellis committed Feb 6, 2021
1 parent ea8ac8a commit d8ed3cc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-only.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
id: local_build
uses: docker/build-push-action@v2
with:
build-args: |
Version=dev
GitCommit=${{ github.sha }}
outputs: "type=docker,push=false"
platforms: linux/amd64
tags: ghcr.io/alexellis/registry-creds:${{ github.sha }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
id: local_build
uses: docker/build-push-action@v2
with:
build-args: |
Version=${{ steps.get_tag.outputs.TAG }}
GitCommit=${{ github.sha }}
outputs: "type=registry,push=true"
platforms: linux/amd64,linux/arm/v6,linux/arm64
tags: |
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG Version
ARG GitCommit

WORKDIR /workspace

Expand All @@ -18,8 +20,9 @@ COPY api/ api/
COPY controllers/ controllers/

# Build
RUN echo flags=${Version} ${GitCommit}
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
GO111MODULE=on go build -ldflags="-w -s" -a -o /usr/bin/controller
GO111MODULE=on go build -ldflags "-s -w -X main.Release=${Version} -X main.SHA=${GitCommit}" -a -o /usr/bin/controller

# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/static:nonroot
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Release 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down Expand Up @@ -36,6 +36,8 @@ import (
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Release string
SHA string
)

func init() {
Expand Down Expand Up @@ -113,7 +115,7 @@ func main() {
}
// +kubebuilder:scaffold:builder

setupLog.Info("starting manager")
setupLog.Info("starting manager with the version %s and commit %s", Release, SHA)
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
Expand Down

0 comments on commit d8ed3cc

Please sign in to comment.