-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
100 lines (86 loc) · 2.61 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
all: get build docker test loadtest inspect clean
OS = $(shell uname -s)
IMAGENAME = skandyla/go-websocket-echo-server
ARTF = go-websocket-echo-server
CGO_ENABLED=0
GOOS = linux
PORTHOST = 8080
PORTCT = 8080
define tag_docker
@if [ "$(TRAVIS_BRANCH)" = "master" -a "$(TRAVIS_PULL_REQUEST)" = "false" ]; then \
docker tag $(1) $(1):latest; \
fi
@if [ "$(TRAVIS_BRANCH)" != "master" ]; then \
docker tag $(1) $(1):$(TRAVIS_BRANCH); \
fi
@if [ "$(TRAVIS_PULL_REQUEST)" != "false" ]; then \
docker tag $(1) $(1):PR_$(TRAVIS_PULL_REQUEST); \
fi
endef
get:
@echo
@echo MARK: get dependencies
go get -v ./...
build:
@echo
@echo MARK: build go code
GOOS=$(GOOS) CGO_ENABLED=$(CGO_ENABLED) go build -v --ldflags '-extldflags "-static"' -o $(ARTF)
build_in_docker:
@echo
@echo MARK: build go code inside docker container - optional for testing
docker run --rm -v "$$PWD":/opt -w /opt golang:latest /bin/bash -c "\
export GOBIN=$$GOPATH/bin ;\
go get -v ./... ;\
GOOS=$(GOOS) CGO_ENABLED=$(CGO_ENABLED) go build -v --ldflags '-extldflags "-static"' -o $(ARTF)"
docker:
@echo
@echo MARK: build docker container docker
docker version
docker build -t $(IMAGENAME) --build-arg GIT_COMMIT=$(TRAVIS_COMMIT) --build-arg GIT_BRANCH=$(TRAVIS_BRANCH) -f Dockerfile .
test:
@echo
@echo MARK: testing the container
docker run -d -p $(PORTHOST):$(PORTCT) $(IMAGENAME)
docker ps
curl -w "\n" http://localhost:8080
curl -w "\n" http://localhost:8080/stats
loadtest:
@echo
@echo MARK: make loadtest of the container
docker run --net="host" --rm skandyla/wrk -c60 -d5 -t10 http://localhost:8080/stats
curl -w "\n" http://localhost:8080/stats
#test_compose:
#ifeq ($(strip $(OS)),Linux)
# @echo
# @echo MARK: running via docker-compose
# docker-compose up -d
# docker-compose ps
# curl -w "\n" http://localhost:8000/stats
# docker-compose down
#endif
clean:
@echo
@echo MARK: cleaning the environment
rm -rvf $(ARTF)
docker ps | grep $(IMAGENAME)
docker ps | grep $(IMAGENAME) | awk '{print $$1}' | xargs docker kill
docker-tag:
@echo
@echo MARK: tag_docker depend of branch
$(call tag_docker, $(IMAGENAME))
docker-push:
@echo
@echo MARK: push image to dockerhub
docker push $(IMAGENAME)
inspect:
@echo
@echo MARK: inspecting our image
docker images
docker inspect -f '{{index .ContainerConfig.Labels "git-commit"}}' $(IMAGENAME)
docker inspect -f '{{index .ContainerConfig.Labels "git-branch"}}' $(IMAGENAME)
deploy:
@echo
@echo MARK: deploy template to k8s
@echo MARK: specify DOMAINNAME environment variable first
#envsubst < k8s-deployment.yml
envsubst < k8s-deployment.yml | kubectl apply -f -