Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
feat: add version
Browse files Browse the repository at this point in the history
  • Loading branch information
GalvinGao committed Aug 25, 2022
1 parent 6aad9f0 commit a7f25c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ RUN apk --no-cache add bash git openssh

COPY . .

ARG VERSION

# inject versioning information & build the binary
RUN export BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ"); go build -ldflags "-X cicd-scratchpad.BuildTime=$BUILD_TIME" -o cicdscratchpad .
RUN export BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ"); go build -ldflags "-X 'main.BuildTime=$BUILD_TIME' -X 'main.Version=$VERSION'" -o cicdscratchpad .

# runner
FROM base AS runner
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"os"
)

var BuildTime = "Unknown"
var (
Version = "Unknown"
BuildTime = "Unknown"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, world! Build time: " + BuildTime))
w.Write([]byte("Hello, world! This is version " + Version + " built at " + BuildTime))
})
http.ListenAndServe(os.Getenv("SCRATCHPAD_ADDRESS"), nil)
}

0 comments on commit a7f25c0

Please sign in to comment.