Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (67 loc) · 4.09 KB
/
Copy pathDockerfile
File metadata and controls
98 lines (67 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.10.0@sha256:40fe21f44bb8cddf1eb1226db190d0a984118f62ee02a91b77d99448d28264a6 AS xx
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine3.23@sha256:146e3b9c7c1e2ec3d3f5348c8a686151a75e1976e50efac9fc022ebe446a9a82 AS builder
COPY --link --from=xx / /
RUN xx-apk add --update --no-cache ca-certificates make git curl clang lld
ARG TARGETPLATFORM
RUN xx-apk --update --no-cache add musl-dev gcc
WORKDIR /src
ARG GOPROXY
ENV CGO_ENABLED=1
ENV GOCACHE=/go/cache
ENV GOMODCACHE=/go/pkg/mod
COPY --link go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go mod download -x
ARG VERSION
ARG COMMIT_SHA
COPY --link . .
# 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 --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION} -X main.revision=${COMMIT_SHA}" -tags musl -o /usr/local/bin/openmeter ./cmd/server
RUN xx-verify /usr/local/bin/openmeter
# Build sink-worker binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION} -X main.revision=${COMMIT_SHA}" -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 --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION} -X main.revision=${COMMIT_SHA}" -tags musl -o /usr/local/bin/openmeter-balance-worker ./cmd/balance-worker
RUN xx-verify /usr/local/bin/openmeter-balance-worker
# Build notification-service binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION} -X main.revision=${COMMIT_SHA}" -tags musl -o /usr/local/bin/openmeter-notification-service ./cmd/notification-service
RUN xx-verify /usr/local/bin/openmeter-notification-service
# Build billing-worker binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X main.version=${VERSION} -X main.revision=${COMMIT_SHA}" -tags musl -o /usr/local/bin/openmeter-billing-worker ./cmd/billing-worker
RUN xx-verify /usr/local/bin/openmeter-billing-worker
# Build periodic jobs binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/go/cache \
xx-go build -ldflags "-linkmode external -extldflags \"-static\" -X github.com/openmeterio/openmeter/cmd/jobs/internal.version=${VERSION} -X github.com/openmeterio/openmeter/cmd/jobs/internal.revision=${COMMIT_SHA}" -tags musl -o /usr/local/bin/openmeter-jobs ./cmd/jobs
RUN xx-verify /usr/local/bin/openmeter-jobs
FROM alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
RUN apk add --update --no-cache ca-certificates tzdata bash \
&& addgroup -S -g 10001 openmeter \
&& adduser -S -D -H -u 10001 -G openmeter openmeter \
&& mkdir -p /var/run/openmeter-ca \
&& chown openmeter:openmeter /var/run/openmeter-ca
SHELL ["/bin/bash", "-c"]
COPY --link --from=builder /usr/local/bin/openmeter /usr/local/bin/
COPY --link --from=builder /usr/local/bin/openmeter-sink-worker /usr/local/bin/
COPY --link --from=builder /usr/local/bin/openmeter-balance-worker /usr/local/bin/
COPY --link --from=builder /usr/local/bin/openmeter-notification-service /usr/local/bin/
COPY --link --from=builder /usr/local/bin/openmeter-billing-worker /usr/local/bin/
COPY --link --from=builder /usr/local/bin/openmeter-jobs /usr/local/bin/
COPY --link --from=builder /src/go.* /usr/local/src/openmeter/
COPY --link --chmod=755 prepare-ca-bundle.sh /usr/local/bin/prepare-ca-bundle
USER 10001:10001
CMD ["openmeter"]