Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create multistage version of Dockerfile #2

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.git
.github
.vscode
.*ignore
.env
docker-compose*.yml
Dockerfile*
docker/
**/*_test.go
Makefile
*.sql
*.md
*.sh
*.dump
LICENSE
36 changes: 26 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
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
RUN apk add --no-cache tzdata

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