Skip to content

feat(docker): Switch to a distroless base image #4940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Features**:

- Build and publish Relay containers with a distroless base image. ([#4940](https://github.com/getsentry/relay/pull/4940))

**Bug Fixes**:

- Normalize OS and Browser names in contexts when missing a version. ([#4957](https://github.com/getsentry/relay/pull/4957))
Expand Down
34 changes: 12 additions & 22 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
FROM debian:bookworm-slim
FROM gcr.io/distroless/cc-debian12:debug AS builder

ARG TARGETPLATFORM

RUN apt-get update \
&& apt-get install -y ca-certificates gosu curl --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN ["/busybox/busybox", "mkdir", "/work", "/etc/relay"]

ENV \
RELAY_UID=10001 \
RELAY_GID=10001

Comment on lines -11 to -12
Copy link
Member

@mdtro mdtro Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're going to want to keep these. It looks like the k8s manifest depends on the specific UID/GID values.

https://github.com/getsentry/ops/blob/af385f13a141f608487665407e34f180ecb10919/k8s/services/relay-pop/deployment.yaml#L166-L167

I'm not sure what nonroot:nonroot is going to map to in distroless. Either way, I would assume it is not guaranteed to match 10001.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik nonroot is 65532, but it doesn't matter, this is just the default. The runtime can freely override this, kubernetes can choose the user, the only issue then will be possibly file permissions, but that just needs to configured correctly on the k8s side.

Since we mount the only necessary write directory with read all and write all permissions this should all work fine.

# Create a new user and group with fixed uid/gid
RUN groupadd --system relay --gid $RELAY_GID \
&& useradd --system --gid relay --uid $RELAY_UID relay
FROM gcr.io/distroless/cc-debian12:nonroot

RUN mkdir /work /etc/relay \
&& chown relay:relay /work /etc/relay
VOLUME ["/work", "/etc/relay"]
WORKDIR /work
ARG TARGETPLATFORM

EXPOSE 3000

COPY $TARGETPLATFORM/relay /bin/relay
RUN chmod +x /bin/relay
COPY --from=builder --chown=nonroot:noonroot /etc/relay /etc/relay
COPY --from=builder --chown=nonroot:noonroot /work /work

COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/bin/bash", "/docker-entrypoint.sh"]
CMD ["run"]
VOLUME ["/etc/relay", "/work"]
WORKDIR /work

COPY --chmod=755 $TARGETPLATFORM/relay /bin/relay

ENTRYPOINT ["/bin/relay"]
CMD ["run"]
51 changes: 0 additions & 51 deletions docker-entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion relay-kafka/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false
workspace = true

[dependencies]
rdkafka = { workspace = true, optional = true, features = ["tracing", "ssl"] }
rdkafka = { workspace = true, optional = true, features = ["tracing", "ssl", "libz-static"] }
rdkafka-sys = { workspace = true, optional = true }
relay-log = { workspace = true, optional = true }
relay-statsd = { workspace = true, optional = true }
Expand Down
Loading