mirror of
https://github.com/skidoodle/ipinfo.git
synced 2026-04-28 17:37:37 +02:00
docker healthcheck
This commit is contained in:
+5
-4
@@ -3,15 +3,16 @@ WORKDIR /build
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go build -o ipinfo .
|
||||
RUN go build -ldflags="-s -w" -o ipinfo .
|
||||
RUN go build -ldflags="-s -w" -o healthcheck ./healthcheck/healthcheck.go
|
||||
RUN go install github.com/maxmind/geoipupdate/v7/cmd/geoipupdate@latest
|
||||
RUN mkdir -p /build/data
|
||||
|
||||
FROM alpine:latest
|
||||
RUN apk add --no-cache curl tzdata busybox-suid
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /build/ipinfo .
|
||||
COPY --from=builder /build/healthcheck .
|
||||
COPY --from=builder /go/bin/geoipupdate /usr/local/bin/geoipupdate
|
||||
|
||||
ENV GEOIPUPDATE_ACCOUNT_ID=${GEOIPUPDATE_ACCOUNT_ID}
|
||||
@@ -27,8 +28,8 @@ RUN echo "AccountID ${GEOIPUPDATE_ACCOUNT_ID}" > /etc/GeoIP.conf && \
|
||||
RUN echo "0 0 * * * geoipupdate >> /var/log/geoipupdate.log 2>&1" > /etc/crontabs/root
|
||||
RUN cat /etc/crontabs/root
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD curl --fail http://localhost:3000/health || exit 1
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD ["./healthcheck"]
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["sh", "-c", "geoipupdate && ./ipinfo"]
|
||||
CMD ["./ipinfo"]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
services:
|
||||
ipinfo:
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: ipinfo
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
@@ -8,11 +10,3 @@ services:
|
||||
environment:
|
||||
GEOIPUPDATE_ACCOUNT_ID: ${GEOIPUPDATE_ACCOUNT_ID}
|
||||
GEOIPUPDATE_LICENSE_KEY: ${GEOIPUPDATE_LICENSE_KEY}
|
||||
GEOIPUPDATE_EDITION_IDS: "GeoLite2-City GeoLite2-ASN"
|
||||
GEOIPUPDATE_DB_DIR: /app
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
@@ -8,11 +8,3 @@ services:
|
||||
environment:
|
||||
GEOIPUPDATE_ACCOUNT_ID: ${GEOIPUPDATE_ACCOUNT_ID}
|
||||
GEOIPUPDATE_LICENSE_KEY: ${GEOIPUPDATE_LICENSE_KEY}
|
||||
GEOIPUPDATE_EDITION_IDS: "GeoLite2-City GeoLite2-ASN"
|
||||
GEOIPUPDATE_DB_DIR: /app
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module skidoodle/ipinfo
|
||||
|
||||
go 1.22.4
|
||||
go 1.24.0
|
||||
|
||||
require github.com/oschwald/maxminddb-golang v1.13.1
|
||||
|
||||
require golang.org/x/sys v0.29.0 // indirect
|
||||
require golang.org/x/sys v0.30.0 // indirect
|
||||
|
||||
@@ -8,5 +8,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module healthcheck
|
||||
|
||||
go 1.24.0
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("http://localhost:3000/health")
|
||||
if err != nil {
|
||||
log.Fatalf("Error performing health check: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Printf("Health check failed: Status code %d", resp.StatusCode)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("OK")
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -48,10 +48,8 @@ cd ipinfo
|
||||
docker build -t ipinfo:main .
|
||||
docker run \
|
||||
-p 3000:3000
|
||||
-e GEOIPUPDATE_ACCOUNT_ID=<> \
|
||||
-e GEOIPUPDATE_LICENSE_KEY=<> \
|
||||
-e GEOIPUPDATE_EDITION_IDS=<> \
|
||||
-e GEOIPUPDATE_DB_DIR=<> \
|
||||
-e GEOIPUPDATE_ACCOUNT_ID=${GEOIPUPDATE_ACCOUNT_ID} \
|
||||
-e GEOIPUPDATE_LICENSE_KEY=${GEOIPUPDATE_LICENSE_KEY} \
|
||||
ipinfo:main
|
||||
```
|
||||
|
||||
@@ -78,14 +76,6 @@ services:
|
||||
environment:
|
||||
GEOIPUPDATE_ACCOUNT_ID: ${GEOIPUPDATE_ACCOUNT_ID}
|
||||
GEOIPUPDATE_LICENSE_KEY: ${GEOIPUPDATE_LICENSE_KEY}
|
||||
GEOIPUPDATE_EDITION_IDS: "GeoLite2-City GeoLite2-ASN"
|
||||
GEOIPUPDATE_DB_DIR: /app
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
```
|
||||
|
||||
### Docker Run
|
||||
@@ -96,10 +86,8 @@ docker run \
|
||||
--name=ipinfo \
|
||||
--restart=unless-stopped \
|
||||
-p 3000:3000 \
|
||||
-e GEOIPUPDATE_ACCOUNT_ID=<> \
|
||||
-e GEOIPUPDATE_LICENSE_KEY=<> \
|
||||
-e GEOIPUPDATE_EDITION_IDS=<> \
|
||||
-e GEOIPUPDATE_DB_DIR=<> \
|
||||
-e GEOIPUPDATE_ACCOUNT_ID=${GEOIPUPDATE_ACCOUNT_ID} \
|
||||
-e GEOIPUPDATE_LICENSE_KEY=${GEOIPUPDATE_LICENSE_KEY} \
|
||||
ghcr.io/skidoodle/ipinfo:main
|
||||
```
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ func HealthCheck() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Healthy"))
|
||||
w.Write([]byte("OK"))
|
||||
})
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user