This repository was archived by the owner on Jul 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +55
-4
lines changed Expand file tree Collapse file tree 4 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 1
1
ARG ALPINE_VERSION=3.7
2
2
ARG GO_VERSION=1.10.1
3
+ ARG COMMIT=unknown
3
4
ARG TAG=unknown
4
5
5
6
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build
@@ -10,9 +11,11 @@ WORKDIR /go/src/github.com/docker/lunchbox/
10
11
COPY . .
11
12
12
13
FROM build AS bin-build
14
+ ARG COMMIT
13
15
ARG TAG
14
- RUN make TAG=${TAG} bin-all
16
+ RUN make COMMIT=${COMMIT} TAG=${TAG} bin-all
15
17
16
18
FROM build AS test
19
+ ARG COMMIT
17
20
ARG TAG
18
- RUN make TAG=${TAG} unit-test e2e-test
21
+ RUN make COMMIT=${COMMIT} TAG=${TAG} unit-test e2e-test
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ PKG_NAME := github.com/docker/lunchbox
2
2
BIN_NAME := docker-app
3
3
4
4
TAG ?= $(shell git describe --always --dirty)
5
+ COMMIT ?= $(shell git rev-parse --short HEAD)
5
6
6
7
IMAGE_NAME := docker-app
7
8
@@ -12,9 +13,12 @@ IMAGE_BUILD_ARGS := \
12
13
--build-arg ALPINE_VERSION=$(ALPINE_VERSION ) \
13
14
--build-arg GO_VERSION=$(GO_VERSION ) \
14
15
--build-arg BIN_NAME=$(BIN_NAME ) \
16
+ --build-arg COMMIT=$(COMMIT ) \
15
17
--build-arg TAG=$(TAG )
16
18
17
- LDFLAGS := "-s -w"
19
+ LDFLAGS := "-s -w \
20
+ -X $(PKG_NAME ) /internal.GitCommit=$(COMMIT ) \
21
+ -X $(PKG_NAME ) /internal.Version=$(TAG ) "
18
22
19
23
# ####################
20
24
# Local Development #
@@ -59,7 +63,7 @@ unit-test:
59
63
go test $(shell go list ./... | grep -vE '/vendor/|/e2e')
60
64
61
65
clean :
62
- rm -Rf ./_build
66
+ rm -Rf ./_build docker-app- * .tar.gz
63
67
64
68
# #####
65
69
# CI #
Original file line number Diff line number Diff line change
1
+ package cmd
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/docker/lunchbox/internal"
7
+ "github.com/spf13/cobra"
8
+ )
9
+
10
+ var versionCmd = & cobra.Command {
11
+ Use : "version" ,
12
+ Short : "Print version information" ,
13
+ Run : func (cmd * cobra.Command , args []string ) {
14
+ fmt .Println (internal .FullVersion ())
15
+ },
16
+ }
17
+
18
+ func init () {
19
+ rootCmd .AddCommand (versionCmd )
20
+ }
Original file line number Diff line number Diff line change
1
+ package internal
2
+
3
+ import (
4
+ "fmt"
5
+ "runtime"
6
+ "strings"
7
+ )
8
+
9
+ var (
10
+ // Version is the git tag that this was built from.
11
+ Version = "unknown"
12
+ // GitCommit is the commit that this was built from.
13
+ GitCommit = "unknown"
14
+ )
15
+
16
+ // FullVersion returns a string of version information.
17
+ func FullVersion () string {
18
+ res := []string {
19
+ fmt .Sprintf ("Version: %s" , Version ),
20
+ fmt .Sprintf ("Git commit: %s" , GitCommit ),
21
+ fmt .Sprintf ("OS/Arch: %s/%s" , runtime .GOOS , runtime .GOARCH ),
22
+ }
23
+ return strings .Join (res , "\n " )
24
+ }
You can’t perform that action at this time.
0 commit comments