Skip to content

Commit

Permalink
Make targets to build os binaries in docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
everesio committed Mar 30, 2020
1 parent 9b50945 commit 6c51971
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/spring-config-decryptor
/spring-config-decryptor*
/bin
/dist
/target
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13 as builder
FROM golang:1.14 as builder

ARG MAKE_TARGET="test build"

Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.14 as builder

ARG GOOS=linux
ARG GOARCH=amd64

WORKDIR "/code"
ADD . "/code"
RUN make BINARY=spring-config-decryptor os.build
RUN cp /code/spring-config-decryptor /spring-config-decryptor
33 changes: 32 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ BINARY ?= spring-config-decryptor
VERSION ?= $(shell git describe --tags --always --dirty)
LDFLAGS ?= -w -s

GOARCH ?= amd64
GOOS ?= linux

IMAGE ?= spring-config-decryptor
TAG ?= latest
CLOUD_IMAGE ?= grepplabs/spring-config-decryptor:$(TAG)

ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

OS_IMAGE ?= local/$(GOOS)-$(GOARCH)/$(BINARY)
OS_BIN ?= $(BINARY)-$(GOOS)-$(GOARCH)

default: build

test:
Expand All @@ -23,11 +29,15 @@ test:
build:
CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -o $(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .

.PHONY: os.build
os.build:
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -o $(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .

fmt:
go fmt ./...

clean:
@rm -rf $(BINARY)
@rm -rf $(BINARY)*

.PHONY: deps
deps:
Expand All @@ -50,6 +60,27 @@ docker.push: docker.build
docker tag $(IMAGE) $(CLOUD_IMAGE)
docker push $(CLOUD_IMAGE)

.PHONY: os.bin
os.bin:
docker build -t $(OS_IMAGE) --build-arg GOOS=$(GOOS) --build-arg GOARCH=$(GOARCH) -f Dockerfile.build .
$(eval BUILDCONTAINER=$(shell sh -c "docker create $(OS_IMAGE)"))
$(shell docker cp $(BUILDCONTAINER):/spring-config-decryptor ./$(OS_BIN))
$(eval RESULT=$(shell sh -c "docker rm $(BUILDCONTAINER)"))
$(eval RESULT=$(shell sh -c "docker rmi $(OS_IMAGE)"))
@echo "Binary copied to local directory"

.PHONY: build.linux
build.linux: clean
make GOOS=linux OS_BIN=$(BINARY) os.bin

.PHONY: build.darwin
build.darwin: clean
make GOOS=darwin OS_BIN=$(BINARY) os.bin

.PHONY: build.windows
build.windows: clean
make GOOS=windows OS_BIN=$(BINARY).exe os.bin

tag:
git tag $(TAG)

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ The secret values are base64 encoded and start with `{cipher}` prefix.
## Building

make clean build

## Build in docker

Linux

make build.linux

MacOS

make build.darwin

Windows

make build.windows


## Usage

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/grepplabs/spring-config-decryptor

go 1.13
go 1.14

require golang.org/x/crypto v0.0.0-20200109152110-61a87790db17
require golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200109152110-61a87790db17 h1:nVJ3guKA9qdkEQ3TUdXI9QSINo2CUPM/cySEvw2w8I0=
golang.org/x/crypto v0.0.0-20200109152110-61a87790db17/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# golang.org/x/crypto v0.0.0-20200109152110-61a87790db17
# golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
## explicit
golang.org/x/crypto/pbkdf2

0 comments on commit 6c51971

Please sign in to comment.