This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (65 loc) · 2.3 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
REPO=badmuts
# Name of the image
IMAGE=hsleiden-ipsenh-api
# Current branch-commit (example: master-ab01c1z)
CURRENT=`echo $$TRAVIS_BRANCH | cut -d'/' -f 2-`-$$(git rev-parse HEAD | cut -c1-7)
# Colors
GREEN=\033[0;32m
NC=\033[0m
.PHONY: coverage
run: start
suite: install lint test
package: install compile build
# Install packages
install:
glide install
# Run linters, simple code quality check
lint:
golint $$(go list ./... | grep -v /vendor/)
# go tool vet $$(go list ./... | grep -v /vendor/)
# Run tests
# Coverage is disabled because of this: https://lk4d4.darth.io/posts/multicover/
# mkdir -p coverage
# go test -v -coverprofile=coverage/c.out $$(go list ./... | grep -v /vendor/)
test:
go test -v $$(go list ./... | grep -v /vendor/)
# Create coverage report
coverage:
go tool cover -html=coverage/c.out -o coverage/coverage.html
# Jenkins step to run complete pipeline
ci-tests:
echo "$(GREEN)--- BUILDING TEST IMAGE ---$(NC)"
docker build -t $(IMAGE):test -f operations/docker/Dockerfile.test .
echo "$(GREEN)--- RUNNING TEST SUITE ---$(NC)"
docker run -v "$$(pwd):/go/src/github.com/$(REPO)/$(IMAGE)" --rm $(IMAGE):test bash -c 'make suite'
echo "$(GREEN)--- COMPILE BINARY ---$(NC)"
docker run -v "$$(pwd):/go/src/github.com/$(REPO)/$(IMAGE)" --rm $(IMAGE):test bash -c 'make compile'
# Ci step to run complete pipeline
ci: ci-tests build push cleanup
# Create binary
compile:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo .
# Create docker image with tag badmuts/$(IMAGE):branch-sha
build:
echo "$(GREEN)--- BUILDING DOCKER IMAGE ---$(NC)"
docker build -t $(REPO)/$(IMAGE):$(CURRENT) -f operations/docker/Dockerfile .
# Push image to the hub, this also build the image
push: build
echo "$(GREEN)--- PUSHING IMAGE TO HUB ---$(NC)"
docker push $(REPO)/$(IMAGE):$(CURRENT)
if ! [ -z $$TRAVIS_TAG ]; then \
docker tag $(REPO)/$(IMAGE):$(CURRENT) $(REPO)/$(IMAGE):$$TRAVIS_TAG; \
docker push $(REPO)/$(IMAGE):$$TRAVIS_TAG; \
fi
# Cleanup step to remove test image and build image
cleanup:
docker rmi $(IMAGE):test
docker rmi $(REPO)/$(IMAGE):$(CURRENT)
# Run development via docker-compose. This autoreloads/compiles on change etc.
start:
docker-compose up -d
logs:
docker-compose logs -f api
# Deploy task, only works on ci env
deploy:
./operations/scripts/deploy.sh $$TRAVIS_BRANCH $(CURRENT)