-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
53 lines (40 loc) · 1.41 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
.PHONY: build proto
SHELL:=/bin/sh
PROJECT_NAME := golayout
DATETIME = $(shell date '+%Y%m%d_%H%M%S')
PROTOS = `ls proto`
# Path Related
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))
RELEASE_DIR := ${MKFILE_DIR}bin
DOCKER_TAG := golayout
# Version
RELEASE?=0.0.1
ifndef GIT_COMMIT
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
endif
GIT_REPO_INFO=$(shell git config --get remote.origin.url)
ifndef GIT_COMMIT
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
endif
# Build Flags
GO_LD_FLAGS= "-s -w -X ${PROJECT_NAME}/pkg/version.RELEASE=${RELEASE} -X ${PROJECT_NAME}/pkg/version.COMMIT=${GIT_COMMIT} -X ${PROJECT_NAME}/pkg/version.REPO=${GIT_REPO_INFO} -X ${PROJECT_NAME}/pkg/version.BUILDTIME=${DATETIME} -X ${PROJECT_NAME}/pkg/version.SERVICENAME=$@"
CGO_SWITCH := 0
proto:
${MKFILE_DIR}tools/buf lint
${MKFILE_DIR}tools/buf generate
build: restful monitor
restful monitor:
cd ${MKFILE_DIR} && \
CGO_ENABLED=${CGO_SWITCH} go build -v -trimpath -ldflags ${GO_LD_FLAGS} \
-o ${RELEASE_DIR}/$@ ${MKFILE_DIR}cmd/$@/
docker_build:
docker build -t ${DOCKER_TAG}:${RELEASE} -f deployment/Dockerfile . --network=host
docker_clean:
docker images | grep \<none\> | awk '{print $$3}' |xargs docker rmi -f #clean <none>
clean:
@rm -f ${MKFILE_DIR}bin/*
up:
docker-compose -f deployment/docker-compose.yaml up -d
down:
docker-compose -f deployment/docker-compose.yaml down