-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (49 loc) · 1.39 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
NAME := goone
VERSION := v0.0.1
ifeq ($(COMMIT),)
COMMIT := $(shell git rev-parse HEAD)
endif
DATE := $(shell date "+%Y-%m-%dT%H:%M:%S%z")
SRCS := $(shell find . -type f -name '*.go')
LDFLAGS := -ldflags="-s -w -X \"main.version=$(VERSION)\" -X \"main.commit=$(COMMIT)\" -X \"main.date=$(DATE)\" -extldflags -static"
NOVENDOR := $(shell go list ./... | grep -v vendor)
export GO111MODULE=on
.DEFAULT_GOAL := bin/$(NAME)
bin/$(NAME): $(SRCS)
go build $(LDFLAGS) -o bin/$(NAME)
.PHONY: ci-test
ci-test:
go test -coverpkg=./... -coverprofile=coverage.txt -v ./...
.PHONY: clean
clean:
rm -rf bin/*
rm -rf dist/*
rm -rf vendor/*
.PHONY: fast
fast:
go build $(LDFLAGS) -o bin/$(NAME)
.PHONY: cross-build
cross-build:
for os in darwin linux windows; do \
for arch in amd64 386; do \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo $(LDFLAGS) -o dist/$$os-$$arch/$(NAME); \
done; \
done
dist/linux-amd64/$(NAME): cross-build
DOCKER_REPOSITORY := docker.io
ifeq ($(DOCKER_REPOSITORY),)
DOCKER_IMAGE_NAME := goone
else
DOCKER_IMAGE_NAME := $(DOCKER_REPOSITORY)/goone
endif
DOCKER_IMAGE_TAG ?= latest
DOCKER_IMAGE := $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
.PHONY: docker-build
docker-build:
docker build --build-arg COMMIT=$(COMMIT) -t $(DOCKER_IMAGE) .
.PHONY: install
install:
go install $(LDFLAGS)
.PHONY: test
test:
go test -cover -v $(NOVENDOR)