From 2da30e46e1191ffea8e57739e435115e1d748506 Mon Sep 17 00:00:00 2001 From: khiem20tc Date: Sun, 22 Oct 2023 11:25:59 +0700 Subject: [PATCH] chore(docker): build multi-stage docker --- .husky/commit-msg | 0 .husky/pre-commit | 0 Dockerfile | 24 ++++++++++++++++++++++-- docker-compose.yaml | 1 - 4 files changed, 22 insertions(+), 3 deletions(-) mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index 81b095b..3cd3448 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,19 @@ -FROM golang:1.21 +# FROM golang:1.21 + +# WORKDIR /app + +# COPY go.mod go.sum ./ + +# RUN go mod download + +# COPY . ./ + +# RUN CGO_ENABLED=0 GOOS=linux go build -o /main + +# CMD ["/main"] + +# Stage 1: Build the application +FROM golang:1.21 AS BUILDER WORKDIR /app @@ -10,4 +25,9 @@ COPY . ./ RUN CGO_ENABLED=0 GOOS=linux go build -o /main -CMD ["/main"] \ No newline at end of file +# Stage 2: Create a minimal image with the built binary +FROM alpine:latest AS RUNNER + +COPY --from=builder /main / + +CMD ["/main"] diff --git a/docker-compose.yaml b/docker-compose.yaml index 4d9bdc3..411c91e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,6 @@ version: "3.8" services: - services: redis: image: redis:5.0 ports: