From 01bc12352a4a50f62bc16d52d0a547d4c6d54948 Mon Sep 17 00:00:00 2001 From: renaldybrada Date: Fri, 27 Feb 2026 12:38:36 +0700 Subject: [PATCH] docker ready --- .dockerignore | 7 +++++++ dockerfile | 37 +++++++++++++++++++++++++++++++++++++ readme.md | 12 ++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 .dockerignore create mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9e2282a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitignore +.env +Dockerfile +docker-compose* +tmp/ +*.log \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..0a52066 --- /dev/null +++ b/dockerfile @@ -0,0 +1,37 @@ +# ================================ +# 1️⃣ Builder Stage +# ================================ +FROM golang:1.25.3-alpine AS builder + +WORKDIR /app + +# Install git jika pakai private module +RUN apk add --no-cache git + +# Cache dependency +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source +COPY . . + +# Build dari cmd/api +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + go build -ldflags="-s -w" \ + -o app ./cmd/api + +# ================================ +# 2️⃣ Final Stage (Distroless) +# ================================ +FROM gcr.io/distroless/base-debian12 + +WORKDIR /app + +COPY --from=builder /app/app . + +# Run as non-root (distroless default user) +USER nonroot:nonroot + +EXPOSE 8080 + +ENTRYPOINT ["/app/app"] \ No newline at end of file diff --git a/readme.md b/readme.md index df297e3..6bede01 100644 --- a/readme.md +++ b/readme.md @@ -86,4 +86,16 @@ Project ini menggunakan seed data untuk integrasi dengan component di frontend. cd go run ./migrations/seeder.go +``` + +## Docker +```bash +// masuk ke root project +cd + +// build docker image +docker build -t antrianoperasi-api:latest . + +// run docker container +docker run --env-file .env -p 8080:8080 antrianoperasi-api ``` \ No newline at end of file