Skip to content

Commit f68d8e9

Browse files
authored
Dev (#7)
* chore: remove deprecated configuration files and resources for staging environment * chore: remove outdated documentation and add new migration instructions * chore: update Go version to 1.26.2 and add govulncheck commands * chore: add mock implementations for interaction services and update command documentation * Ratelimiter: Singleton for Storage * fix: align env variables and cleanup Viper-MySQL mismatch" -m "Fixed DB connection by aligning .env keys (DB_*) with Viper defaults. Fixed Access Denied by ensuring the app uses the same credentials as Docker secrets. * refactor: implement two-tier rate limiting for enhanced DoS protection * refactor: update Dockerfiles for improved security and build efficiency * refactor: streamline Dockerfile for improved build efficiency and security
2 parents fa42f2c + 601fcaa commit f68d8e9

1 file changed

Lines changed: 4 additions & 22 deletions

File tree

cmd/api/Dockerfile

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,43 @@
1-
# --- ETAP 1: GOLANG BUILDER ---
21
FROM golang:1.26-alpine AS builder
32

4-
# Dodajemy narzędzia niezbędne do kompilacji i bezpieczeństwa
53
RUN apk add --no-cache ca-certificates git tzdata
64

75
WORKDIR /src
86

9-
# Optymalizacja cache zależności
107
COPY go.mod go.sum ./
118
RUN go mod download
129

13-
# Kopiujemy kod źródłowy
1410
COPY . .
1511

16-
# [PRO TIP] Budowanie z flagami, które czynią binarkę jeszcze bezpieczniejszą:
17-
# -trimpath: usuwa ścieżki z Twojego komputera z binarki (bezpieczeństwo logów)
18-
# -ldflags="-w -s": usuwa symbole debugowania
1912
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
2013
go build -trimpath -ldflags="-w -s" -o /app/server ./cmd/api
2114

22-
23-
# --- ETAP 2: FINAL RUNTIME ---
2415
FROM alpine:3.19.1 AS final
2516

26-
# Etykiety zgodne ze standardem OCI (Google/Amazon to kochają)
27-
LABEL org.opencontainers.image.source="https://github.com/twoj-user/twoj-repo"
17+
LABEL org.opencontainers.image.source="https://github.com/ZeroDayZ7/http-server"
2818
LABEL org.opencontainers.image.description="Hardened Go API"
2919

30-
# Instalacja tylko niezbędnych paczek i aktualizacja poprawek bezpieczeństwa
3120
RUN apk update && \
3221
apk add --no-cache ca-certificates tzdata && \
3322
rm -rf /var/cache/apk/*
3423

35-
# Tworzymy użytkownika (UID 10001 jest poza standardowym zakresem systemowym)
3624
RUN addgroup -S appgroup && \
3725
adduser -S -u 10001 -g appgroup appuser
3826

3927
WORKDIR /home/appuser
4028

41-
# Kopiujemy binarkę i migracje z poprawnym właścicielem w jednej warstwie
42-
COPY --from=builder --chown=appuser:appgroup /app/server .
29+
COPY --from=builder /app/server .
4330
COPY --from=builder --chown=appuser:appgroup /src/migrations ./migrations
4431

45-
# [PRO TIP] Usuwamy powłoki (shell), jeśli nie są potrzebne do healthchecka
46-
# Ale zostawiamy wget dla Twojego HEALTHCHECKa poniżej.
47-
48-
# Zabezpieczenie plików (Read-Only)
4932
RUN chmod 500 ./server && \
50-
chmod -R 400 ./migrations
33+
chmod 500 ./migrations && \
34+
chmod 400 ./migrations/*
5135

5236
USER appuser
5337

5438
EXPOSE 8080
5539

56-
# Ulepszony Healthcheck - upewnij się, że Twoja apka Go ma endpoint /health!
5740
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
5841
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
5942

60-
# Uruchomienie jako proces nr 1
6143
ENTRYPOINT ["./server"]

0 commit comments

Comments
 (0)