-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
59 lines (47 loc) · 1.84 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
GOPATH ?= $(shell go env GOPATH)
VERSION ?= devel-$(shell git rev-parse --short HEAD)
DOCKER_URL ?= dcarrillo/whatismyip
.PHONY: test
test: unit-test integration-test
unit-test:
go test -count=1 -race -short -cover ./...
integration-test:
go test -count=1 -v ./integration-tests
install-tools:
@command golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin; \
fi
@command $(GOPATH)/revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mgechev/revive; \
fi
@command $(GOPATH)/shadow > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest; \
fi
lint: install-tools
gofmt -l . && test -z $$(gofmt -l .)
golangci-lint run
shadow ./...
build:
CGO_ENABLED=0 go build -ldflags="-s -w -X 'github.com/dcarrillo/whatismyip/internal/core.Version=${VERSION}'" -o whatismyip ./cmd
docker-build-dev:
docker build --target=dev --build-arg=ARG_VERSION="${VERSION}" --tag ${DOCKER_URL}:${VERSION} .
docker-build-prod:
docker build --target=prod --build-arg=ARG_VERSION="${VERSION}" --tag ${DOCKER_URL}:${VERSION} .
docker-push: docker-build-prod
ifneq (,$(findstring devel-,$(VERSION)))
@echo "VERSION is set to ${VERSION}, I can't push devel builds"
exit 1
else
docker push ${DOCKER_URL}:${VERSION}
docker tag ${DOCKER_URL}:${VERSION} ${DOCKER_URL}:latest
docker push ${DOCKER_URL}:latest
endif
docker-run: docker-build-dev
docker run --tty --interactive --rm \
--publish 8080:8080 \
--volume ${PWD}/test/GeoIP2-City-Test.mmdb:/GeoIP2-City-Test.mmdb \
--volume ${PWD}/test/GeoLite2-ASN-Test.mmdb:/GeoLite2-ASN-Test.mmdb \
${DOCKER_URL}:${VERSION} \
-geoip2-city /GeoIP2-City-Test.mmdb \
-geoip2-asn /GeoLite2-ASN-Test.mmdb \
-trusted-header X-Real-IP