Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
improved versioning output and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Weiss committed Dec 7, 2018
1 parent 84e9e76 commit d5a1e02
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
builds:
- binary: oscalkit
main: ./cli/main.go
ldflags: -s -w -X github.com/opencontrol/oscalkit/cli/version.Version={{.Version}} -X github.com/opencontrol/oscalkit/cli/version.Commit={{.Commit}} -X github.com/opencontrol/oscalkit/cli/version.Date={{.Date}}
ldflags: -s -w -X github.com/opencontrol/oscalkit/cli/version.Version={{.Version}} -X github.com/opencontrol/oscalkit/cli/version.Build={{.ShortCommit}} -X github.com/opencontrol/oscalkit/cli/version.Date={{.Date}}
env:
- CGO_ENABLED=0
goos:
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

FROM golang:1.11-alpine AS builder
WORKDIR /go/src/github.com/opencontrol/oscalkit
ARG VERSION
ARG BUILD
ARG DATE
COPY . .
WORKDIR /go/src/github.com/opencontrol/oscalkit/cli
RUN CGO_ENABLED=0 go build -o oscalkit -v -ldflags="-s -w"
RUN CGO_ENABLED=0 go build -o oscalkit -v -ldflags "-s -w -X github.com/opencontrol/oscalkit/cli/version.Version=${VERSION} -X github.com/opencontrol/oscalkit/cli/version.Build=${BUILD} -X github.com/opencontrol/oscalkit/cli/version.Date=${DATE}"

FROM alpine:3.7
RUN apk --no-cache add ca-certificates libxml2-utils
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

GOOS ?= darwin
GOARCH ?= amd64
LDFLAGS=-ldflags "-s -w"
NAMESPACE ?= opencontrolorg
REPO ?= oscalkit
BUILD ?= dev
GOOS := darwin
GOARCH := amd64
VERSION := 0.1.0
BUILD := $(shell git rev-parse --short HEAD)-dev
DATE := $(shell date "+%Y-%m-%d")
LDFLAGS=-ldflags "-s -w -X github.com/opencontrol/oscalkit/cli/version.Version=$(VERSION) -X github.com/opencontrol/oscalkit/cli/version.Build=$(BUILD) -X github.com/opencontrol/oscalkit/cli/version.Date=$(DATE)"
NAMESPACE := opencontrolorg
REPO := oscalkit
BINARY=oscalkit_$(GOOS)_$(GOARCH)

.DEFAULT_GOAL := $(BINARY)
Expand All @@ -27,14 +29,15 @@ generate:
sh -c "go generate"

test: generate

docker container run \
-v $$PWD:/go/src/github.com/opencontrol/oscalkit \
-w /go/src/github.com/opencontrol/oscalkit \
golang:1.11 \
sh -c "go test \$$(go list ./... | grep -v /vendor/)"

build-docker:
docker image build -t $(NAMESPACE)/$(REPO):$(BUILD) .
docker image build --build-arg VERSION=$(VERSION) --build-arg BUILD=$(BUILD) --build-arg DATE=$(DATE) -t $(NAMESPACE)/$(REPO):$(VERSION)-$(BUILD) .

push: build-docker
docker image push $(NAMESPACE)/$(REPO):$(BUILD)
Expand Down
6 changes: 4 additions & 2 deletions cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (

// Execute ...
func Execute() error {
appVersion := fmt.Sprintf("%s-%s (Built: %s)\n", version.Version, version.Build, version.Date)

cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("oscal-proxy version %s, build %s, date %s\n", c.App.Version, version.Version, version.Date)
fmt.Println(appVersion)
}

app := cli.NewApp()
app.Name = "oscalkit"
app.Version = version.Version
app.Version = appVersion
app.Usage = "OSCAL toolkit"
app.Flags = []cli.Flag{
cli.BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion cli/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package version
// Build details
var (
Version string
Commit string
Build string
Date string
)

0 comments on commit d5a1e02

Please sign in to comment.