mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-06 14:49:25 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
126ae833b5
|
|||
97b3245278
|
|||
7bc95f98c8
|
|||
66f3436371
|
|||
7d2209d390
|
|||
255660374f
|
|||
36f82eb6a7 | |||
c0d1143de6
|
66
.github/workflows/main.yml
vendored
Normal file
66
.github/workflows/main.yml
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- '*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
|
||||
- name: install go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "^1.17"
|
||||
|
||||
- name: Lint
|
||||
run: make lint
|
||||
|
||||
- name: Tests
|
||||
run: make test
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: tests
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||
strategy:
|
||||
matrix:
|
||||
goosarch: [linux-amd64]
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Sign in to dockerhub
|
||||
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
|
||||
- name: Deploy image
|
||||
run: make docker-push VERSION=$RELEASE_VERSION
|
||||
|
||||
- name: Build
|
||||
run: make build VERSION=$RELEASE_VERSION
|
||||
|
||||
- name: Prepare release
|
||||
run: |
|
||||
git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:%h - %s (%cr) <%an>' --no-merges > changelog.txt
|
||||
tar zcvf whatismyip-$RELEASE_VERSION-${{matrix.goosarch}}.tar.gz whatismyip LICENSE README.md
|
||||
sha256sum whatismyip-$RELEASE_VERSION-${{matrix.goosarch}}.tar.gz > whatismyip-$RELEASE_VERSION-${{matrix.goosarch}}.tar.gz.sha256
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v0.1.14
|
||||
with:
|
||||
body_path: changelog.txt
|
||||
files: |
|
||||
whatismyip-${{env.RELEASE_VERSION}}-${{matrix.goosarch}}.tar.gz
|
||||
whatismyip-${{env.RELEASE_VERSION}}-${{matrix.goosarch}}.tar.gz.sha256
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@ -1,10 +1,13 @@
|
||||
FROM golang:1.17-alpine as builder
|
||||
|
||||
ARG ARG_VERSION
|
||||
ENV VERSION $ARG_VERSION
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN apk add make && make build
|
||||
RUN apk add make && make build VERSION=$VERSION
|
||||
|
||||
# Build final image
|
||||
FROM scratch
|
||||
|
30
Makefile
30
Makefile
@ -1,3 +1,4 @@
|
||||
GOPATH ?= $(shell go env GOPATH)
|
||||
VERSION ?= devel-$(shell git rev-parse --short HEAD)
|
||||
DOCKER_URL ?= dcarrillo/whatismyip
|
||||
|
||||
@ -13,13 +14,13 @@ integration-test:
|
||||
go test ./integration-tests -v
|
||||
|
||||
.PHONY: install-tools
|
||||
install-int:
|
||||
@hash 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 $(go env GOPATH)/bin v1.43.0
|
||||
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 v1.43.0; \
|
||||
fi
|
||||
|
||||
@hash shadow > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@v0.1.7
|
||||
@command $(GOPATH)/shadow > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@v0.1.7; \
|
||||
fi
|
||||
.PHONY: lint
|
||||
lint: install-tools
|
||||
@ -28,17 +29,28 @@ lint: install-tools
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
CGO_ENABLED=0 go build -ldflags="-X 'github.com/dcarrillo/whatismyip/internal/core.Version=${VERSION}'" -o whatismyip ./cmd
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w -X 'github.com/dcarrillo/whatismyip/internal/core.Version=${VERSION}'" -o whatismyip ./cmd
|
||||
|
||||
.PHONY: docker-build
|
||||
docker-build:
|
||||
docker build --tag ${DOCKER_URL}:${VERSION} .
|
||||
docker build --build-arg=ARG_VERSION="${VERSION}" --tag ${DOCKER_URL}:${VERSION} .
|
||||
|
||||
.PHONY: docker-push
|
||||
docker-push: docker-build
|
||||
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
|
||||
|
||||
.PHONY: docker-run
|
||||
docker-run: docker-build
|
||||
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 \
|
||||
-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 \
|
||||
${DOCKER_URL}:${VERSION} \
|
||||
-geoip2-city /tmp/GeoIP2-City-Test.mmdb \
|
||||
-geoip2-asn /tmp/GeoLite2-ASN-Test.mmdb \
|
||||
|
41
README.md
41
README.md
@ -5,6 +5,11 @@
|
||||
- [Endpoints](#endpoints)
|
||||
- [Build](#build)
|
||||
- [Usage](#usage)
|
||||
- [Examples](#examples)
|
||||
- [Run a default TCP server](#run-a-default-tcp-server)
|
||||
- [Run a TLS server only](#run-a-tls-server-only)
|
||||
- [Run a default TCP server with a custom template and trust a custom header set by an upstream proxy](#run-a-default-tcp-server-with-a-custom-template-and-trust-a-custom-header-set-by-an-upstream-proxy)
|
||||
- [Download](#download)
|
||||
- [Docker](#docker)
|
||||
- [Running a container locally using test databases](#running-a-container-locally-using-test-databases)
|
||||
- [From Docker Hub](#from-docker-hub)
|
||||
@ -25,12 +30,14 @@ curl -6 ifconfig.es
|
||||
|
||||
## Features
|
||||
|
||||
- TLS available
|
||||
- TLS is avaliable.
|
||||
- Can run behind a proxy by trusting a custom header (usually `X-Real-IP`) to figure out the source IP address.
|
||||
- IPv4 and IPv6.
|
||||
- Geolocation info including ASN. This feature is possible thanks to [maxmind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en) GeoLite2 databases. In order to use these databases, a -icense key is needed. Please visit Maxmind site for further instructions and get a free license.
|
||||
- High performance
|
||||
- HTML with templates, text plain and JSON output.
|
||||
- Geolocation info including ASN. This feature is possible thanks to [maxmind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en) GeoLite2 databases. In order to use these databases, a license key is needed. Please visit Maxmind site for further instructions and get a free license.
|
||||
- High performance.
|
||||
- Self-contained server what can reload GeoLite2 databases and/or SSL certificates without stop/start. The `hup` signal is honored.
|
||||
- HTML templates for the landing page.
|
||||
- Text plain and JSON output.
|
||||
|
||||
## Endpoints
|
||||
|
||||
@ -81,9 +88,33 @@ Usage of ./whatismyip:
|
||||
Output version information and exit
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Run a default TCP server
|
||||
|
||||
```bash
|
||||
./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb
|
||||
```
|
||||
|
||||
### Run a TLS server only
|
||||
|
||||
```bash
|
||||
./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb -bind "" -tls-bind :8081 -tls-crt ./test/server.pem -tls-key ./test/server.key
|
||||
```
|
||||
|
||||
### Run a default TCP server with a custom template and trust a custom header set by an upstream proxy
|
||||
|
||||
```bash
|
||||
./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb -trusted-header X-Real-IP -template mytemplate.tmpl
|
||||
```
|
||||
|
||||
## Download
|
||||
|
||||
Download latest version from https://github.com/dcarrillo/whatismyip/releases
|
||||
|
||||
## Docker
|
||||
|
||||
An ultra-light (13MB) image is available.
|
||||
An ultra-light (~9MB) image is available.
|
||||
|
||||
### Running a container locally using test databases
|
||||
|
||||
|
@ -46,7 +46,7 @@ func Setup() {
|
||||
flag.Parse()
|
||||
|
||||
if *ver {
|
||||
fmt.Printf("whaismyip version %s", core.Version)
|
||||
fmt.Printf("whatismyip version %s", core.Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user