-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
62 lines (46 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
54
55
56
57
58
59
60
61
62
APP?=serv4kub
PORT?=8000
RELEASE?=0.0.1
# COMMIT?=$(shell git rev-parse --short HEAD)
COMMIT?=33301
BUILD_TIME?=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
PROJECT?=play4j/serv4kub
USERNAME?=lis7
CONTAINER_IMAGE_NAME?=${USERNAME}/${APP}
CONTAINER_IMAGE?=docker.io/${CONTAINER_IMAGE_NAME}
GOOS?=linux
GOARCH?=amd64
.DEFAULT_GOAL := prepare
# ----- ----- ----- ----- -----
prepare:
@echo "Choose command: \n build \n container \n run \n test \n push \n minikube"
clean:
rm -f ${APP}
build: clean
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} \
go build \
-ldflags "-s -w -X ${PROJECT}/version.Release=${RELEASE} \
-X ${PROJECT}/version.Commit=${COMMIT} -X ${PROJECT}/version.BuildTime=${BUILD_TIME}" \
-o ${APP}
#run: build
# PORT=${PORT} ./${APP}
container: build
docker build -t $(CONTAINER_IMAGE_NAME) .
run: container
docker stop $(CONTAINER_IMAGE_NAME) || true && docker rm $(CONTAINER_IMAGE_NAME) || true
docker run --name ${APP} -p ${PORT}:${PORT} --rm \
-e "PORT=${PORT}" \
$(CONTAINER_IMAGE_NAME)
test:
go test -v -race ./...
push: container
docker push $(CONTAINER_IMAGE_NAME)
minikube: push
for t in $(shell find ./kubernetes/serv4kub -type f -name "*.yaml"); do \
cat $$t | \
gsed -E "s/\{\{(\s*)\.Release(\s*)\}\}/$(RELEASE)/g" | \
gsed -E "s/\{\{(\s*)\.ServiceName(\s*)\}\}/$(APP)/g"; \
echo "\n---"; \
done > tmp.yaml
# cat tmp.yaml
kubectl apply -f tmp.yaml