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 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"]