forked from mpolden/echoip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (54 loc) · 2.17 KB
/
Makefile
File metadata and controls
70 lines (54 loc) · 2.17 KB
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
DOCKER ?= docker
DOCKER_IMAGE ?= ebzao/echoip
OS := $(shell uname)
ifeq ($(OS),Linux)
TAR_OPTS := --wildcards
endif
XGOARCH := amd64
XGOOS := linux
XBIN := $(XGOOS)_$(XGOARCH)/echoip
all: checkfmt vet test install
test:
go test ./...
vet:
go vet ./...
checkfmt:
@sh -c "test -z $$(gofmt -l .)" || { echo "one or more files need to be formatted: try make fmt to fix this automatically"; exit 1; }
fmt:
gofmt -w .
install:
go install ./...
databases := GeoLite2-City GeoLite2-Country GeoLite2-ASN
$(databases):
ifndef GEOIP_LICENSE_KEY
$(error GEOIP_LICENSE_KEY and MAXMIND_ACCOUNT_ID must be set. See https://dev.maxmind.com/geoip/updating-databases/#directly-downloading-databases
endif
ifndef MAXMIND_ACCOUNT_ID
$(error GEOIP_LICENSE_KEY and MAXMIND_ACCOUNT_ID must be set. See https://dev.maxmind.com/geoip/updating-databases/#directly-downloading-databases
endif
mkdir -p data
@curl -fsSL -m 30 -u $(MAXMIND_ACCOUNT_ID):$(GEOIP_LICENSE_KEY) "https://download.maxmind.com/geoip/databases/$@/download?suffix=tar.gz" | tar $(TAR_OPTS) --strip-components=1 -C $(CURDIR)/data -xzf - '*.mmdb'
test ! -f data/GeoLite2-City.mmdb || mv data/GeoLite2-City.mmdb data/city.mmdb
test ! -f data/GeoLite2-Country.mmdb || mv data/GeoLite2-Country.mmdb data/country.mmdb
test ! -f data/GeoLite2-ASN.mmdb || mv data/GeoLite2-ASN.mmdb data/asn.mmdb
geoip-download: $(databases)
docker-build:
$(DOCKER) build -t $(DOCKER_IMAGE) .
docker-login:
@echo "$(DOCKER_PASSWORD)" | $(DOCKER) login -u "$(DOCKER_USERNAME)" --password-stdin
docker-test:
$(eval CONTAINER=$(shell $(DOCKER) run --rm --detach --publish-all $(DOCKER_IMAGE)))
$(eval DOCKER_PORT=$(shell $(DOCKER) port $(CONTAINER) | cut -d ":" -f 2))
curl -fsS -m 5 localhost:$(DOCKER_PORT) > /dev/null; $(DOCKER) stop $(CONTAINER)
docker-push: docker-test docker-login
$(DOCKER) push $(DOCKER_IMAGE)
xinstall:
env GOOS=$(XGOOS) GOARCH=$(XGOARCH) go install ./...
publish:
ifndef DEST_PATH
$(error DEST_PATH must be set when publishing)
endif
rsync -a $(GOPATH)/bin/$(XBIN) $(DEST_PATH)/$(XBIN)
@sha256sum $(GOPATH)/bin/$(XBIN)
run:
go run cmd/echoip/main.go -a data/asn.mmdb -c data/city.mmdb -f data/country.mmdb -H x-forwarded-for -r -s -p