dockerize
This commit is contained in:
29
Dockerfile
Normal file
29
Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Cache dependency
|
||||||
|
FROM golang:1.22-alpine AS go-mod-cache
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# BUILD
|
||||||
|
FROM go-mod-cache AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY internal .
|
||||||
|
|
||||||
|
RUN go build . -o ip-info
|
||||||
|
|
||||||
|
# RUN IMAGE
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk update && apk upgrade && \
|
||||||
|
apk add --no-cache tzdata
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/ip-info .
|
||||||
|
COPY mmdbmeld.yml .
|
||||||
|
|
||||||
|
CMD ["./ip-info"]
|
||||||
@@ -5,7 +5,12 @@ var GeoDbSourcePaths = []string{
|
|||||||
"https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-asn/geolite2-asn-ipv4.csv",
|
"https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-asn/geolite2-asn-ipv4.csv",
|
||||||
}
|
}
|
||||||
|
|
||||||
const GeoDbFolder = "data/"
|
const (
|
||||||
|
GeoDbFolder = "data/"
|
||||||
|
MmdbmeldConfig = "mmdbmeld.yml"
|
||||||
|
MmdbDbFile = GeoDbFolder + "geoip-v4.mmdb"
|
||||||
|
)
|
||||||
|
|
||||||
const MmdbmeldConfig = "mmdbmeld.yml"
|
const (
|
||||||
const MmdbDbFile = GeoDbFolder + "geoip-v4.mmdb"
|
ApiDefaultPort = "8080"
|
||||||
|
)
|
||||||
|
|||||||
Binary file not shown.
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
services:
|
||||||
|
ip-info:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
environment:
|
||||||
|
- GIN_TRUSTED_PROXY_IP=127.0.0.1
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"thuanle.me/ip-info/configs"
|
||||||
"thuanle.me/ip-info/configs/key"
|
"thuanle.me/ip-info/configs/key"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,6 +26,9 @@ func StartApiService() {
|
|||||||
engine.GET("/json", HandleJson)
|
engine.GET("/json", HandleJson)
|
||||||
|
|
||||||
port := os.Getenv(key.EnvApiPort)
|
port := os.Getenv(key.EnvApiPort)
|
||||||
|
if len(port) == 0 {
|
||||||
|
port = configs.ApiDefaultPort
|
||||||
|
}
|
||||||
srv = &http.Server{
|
srv = &http.Server{
|
||||||
Addr: ":" + port,
|
Addr: ":" + port,
|
||||||
Handler: engine,
|
Handler: engine,
|
||||||
|
|||||||
Reference in New Issue
Block a user