Build improvement closes #36

- Some cleaning on the Makefile, also specify PHONYs
- Static builds
- Use multi staged builds for the Docker image
- Remove .idea from the gitignore, it's not related to the project but on
how the user interacts with it. If one uses idea he can just create a
global gitignore to ignore that
- License had a disalignement

Signed-off-by: Lorenzo Fontana <lo@linux.com>
This commit is contained in:
Lorenzo Fontana 2017-08-20 04:46:52 +02:00
parent 35dbe63ec8
commit 23993995ad
No known key found for this signature in database
GPG Key ID: 0D48B0B074C3DC15
6 changed files with 44 additions and 37 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
bin/
.idea/

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM golang:1.8.3 as builder
RUN mkdir -p /go/src/github.com/gianarb/orbiter
ADD . /go/src/github.com/gianarb/orbiter/
WORKDIR /go/src/github.com/gianarb/orbiter
RUN make build
FROM scratch
COPY --from=builder /go/src/github.com/gianarb/orbiter/bin/orbiter /bin/orbiter
ENTRYPOINT ["orbiter"]
CMD ["orbiter", "daemon"]

View File

@ -1,11 +0,0 @@
FROM golang:1.8.3
RUN mkdir -p /go/src/github.com/gianarb/orbiter
ADD . /go/src/github.com/gianarb/orbiter/
WORKDIR /go/src/github.com/gianarb/orbiter
RUN go build -o orbiter
RUN mv ./orbiter /bin/orbiter
ENTRYPOINT ["orbiter"]
CMD ["orbiter", "daemon"]

View File

@ -1,7 +0,0 @@
FROM scratch
ADD ./bin/orbiter /bin/orbiter
ENTRYPOINT ["orbiter"]
CMD ["orbiter", "daemon"]

View File

@ -1,23 +1,35 @@
out_binary=bin/orbiter
docker_image_fqdn=docker.io/gianarb/orbiter
PACKAGES=$(shell go list ./... | grep -v /vendor/)
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))
RACE=$(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))
.PHONY: build
build: clean $(out_binary)
$(out_binary): bin
mkdir -p ./bin
CGO_ENABLED=0 GOOS=linux go build -o $(out_binary) -a -tags netgo -ldflags '-w' .
bin:
mkdir -p bin/
.PHONY: build/docker-image
docker-image:
docker build -t $(docker_image_fqdn):latest .
.PHONY: clean
help: ## this help
awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
.PHONY: ci test vet
ci: vet test
test: ## run tests, except integration tests
@go test ${RACE} ${PACKAGES}
binaries:
@echo "Compiling..."
@mkdir -p ./bin
@go build -i -o ./bin/orbiter
@CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -i -o ./bin/orbiter
@echo "All done! The binaries is in ./bin let's have fun!"
build/docker: binaries
@docker build -t gianarb/orbiter:latest .
go test ${RACE} ${PACKAGES}
vet: ## run go vet
@test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v '*composite literal uses unkeyed fields|exit status 0)' | tee /dev/stderr)"
test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v '*composite literal uses unkeyed fields|exit status 0)' | tee /dev/stderr)"
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
ci: vet test
.PHONY: clean
clean:
rm -Rf bin/