Skip to content

Commit

Permalink
create multistage version of Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
irdgss committed Dec 11, 2023
1 parent 2cb71dd commit 4308619
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
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
34 changes: 24 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 4308619

Please sign in to comment.