From 13031c6339c8d24a382ad3beb880b5d0846c7285 Mon Sep 17 00:00:00 2001 From: RawanMostafa08 Date: Sat, 21 Sep 2024 21:19:51 +0300 Subject: [PATCH] feat: multistage docker for gin server --- Dockerfile.gin | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Dockerfile.gin b/Dockerfile.gin index 4644505..39f42e2 100644 --- a/Dockerfile.gin +++ b/Dockerfile.gin @@ -1,13 +1,17 @@ FROM golang:latest AS builder - -WORKDIR /app - + +WORKDIR /build + COPY . . - + RUN go mod download - -RUN go build -o ginserver ./cmd/ginserver/main.go - + +RUN CGO_ENABLED=0 GOOS=linux go build -o ginout ./cmd/ginserver/main.go + EXPOSE 8083 - -ENTRYPOINT [ "/app/ginserver" ] \ No newline at end of file + +FROM scratch +WORKDIR /app +COPY --from=builder /build/ginout . + +ENTRYPOINT [ "/app/ginout" ]