From 72bd8f9e5c2eeda31c0ab7e5ec9f3392d2406d9c Mon Sep 17 00:00:00 2001 From: Icaro Rodrigues Date: Mon, 11 Dec 2023 14:06:30 -0300 Subject: [PATCH 1/2] create multistage version of Dockerfile --- docker/Dockerfile | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e4e8130..fdf95b7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,20 +1,34 @@ -FROM golang:1.17.3-alpine3.14 +FROM golang:1.17.5-alpine3.14 AS builder WORKDIR /app -RUN apk update \ - && apk add --virtual build-deps gcc git \ - && rm -rf /var/cache/apk/* +RUN apk add --no-cache --virtual build-deps curl gcc -RUN addgroup -S golang \ - && adduser -S -G golang golang +COPY go.sum go.mod ./ +RUN --mount=type=cache,target=/go/pkg/mod/ \ + go mod download -x COPY . . +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + go install -v ./cmd/... -RUN go install -v ./cmd/... -RUN chown -R golang /app +FROM alpine:3.18.4 -USER golang +ENV APP_USER=app \ + APP_GROUP=app \ + USER_ID=11999 \ + GROUP_ID=11999 + +RUN addgroup --system --gid ${GROUP_ID} ${APP_GROUP} \ + && adduser --system --disabled-password --home /home/${APP_USER} \ + --uid ${USER_ID} --ingroup ${APP_GROUP} ${APP_USER} + +COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /go/bin/ /app/ + +WORKDIR /app + +USER ${APP_USER}:${APP_GROUP} EXPOSE 8080 -ENTRYPOINT ["rp-indexer"] +ENTRYPOINT ["./rp-indexer"] From 2ef0d5b5b432ab814eb44ab65761c6c1f96a305b Mon Sep 17 00:00:00 2001 From: Icaro Rodrigues Date: Mon, 11 Dec 2023 14:42:26 -0300 Subject: [PATCH 2/2] add dockerignore --- .dockerignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..97d8b36 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +.github +.vscode +.*ignore +.env +docker-compose*.yml +Dockerfile* +docker/ +**/*_test.go +Makefile +*.sql +*.md +*.sh +*.dump +LICENSE