Skip to content

Commit

Permalink
chore(server,worker): optimize Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Oct 18, 2024
1 parent 96a1893 commit 5e66d73
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 10 additions & 4 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
FROM golang:1.22-bullseye AS build
ARG GO_VERSION=1.22
ARG TAG=release,draco
ARG VERSION

FROM golang:${GO_VERSION}-bullseye AS build

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download

RUN --mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . /app/

RUN go build -tags "${TAG}" "-ldflags=-X main.version=${VERSION} -s -w -buildid=" -trimpath
RUN --mount=type=cache,target=/go/pkg/mod \
go build -tags "${TAG}" "-ldflags=-X main.version=${VERSION} -s -w -buildid=" -trimpath

FROM debian:bullseye

Expand Down
14 changes: 11 additions & 3 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
FROM golang:1.22-alpine AS build
ARG GO_VERSION=1.22
ARG TAG=release
ARG VERSION
FROM golang:${GO_VERSION}-alpine AS build

RUN apk add --update --no-cache git ca-certificates build-base fuse
RUN CGO_ENABLED=0 go install github.com/googlecloudplatform/[email protected]
# RUN CGO_ENABLED=0 go install github.com/googlecloudplatform/[email protected]

WORKDIR /app

RUN --mount=type=bind,source=worker/go.mod,target=go.mod \
--mount=type=bind,source=worker/go.sum,target=go.sum \
--mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . /app/

RUN CGO_ENABLED=0 go build -tags "${TAG}" "-ldflags=-X main.version=${VERSION} -s -w -buildid=" -trimpath -o plateauview-worker ./worker
RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 go build -tags "${TAG}" "-ldflags=-X main.version=${VERSION} -s -w -buildid=" -trimpath -o plateauview-worker ./worker

FROM scratch

Expand Down

0 comments on commit 5e66d73

Please sign in to comment.