Skip to content

Commit 0343b5c

Browse files
author
C1258882 Werberson Pereira da Silva
committed
add version command
1 parent 39ea9d7 commit 0343b5c

File tree

5 files changed

+126
-25
lines changed

5 files changed

+126
-25
lines changed

.dockerignore

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### VisualStudioCode template
3+
.vscode/*
4+
!.vscode/settings.json
5+
!.vscode/tasks.json
6+
!.vscode/launch.json
7+
!.vscode/extensions.json
8+
### Go template
9+
# Binaries for programs and plugins
10+
*.exe
11+
*.exe~
12+
*.dll
13+
*.so
14+
*.dylib
15+
16+
# Test binary, build with `go test -c`
17+
*.test
18+
19+
# Output of the go coverage tool, specifically when used with LiteIDE
20+
*.out
21+
### macOS template
22+
# General
23+
.DS_Store
24+
.AppleDouble
25+
.LSOverride
26+
27+
# Icon must end with two \r
28+
Icon
29+
30+
# Thumbnails
31+
._*
32+
33+
# Files that might appear in the root of a volume
34+
.DocumentRevisions-V100
35+
.fseventsd
36+
.Spotlight-V100
37+
.TemporaryItems
38+
.Trashes
39+
.VolumeIcon.icns
40+
.com.apple.timemachine.donotpresent
41+
42+
# Directories potentially created on remote AFP share
43+
.AppleDB
44+
.AppleDesktop
45+
Network Trash Folder
46+
Temporary Items
47+
.apdisk
48+
### Example user template template
49+
### Example user template
50+
51+
# IntelliJ project files
52+
.idea
53+
*.iml
54+
out
55+
gen
56+
57+
# Dcoker
58+
.dockerignore
59+
Dockerfile
60+
61+
# Environments
62+
.env
63+

Dockerfile

+14-25
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,27 @@ FROM golang:1.11-alpine as builder
33

44
RUN apk add --no-cache git mercurial
55

6-
ENV BUILD_PATH=$GOPATH/src/github.com/labbsr0x/bindman-dns-bind9/src
6+
ENV p $GOPATH/src/github.com/labbsr0x/bindman-dns-bind9
77

8-
RUN mkdir -p ${BUILD_PATH}
9-
WORKDIR ${BUILD_PATH}
10-
11-
ADD ./src ./
8+
ADD ./ ${p}
9+
WORKDIR ${p}
1210
RUN go get -v ./...
1311

14-
WORKDIR ${BUILD_PATH}/cmd
15-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o /manager .
12+
RUN GIT_COMMIT=$(git rev-parse --short HEAD 2> /dev/null || true) \
13+
&& BUILDTIME=$(TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ') \
14+
&& VERSION=$(git describe --abbrev=0 --tags 2> /dev/null || true) \
15+
&& CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w \
16+
-X github.com/labbsr0x/bindman-dns-bind9/src/version.Version=${VERSION:-unknow-version} \
17+
-X github.com/labbsr0x/bindman-dns-bind9/src/version.GitCommit=${GIT_COMMIT} \
18+
-X github.com/labbsr0x/bindman-dns-bind9/src/version.BuildTime=${BUILDTIME}" \
19+
-a -installsuffix cgo -o /bindman-dns-manager src/main.go
1620

1721
# PKG
18-
FROM alpine:latest
19-
20-
RUN apk add --no-cache --update \
21-
curl \
22-
wget \
23-
nmap \
24-
bind-tools
25-
26-
COPY --from=builder /manager /
22+
FROM scratch
2723

2824
VOLUME [ "/data" ]
25+
COPY --from=builder /bindman-dns-manager /go/bin/
2926

30-
EXPOSE 7070
31-
32-
ENV BINDMAN_NAMESERVER_ADDRESS ""
33-
ENV BINDMAN_NAMESERVER_PORT ""
34-
ENV BINDMAN_NAMESERVER_KEYFILE ""
35-
ENV BINDMAN_NAMESERVER_ZONE ""
36-
ENV BINDMAN_MODE ""
37-
38-
ENTRYPOINT [ "./manager" ]
27+
ENTRYPOINT [ "/go/bin/bindman-dns-manager" ]
3928

4029
CMD [ "serve" ]

src/cmd/serve.go

+8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"fmt"
55
"github.com/labbsr0x/bindman-dns-bind9/src/manager"
66
"github.com/labbsr0x/bindman-dns-bind9/src/nsupdate"
7+
"github.com/labbsr0x/bindman-dns-bind9/src/version"
78
"github.com/labbsr0x/bindman-dns-webhook/src/hook"
9+
"github.com/sirupsen/logrus"
810
"github.com/spf13/cobra"
911
"github.com/spf13/viper"
1012
)
@@ -29,6 +31,12 @@ func runE(_ *cobra.Command, _ []string) error {
2931
if err != nil {
3032
return err
3133
}
34+
35+
logrus.New().WithFields(logrus.Fields{
36+
"Version": version.Version,
37+
"GitCommit": version.GitCommit,
38+
"BuildTime": version.BuildTime,
39+
}).Info("Bindman-DNS Bind9 version")
3240
hook.Initialize(bind9Manager)
3341
return nil
3442
}

src/cmd/version.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/labbsr0x/bindman-dns-bind9/src/version"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// versionCmd represents the version command
10+
var versionCmd = &cobra.Command{
11+
Use: "version",
12+
Short: "Display this build's version, build time, and git hash",
13+
Run: func(cmd *cobra.Command, args []string) {
14+
fmt.Print(version.FormattedMessage())
15+
},
16+
}
17+
18+
func init() {
19+
rootCmd.AddCommand(versionCmd)
20+
}

src/version/version.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package version
2+
3+
import "fmt"
4+
5+
// Default build-time variable.
6+
// These values are overridden via ldflags
7+
var (
8+
Version = "unknown-version"
9+
GitCommit = "unknown-commit"
10+
BuildTime = "unknown-buildtime"
11+
)
12+
13+
const versionF = `Bindman-DNS Bind9
14+
Version: %s
15+
GitCommit: %s
16+
BuildTime: %s
17+
`
18+
19+
func FormattedMessage() string {
20+
return fmt.Sprintf(versionF, Version, GitCommit, BuildTime)
21+
}

0 commit comments

Comments
 (0)