From 6d1d079f06e571a16252184acad075d0c3c80290 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Aug 2025 04:08:43 +0300 Subject: [PATCH] add Dockerfile for multi-stage build and update generate.go command --- Dockerfile | 30 +++++++++++++++++++++++++++ generate.go | 3 --- internal/api/auth/handler/generate.go | 1 - 3 files changed, 30 insertions(+), 4 deletions(-) delete mode 100644 generate.go diff --git a/Dockerfile b/Dockerfile index e69de29..4097171 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,30 @@ +# ---------- Build Stage ---------- +FROM golang:1.24 AS builder + +# Set working directory +WORKDIR /app + +# Copy Go module files and download dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build the Go binary +RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/api/main.go + +# ---------- Final Image ---------- +FROM alpine:latest + +# Set working directory in final image +WORKDIR /app + +# Copy only the binary from builder +COPY --from=builder /app/main . + +# Expose the port your app listens on +EXPOSE 8080 + +# Set default command +CMD ["./main"] diff --git a/generate.go b/generate.go deleted file mode 100644 index 4448c33..0000000 --- a/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package LogDex_ID - -//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml api.yaml diff --git a/internal/api/auth/handler/generate.go b/internal/api/auth/handler/generate.go index 5f7e4ab..9cc9671 100644 --- a/internal/api/auth/handler/generate.go +++ b/internal/api/auth/handler/generate.go @@ -1,4 +1,3 @@ package handler -//go:generate go tool oapi-codegen -config ../../../../api/auth/cfg.yaml ../../../../api/auth/api.yam //go:generate go tool oapi-codegen -config ../../../../api/auth/cfg.yaml ../../../../api/auth/api.yaml