echoip/Makefile

72 lines
2.3 KiB
Makefile
Raw Normal View History

DOCKER ?= docker
2020-04-07 04:23:06 +02:00
DOCKER_IMAGE ?= mpolden/echoip
2018-02-09 21:20:32 +01:00
OS := $(shell uname)
ifeq ($(OS),Linux)
TAR_OPTS := --wildcards
endif
2020-08-23 17:11:16 +02:00
XGOARCH := amd64
XGOOS := linux
XBIN := $(XGOOS)_$(XGOARCH)/echoip
2018-02-09 21:20:32 +01:00
2019-10-18 18:06:43 +02:00
all: lint test install
2014-12-22 16:01:23 +01:00
2019-10-18 18:06:43 +02:00
test:
2015-09-17 20:57:27 +02:00
go test ./...
2014-12-22 16:53:41 +01:00
2019-10-18 18:06:43 +02:00
vet:
2016-04-15 17:59:56 +02:00
go vet ./...
check-fmt:
2018-08-27 20:45:51 +02:00
bash -c "diff --line-format='%L' <(echo -n) <(gofmt -d -s .)"
2018-08-27 21:24:28 +02:00
lint: check-fmt vet
2019-10-18 18:06:43 +02:00
install:
2018-02-09 21:57:33 +01:00
go install ./...
2019-07-05 15:01:45 +02:00
databases := GeoLite2-City GeoLite2-Country GeoLite2-ASN
2018-02-09 21:20:32 +01:00
$(databases):
ifndef GEOIP_LICENSE_KEY
$(error GEOIP_LICENSE_KEY must be set. Please see https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/)
endif
2018-02-09 21:20:32 +01:00
mkdir -p data
@curl -fsSL -m 30 "https://download.maxmind.com/app/geoip_download?edition_id=$@&license_key=$(GEOIP_LICENSE_KEY)&suffix=tar.gz" | tar $(TAR_OPTS) --strip-components=1 -C $(CURDIR)/data -xzf - '*.mmdb'
2018-02-09 21:20:32 +01:00
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
2019-07-05 15:01:45 +02:00
test ! -f data/GeoLite2-ASN.mmdb || mv data/GeoLite2-ASN.mmdb data/asn.mmdb
2018-02-09 21:20:32 +01:00
geoip-download: $(databases)
2019-03-16 15:14:32 +01:00
# Create an environment to build multiarch containers (https://github.com/docker/buildx/)
docker-multiarch-builder:
DOCKER_BUILDKIT=1 $(DOCKER) build -o . git://github.com/docker/buildx
mkdir -p ~/.docker/cli-plugins
mv buildx ~/.docker/cli-plugins/docker-buildx
$(DOCKER) buildx create --name multiarch-builder --node multiarch-builder --driver docker-container --use
$(DOCKER) run --rm --privileged multiarch/qemu-user-static --reset -p yes
2019-03-16 15:14:32 +01:00
docker-build:
$(DOCKER) build -t $(DOCKER_IMAGE) .
2019-03-16 15:14:32 +01:00
docker-login:
@echo "$(DOCKER_PASSWORD)" | $(DOCKER) login -u "$(DOCKER_USERNAME)" --password-stdin
2019-03-16 15:14:32 +01:00
2019-03-29 20:38:43 +01:00
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)
2019-03-29 20:38:43 +01:00
docker-push: docker-test docker-multiarch-builder docker-login
$(DOCKER) buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t $(DOCKER_IMAGE) --push .
2019-12-24 17:31:27 +01:00
2020-08-23 17:11:16 +02:00
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)