-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
50 lines (35 loc) · 1.59 KB
/
Dockerfile
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
ARG go_version=1.22
ARG otelcol_name=otelcol
ARG otelcol_builder_version=0.115.0
FROM powerman/dockerize:0.19.0 AS dockerize
# Use the Go image to run the OpenTelemetry Collector Builder Binary that will generate
# and compile Go code to create the collector binary.
FROM golang:${go_version} AS otelcolbuilder
ARG otelcol_name
ARG otelcol_builder_version
RUN --mount=type=cache,target=$GOPKG/pkg \
go install github.com/mikefarah/yq/v4@latest; \
go install go.opentelemetry.io/collector/cmd/builder@v${otelcol_builder_version}; \
command -v yq && command -v builder;
WORKDIR /usr/src/app
COPY . .
RUN --mount=type=cache,target=$GOPKG/pkg \
--mount=type=cache,target=/root/.cache/go-build \
yq -i '.dist.output_path = "/usr/src/gen" | \
.dist.name ="'${otelcol_name}'"' ./builder-config.yaml; \
CGO_ENABLED=0 GOOS=linux GOWORK=off \
builder --config=./builder-config.yaml;
# Use a Distroless-base image to run collector with minimal environment
# (the distroless/static-debian12 one is not sufficient and the collector cannot be run).
FROM gcr.io/distroless/base-debian12
ARG otelcol_name
WORKDIR /
COPY --from=dockerize --chown=nonroot:nonroot \
/usr/local/bin/dockerize /usr/local/bin/
COPY --from=otelcolbuilder --chown=nonroot:nonroot \
/usr/src/gen/${otelcol_name} /otelcol
USER nonroot:nonroot
ENTRYPOINT ["/otelcol"]
LABEL org.opencontainers.image.source=https://github.com/clement-casse/otelcol-custom
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.description="An OpenTelemetry Collector built with custom modules for research purpose."