diff --git a/Dockerfile b/Dockerfile index 5b862a506..a825c40e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,29 +18,41 @@ ARG GOPROXY ENV CGO_ENABLED=1 -COPY go.mod go.sum ./ -RUN go mod download - -COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go mod download -x ARG VERSION # See https://github.com/confluentinc/confluent-kafka-go#librdkafka # See https://github.com/confluentinc/confluent-kafka-go#static-builds-on-linux # Build server binary (default) -RUN go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter ./cmd/server +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter ./cmd/server RUN xx-verify /usr/local/bin/openmeter # Build sink-worker binary -RUN go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-sink-worker ./cmd/sink-worker +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-sink-worker ./cmd/sink-worker RUN xx-verify /usr/local/bin/openmeter-sink-worker # Build balance-worker binary -RUN go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-balance-worker ./cmd/balance-worker +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-balance-worker ./cmd/balance-worker RUN xx-verify /usr/local/bin/openmeter-balance-worker # Build balance-worker binary -RUN go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-notification-service ./cmd/notification-service +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION}" -tags musl -o /usr/local/bin/openmeter-notification-service ./cmd/notification-service RUN xx-verify /usr/local/bin/openmeter-notification-service diff --git a/benthos-collector.Dockerfile b/benthos-collector.Dockerfile index 93e29d58d..df3008488 100644 --- a/benthos-collector.Dockerfile +++ b/benthos-collector.Dockerfile @@ -10,14 +10,17 @@ ARG GOPROXY ENV CGO_ENABLED=0 -COPY go.mod go.sum ./ -RUN go mod download - -COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go mod download ARG VERSION -RUN go build -ldflags "-X main.version=${VERSION}" -o /usr/local/bin/benthos ./cmd/benthos-collector +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,source=.,target=/usr/local/src/openmeter,ro \ + go build -ldflags "-X main.version=${VERSION}" -o /usr/local/bin/benthos ./cmd/benthos-collector FROM alpine:3.20.3@sha256:1e42bbe2508154c9126d48c2b8a75420c3544343bf86fd041fb7527e017a4b4a