forked from weiiwang01/wpex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (42 loc) · 1.44 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (42 loc) · 1.44 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
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25 as builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG WPEX_VERSION
WORKDIR /build
# Copia i file di dipendenza
COPY go.mod go.sum ./
# Scarica le dipendenze
RUN go mod download
# Copia tutto il codice sorgente
COPY . .
# Costruisci l'eseguibile con ottimizzazioni
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags="-w -s -X main.version=${WPEX_VERSION}" \
-o wpex .
# Stage finale - immagine leggera
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:latest
# Installa ca-certificates per HTTPS, tzdata per timezone, e diagnostica
RUN apk --no-cache add ca-certificates tzdata iputils traceroute
# Crea utente non-root per sicurezza
RUN addgroup -g 1000 wpex && \
adduser -D -u 1000 -G wpex wpex
# Crea directory per dati e log
RUN mkdir -p /data /var/log/wpex && \
chown -R wpex:wpex /data /var/log/wpex
# Copia l'eseguibile
COPY --from=builder /build/wpex /usr/local/bin/wpex
RUN chmod +x /usr/local/bin/wpex
# Espone le porte
EXPOSE 40000/udp 8080/tcp
# Switch all'utente non-root
USER wpex
# Directory di lavoro
WORKDIR /data
# Health check per Docker
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Entry point con configurazione predefinita sensata
ENTRYPOINT ["/usr/local/bin/wpex"]
CMD ["--stats", ":8080"]