From 709b00ec0e9fb1e9d19024ba38a21b94a84adbe9 Mon Sep 17 00:00:00 2001 From: Thanee Charattrakool <37617738+Planxnx@users.noreply.github.com> Date: Thu, 23 May 2024 17:10:03 +0700 Subject: [PATCH] build: add Docker cache mound for Go modules (#21) * build: add cache mount for go modules * doc(docker): update TZ description * build: use entrypoint instead cmd exec * build: add dockerignore * build: add modules dir to image for migration command * build: update dockerignore * doc: fix typo Co-authored-by: gazenw <163862510+gazenw@users.noreply.github.com> --------- Co-authored-by: gazenw <163862510+gazenw@users.noreply.github.com> --- .dockerignore | 18 ++++++++++++++++++ Dockerfile | 13 +++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9d7e865 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +.git +.gitignore +.github +.vscode +**/*.md +**/*.log +.DS_Store + +# Docker +Dockerfile +.dockerignore +docker-compose.yml + +# Go +.golangci.yaml +cmd.local +config.*.y*ml +config.y*ml diff --git a/Dockerfile b/Dockerfile index 4fcf91b..183c362 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,15 @@ FROM golang:1.22 as builder WORKDIR /app COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod/ go mod download COPY ./ ./ ENV GOOS=linux ENV CGO_ENABLED=0 -RUN go build \ - -o main ./main.go +RUN --mount=type=cache,target=/go/pkg/mod/ \ + go build -o main ./main.go FROM alpine:latest @@ -19,9 +19,10 @@ WORKDIR /app RUN apk --no-cache add ca-certificates tzdata - COPY --from=builder /app/main . +COPY --from=builder /app/modules ./modules -# You can set `TZ` environment variable to change the timezone +# You can set TZ identifier to change the timezone, See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List +# ENV TZ=US/Central -CMD ["/app/main", "run"] +ENTRYPOINT ["/app/main"]