whatismyip/Makefile

59 lines
1.8 KiB
Makefile
Raw Normal View History

2021-11-10 19:27:02 +00:00
GOPATH ?= $(shell go env GOPATH)
2021-11-10 19:06:12 +00:00
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 ./...
2021-11-10 19:06:12 +00:00
integration-test:
go test -count=1 -v ./integration-tests
2021-11-10 19:06:12 +00:00
2021-11-10 19:27:02 +00:00
install-tools:
@command golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
2023-01-26 19:47:03 +00:00
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin; \
2021-11-10 19:06:12 +00:00
fi
2024-04-12 17:26:48 +00:00
@command $(GOPATH)/revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mgechev/revive; \
fi
2021-11-10 19:27:02 +00:00
@command $(GOPATH)/shadow > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
2023-01-26 19:47:03 +00:00
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest; \
2021-11-10 19:06:12 +00:00
fi
2024-04-12 17:26:48 +00:00
2021-11-10 19:06:12 +00:00
lint: install-tools
gofmt -l . && test -z $$(gofmt -l .)
2021-11-10 19:06:12 +00:00
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
2021-11-10 19:06:12 +00:00
2024-04-12 17:26:48 +00:00
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} .
2024-04-12 17:26:48 +00:00
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
2021-11-10 19:06:12 +00:00
2024-04-12 17:26:48 +00:00
docker-run: docker-build-dev
2021-11-10 19:06:12 +00:00
docker run --tty --interactive --rm \
-v ${PWD}/test/GeoIP2-City-Test.mmdb:/tmp/GeoIP2-City-Test.mmdb:ro \
-v ${PWD}/test/GeoLite2-ASN-Test.mmdb:/tmp/GeoLite2-ASN-Test.mmdb:ro -p 8080:8080 \
2021-11-10 19:06:12 +00:00
${DOCKER_URL}:${VERSION} \
-geoip2-city /tmp/GeoIP2-City-Test.mmdb \
-geoip2-asn /tmp/GeoLite2-ASN-Test.mmdb \
-trusted-header X-Real-IP