A lightweight, self-hosted REST API service that provides city-level geolocation lookups using DB-IP's free city database. Built with Rust for optimal performance and minimal resource footprint.
# Clone the repository
git clone https://github.com/damianmoore/geoip-api.git
cd geoip-api
# Build and run
make docker-build
make docker-run
# Basic lookup (when API_KEY not set)
curl http://localhost/8.8.8.8
# With API key using Bearer token (recommended)
curl -H "Authorization: Bearer YOUR_API_KEY" http://localhost/8.8.8.8
# With API key using X-API-Key header
curl -H "X-API-Key: YOUR_API_KEY" http://localhost/8.8.8.8
# With API key using query parameter (less secure)
curl http://localhost/8.8.8.8?api_key=YOUR_API_KEY
# Response
{
"ip": "8.8.8.8",
"city": "Mountain View",
"country": "United States",
"country_code": "US",
"latitude": 37.4056,
"longitude": -122.0775,
"timezone": "America/Los_Angeles",
"accuracy_radius": 1000
}
curl http://localhost/health
# Response: {"status":"healthy"}
DATA_DIR: Directory for database storage (default: /data)ALLOWED_HOSTS: Comma-separated list of allowed Host headers (default: localhost,127.0.0.1)API_KEY: Optional API key for authentication. If not set, API endpoints remain open./geoip-api --help
Options:
--bind <BIND> Bind address [default: 0.0.0.0:80]
--data-dir <DATA_DIR> Data directory [default: /data]
The service automatically manages the GeoIP database:
# Setup development environment
make dev-setup
# Run in development mode
make docker-run-dev
# View logs
make docker-logs
# Run tests
make test
# Build Docker image
make docker-build
# Build multi-architecture images
make docker-multiarch
# Build locally (requires Rust toolchain)
make build
version: '3.8'
services:
geoip-api:
image: damianmoore/geoip-api:latest
ports:
- "80:80"
environment:
- ALLOWED_HOSTS=localhost,127.0.0.1
- API_KEY=your_secure_api_key_here # Optional: enables authentication
volumes:
- geoip-data:/data
restart: unless-stopped
healthcheck:
test: ["CMD", "/usr/local/bin/geoip-api", "--help"]
interval: 30s
timeout: 3s
retries: 3
volumes:
geoip-data:
apiVersion: apps/v1
kind: Deployment
metadata:
name: geoip-api
spec:
replicas: 2
selector:
matchLabels:
app: geoip-api
template:
metadata:
labels:
app: geoip-api
spec:
containers:
- name: geoip-api
image: damianmoore/geoip-api:latest
ports:
- containerPort: 80
env:
- name: ALLOWED_HOSTS
value: "*.svc.cluster.local,localhost,127.0.0.1"
- name: API_KEY
valueFrom:
secretKeyRef:
name: geoip-api-secret
key: api-key
volumeMounts:
- name: data
mountPath: /data
resources:
requests:
memory: "128Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "200m"
volumes:
- name: data
persistentVolumeClaim:
claimName: geoip-data
The project includes GitHub Actions workflow that:
DOCKER_USERNAME: Docker Hub usernameDOCKER_PASSWORD: Docker Hub password/tokenMIT License - see LICENSE file for details.
Content type
Image
Digest
sha256:5d896f5e3…
Size
9 MB
Last updated
about 1 year ago
docker pull damianmoore/geoip-api