From ed2ecae9e587c32ce77e9c99a7cbef3d3027bbc0 Mon Sep 17 00:00:00 2001 From: ali Date: Fri, 15 Sep 2023 17:42:00 +0330 Subject: [PATCH] modified the dockerfile for multistage dockerfile. --- Dockerfile | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0dcc346..71270c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,22 @@ -FROM golang:1.17 +FROM golang:1.17 AS build RUN useradd -m netlify -ADD . /src -RUN cd /src && make deps build_linux && mv gocommerce /usr/local/bin/ +WORKDIR /src +COPY . . + +# Build the application +RUN make deps build_linux +RUN mv gocommerce /usr/local/bin/ + +# Stage 2: Create a minimal image +FROM scratch + +# Copy the built binary from the first stage +COPY --from=build /usr/local/bin/gocommerce /usr/local/bin/gocommerce USER netlify -CMD ["gocommerce"] EXPOSE 8080 + +CMD ["gocommerce"] +