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

Build and Makefile changes #25

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# oscalkit - OSCAL conversion utility
# Written in 2017 by Andrew Weiss <andrew.weiss@docker.com>

# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain worldwide.
# This software is distributed without any warranty.

# 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/>.

FROM golang:1.11 AS race-detector
WORKDIR /go/src/github.com/opencontrol/oscalkit
COPY . .
WORKDIR /go/src/github.com/opencontrol/oscalkit/cli
RUN go build -race

FROM golang:1.11
ARG GOOS
ARG GOARCH
ARG VERSION
ARG BUILD
ARG DATE
ARG BINARY
WORKDIR /go/src/github.com/opencontrol/oscalkit
COPY --from=race-detector /go/src/github.com/opencontrol/oscalkit .
WORKDIR /go/src/github.com/opencontrol/oscalkit/cli
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /${BINARY} -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}"
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GOARCH := amd64
VERSION := 0.2.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)
Expand All @@ -29,7 +29,6 @@ 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 \
Expand All @@ -42,12 +41,20 @@ build-docker:
push: build-docker
docker image push $(NAMESPACE)/$(REPO):$(BUILD)

$(BINARY): generate
docker container run --rm \
-v $$PWD:/go/src/github.com/opencontrol/oscalkit \
-w /go/src/github.com/opencontrol/oscalkit/cli \
golang:1.11-alpine \
sh -c 'GOOS=${GOOS} GOARCH=${GOARCH} go build -v ${LDFLAGS} -o ../${BINARY}'
# Builds binary for the OS/arch. Assumes that types have already been generated
# via the "generate" target
$(BINARY):
docker image build -f Dockerfile.build \
--build-arg GOOS=$(GOOS) \
--build-arg GOARCH=$(GOARCH) \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD=$(BUILD) \
--build-arg DATE=$(DATE) \
--build-arg BINARY=$(BINARY) \
-t $(NAMESPACE)/$(REPO):$(VERSION)-$(BUILD)-builder .;
$(eval ID := $(shell docker create $(NAMESPACE)/$(REPO):$(VERSION)-$(BUILD)-builder))
@docker cp $(ID):/$(BINARY) .
@docker rm $(ID) >/dev/null

clean:
if [ -f ${BINARY} ]; then rm ${BINARY}; fi