docker ready
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.gitignore
|
||||
.env
|
||||
Dockerfile
|
||||
docker-compose*
|
||||
tmp/
|
||||
*.log
|
||||
+37
@@ -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"]
|
||||
@@ -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
|
||||
```
|
||||
Reference in New Issue
Block a user