docker ready

This commit is contained in:
renaldybrada
2026-02-27 12:38:36 +07:00
parent a6cba3a219
commit 01bc12352a
3 changed files with 56 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
.git
.gitignore
.env
Dockerfile
docker-compose*
tmp/
*.log
+37
View File
@@ -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"]
+12
View File
@@ -86,4 +86,16 @@ Project ini menggunakan seed data untuk integrasi dengan component di frontend.
cd <project_name>
go run ./migrations/seeder.go
```
## Docker
```bash
// masuk ke root project
cd <project_name>
// build docker image
docker build -t antrianoperasi-api:latest .
// run docker container
docker run --env-file .env -p 8080:8080 antrianoperasi-api
```