Refactor project structure and enhance logging

This commit is contained in:
2025-08-09 14:52:29 +02:00
parent 1f22b9f898
commit 477bc242aa
11 changed files with 380 additions and 264 deletions
+8 -15
View File
@@ -1,32 +1,25 @@
FROM golang:alpine AS builder
FROM golang:1.24-alpine AS builder
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
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
FROM alpine:latest
RUN apk add --no-cache curl tzdata busybox-suid
RUN apk add --no-cache tzdata
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
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}
ENV GEOIPUPDATE_LICENSE_KEY=${GEOIPUPDATE_LICENSE_KEY}
RUN chown -R appuser:appgroup /app
USER appuser
ENV GEOIPUPDATE_EDITION_IDS="GeoLite2-City GeoLite2-ASN"
ENV GEOIPUPDATE_DB_DIR=/app
RUN echo "AccountID ${GEOIPUPDATE_ACCOUNT_ID}" > /etc/GeoIP.conf && \
echo "LicenseKey ${GEOIPUPDATE_LICENSE_KEY}" >> /etc/GeoIP.conf && \
echo "EditionIDs ${GEOIPUPDATE_EDITION_IDS}" >> /etc/GeoIP.conf && \
echo "DatabaseDirectory ${GEOIPUPDATE_DB_DIR}" >> /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 ["./healthcheck"]