-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
131 lines (102 loc) · 4.43 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
GOCMD =go
GOBUILD =$(GOCMD) build
GOCLEAN =$(GOCMD) clean
GOTEST =$(GOCMD) test
GOGET =$(GOCMD) get
BINARY_NAME =hellogo
BINARY_UNIX =$(BINARY_NAME)_unix
GOPKGS =$(shell go list ./... | grep -v /vendor/)
# https://blog.schlomo.schapiro.org/2017/08/meaningful-versions-with-continuous.html
VERSION ?=$(shell git describe --tags --always --dirty)-$(shell /bin/date "+%Y%m%d%H%M%S")
DOCKERFILE ?= Dockerfile
DOCKERFILEBUILDER ?= DockerfileBuilder
DOCKERFILEMIN ?= DockerfileMin
DOCKERFILEALPINE ?= DockerfileAlpine
DOCKERFILE_FOLDER ?= .
DOCKER_BASE_IMAGE =lotharschulz/hellogo
DOCKER_IMAGE =$(DOCKER_BASE_IMAGE):$(VERSION)
DOCKER_CACHE_IMAGE =$(DOCKER_BASE_IMAGE):latest
# all tests and build
all: test build
#build
build:
$(GOBUILD) -o $(BINARY_NAME) -v
#build static linked binary
build-min:
CGO_ENABLED=0 GOOS=linux $(GOBUILD) -a -installsuffix cgo -ldflags '-w -extldflags "-static"' -o $(BINARY_NAME) .
# test
test:
$(GOTEST) -v ./...
# lint and vet (vet in verbose mode)
check:
golint $(GOPKGS)
go vet -v $(GOPKGS)
# clean
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
# run
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
# depencies
deps:
$(GOGET) github.com/markbates/goth
$(GOGET) github.com/markbates/pop
# Display size of dependencies.
size:
@gopherjs build ./*.go -m -o /tmp/out.js
@du -h /tmp/out.js
@gopher-count /tmp/out.js | sort -nr
# builds the docker image, depends on build
build.docker: build
docker build --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILE) $(DOCKERFILE_FOLDER)
# builds the docker image with cache, depends on build
build.docker-cache: build
docker build --cache-from golang:1.12 -t $(DOCKER_IMAGE) -f $(DOCKERFILE) $(DOCKERFILE_FOLDER)
# builder ###########
# builds the docker builder image, depends on build
build.dockerbuilder: build
docker build --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEBUILDER) $(DOCKERFILE_FOLDER)
# builds the docker builder image with cache, depends on build
build.dockerbuilder-cache: build
docker build --cache-from golang:1.12 --cache-from alpine:latest -t $(DOCKER_IMAGE) -f $(DOCKERFILEBUILDER) $(DOCKERFILE_FOLDER)
# builds the docker builder image without cache, depends on build
build.dockerbuilder-nocache: build
docker build --no-cache --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEBUILDER) $(DOCKERFILE_FOLDER)
# builds the docker builder image and sqashes it, depends on build
build.dockerbuilder-squash: build
docker build --squash --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEBUILDER) $(DOCKERFILE_FOLDER)
# builds the docker builder image and sqashes it, depends on build
build.dockerbuilder-compress: build
docker build --compress --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEBUILDER) $(DOCKERFILE_FOLDER)
# alpine ###########
# builds the docker alpine image, depends on build
build.dockeralpine: build
docker build --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEALPINE) $(DOCKERFILE_FOLDER)
# builds the docker alpine image with cache, depends on build
build.dockeralpine-cache: build
docker build --cache-from alpine:latest -t $(DOCKER_IMAGE) -f $(DOCKERFILEALPINE) $(DOCKERFILE_FOLDER)
# builds the docker alpine image without cache, depends on build
build.dockeralpine-nocache: build
docker build --no-cache --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEALPINE) $(DOCKERFILE_FOLDER)
# builds the docker alpine image and sqashes it, depends on build
build.dockeralpine-squash: build
docker build --squash --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEALPINE) $(DOCKERFILE_FOLDER)
# builds the docker alpine image and sqashes it, depends on build
build.dockeralpine-compress: build
docker build --compress --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEALPINE) $(DOCKERFILE_FOLDER)
# min ###########
# builds the docker minimal image, depends on build
build.docker-min: build-min
docker build --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEMIN) $(DOCKERFILE_FOLDER)
# builds the docker minimal image without cache, depends on build
build.docker-min-nocache: build-min
docker build --no-cache --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEMIN) $(DOCKERFILE_FOLDER)
# builds the docker minimal image and sqashes it, depends on build
build.docker-min-squash: build-min
docker build --squash --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEMIN) $(DOCKERFILE_FOLDER)
# builds the docker minimal image and compresses it, depends on build
build.docker-min-compress: build-min
docker build --compress --rm -t $(DOCKER_IMAGE) -f $(DOCKERFILEMIN) $(DOCKERFILE_FOLDER)