Skip to content

Commit

Permalink
use cache mounts in dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
w1ck3dg0ph3r committed Nov 9, 2024
1 parent 651c6c8 commit 6e9da37
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ ARG ui_mode=production
WORKDIR /src/ui
RUN corepack enable pnpm
COPY ui/package.json ui/pnpm-lock.yaml ./
RUN pnpm install
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile
COPY ui ./
RUN pnpm vite build --mode ${ui_mode}

FROM golang:1.23-alpine AS api-builder
ARG version=unknown
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=cache,id=golang,target=/go/pkg/mod/ \
go mod download
COPY . .
COPY --from=ui-builder /src/ui/dist ./ui/dist
RUN \
go build -o /bin/goce -ldflags "-s -w -X main.version=${version}" ./cmd/goce &&\
go build -o /bin/godl -ldflags "-s -w" ./cmd/tools/godl
RUN --mount=type=cache,id=golang,target=/go/pkg/mod/ \
--mount=type=cache,id=golang,target=/root/.cache/go-build \
go build -o /bin/goce -ldflags "-s -w -X main.version=${version}" ./cmd/goce &&\
go build -o /bin/godl -ldflags "-s -w" ./cmd/tools/godl

FROM alpine:3.20
RUN apk add ca-certificates tzdata curl tar git
RUN \
addgroup -g 1000 goce && adduser -u 1000 -DG goce goce &&\
mkdir /opt/data && chown goce: /opt/data
RUN addgroup -g 1000 goce && adduser -u 1000 -DG goce goce &&\
mkdir /opt/data && chown goce: /opt/data
USER goce
RUN mkdir -p ~/sdk ~/go/pkg/mod ~/.cache/go-build
WORKDIR /opt
Expand Down

0 comments on commit 6e9da37

Please sign in to comment.