-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
69 lines (58 loc) · 1.53 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
# prevent run if docker not found
ifeq (, $(shell which docker))
$(error "Binary docker not found in $(PATH)")
endif
override APP_NAME=slack-duty-bot
override MOD_NAME=github.com/insidieux/${APP_NAME}
override GO_VERSION=1.13
override CGO_ENABLED=0
# build go binary variables
GOOS?=$(shell go env GOOS || echo linux)
GOARCH?=$(shell go env GOARCH || echo amd64)
# docker build variables
DOCKER_NAMESPACE?=
DOCKER_IMAGE=${DOCKER_NAMESPACE}/${APP_NAME}
DOCKER_TAG?=1.0.0
DOCKER_USER?=
DOCKER_PASSWORD?=
all: build
init:
docker run --rm \
-v ${PWD}:/project \
-w /project \
-e GO111MODULE=on \
golang:${GO_VERSION} \
go mod init ${MOD_NAME} || true
vendor: init
rm -r vendor || true
docker run --rm \
-v ${PWD}:/project \
-w /project \
-e GO111MODULE=on \
golang:${GO_VERSION} \
go mod vendor
test: vendor
docker run --rm \
-v ${PWD}:/project \
-w /project \
-e GO111MODULE=on \
golang:${GO_VERSION} \
go test -mod vendor -v -race ./...
build: vendor
rm -f ${APP_NAME} || true
docker run --rm \
-v ${PWD}:/project \
-w /project \
golang:${GO_VERSION} \
env GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=${CGO_ENABLED} GO111MODULE=on go build -mod vendor -o ${APP_NAME} -v
image: build
docker rmi ${DOCKER_IMAGE}:${DOCKER_TAG} || true
docker build \
--build-arg APP_NAME=${APP_NAME} \
-f .docker/Dockerfile \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
.
push: image
docker login docker.io -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
.PHONY: all init vendor test build image push