-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
62 lines (45 loc) · 2.02 KB
/
Copy pathDockerfile
File metadata and controls
62 lines (45 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Multi-stage Dockerfile for LogLynx
# Builder stage: compiles a static binary for the target platform
FROM golang:1.25.11 AS builder
# Install C cross-compilers so CGO works when building for non-native platforms.
# gcc-aarch64-linux-gnu is needed for linux/arm64 when building on amd64 runners.
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
# Copy go.mod and go.sum first to leverage Docker layer cache
COPY go.mod go.sum ./
RUN go mod download
# Copy rest of the sources
COPY . .
# Build the server binary (CGO enabled for sqlite/geoip native deps).
# TARGETPLATFORM and TARGETARCH are automatically set by Docker Buildx.
# Select the appropriate cross-compiler based on the target architecture.
ARG TARGETPLATFORM
ARG TARGETARCH
ARG LOGLYNX_USAGE_TELEMETRY_ENDPOINT=""
RUN set -eux; \
case "$TARGETARCH" in \
arm64) export CC=aarch64-linux-gnu-gcc ;; \
*) export CC=gcc ;; \
esac; \
CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH CC=$CC \
go build \
-ldflags "-s -w -X 'loglynx/internal/telemetry.BuildEndpoint=${LOGLYNX_USAGE_TELEMETRY_ENDPOINT}'" \
-o /out/loglynx ./cmd/server
# Final image: small, secure runtime that still ships glibc for CGO
FROM gcr.io/distroless/base-debian12
# Create application directory and set as working dir so relative paths like
# `web/templates/**/*.html` and `geoip/*` resolve inside the container.
WORKDIR /app
# Copy binary from builder
COPY --from=builder /out/loglynx /usr/local/bin/loglynx
# Copy web assets (templates + static) so Gin can load templates from
# the expected relative path `web/templates/**/*.html`.
COPY --from=builder /src/web ./web
# Optional: create directories for volumes
VOLUME ["/data", "/app/geoip", "/traefik/logs"]
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
CMD ["/usr/local/bin/loglynx", "healthcheck"]
ENTRYPOINT ["/usr/local/bin/loglynx"]