Files
openobserve/deploy/build/Dockerfile.amd64
T
Sangharsh Agarwal 74449c2332 fix: collapse apt-get layers and clean cache in Dockerfile and Dockerfile.amd64 (#13633)
## Summary

Fixes three Dockerfile best practice issues in `Dockerfile` and
`Dockerfile.amd64` runtime stages. `Dockerfile.pr` already follows the
correct pattern — this brings the other two files in line with it.

## Why

**Split `RUN` apt-get layers (cache invalidation bug):**
The runtime stage ran `apt-get update` and `apt-get install` in separate
`RUN` instructions. Docker caches each layer independently, so `apt-get
update` can be cached while `apt-get install` runs fresh — resulting in
stale package indexes and potentially inconsistent installs. This is
[explicitly called
out](https://docs.docker.com/build/building/best-practices/#apt-get) in
Docker's official best practices.

**Missing `--no-install-recommends`:**
The second `apt-get install` was missing `--no-install-recommends`,
pulling in unnecessary recommended packages and bloating the image.

**apt cache left in image:**
No `rm -rf /var/lib/apt/lists/*` after the install, leaving the package
index cache in the final image unnecessarily.

## What changed

Both `Dockerfile` and `Dockerfile.amd64` runtime stages: collapsed three
separate `RUN` instructions into one, added `--no-install-recommends`,
and added `rm -rf /var/lib/apt/lists/*` to clean the apt cache.

**Before:**
```dockerfile
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
RUN apt-get install -y curl htop iftop sysstat procps lsof net-tools
RUN update-ca-certificates
```

**After:**
```dockerfile
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      ca-certificates curl htop iftop sysstat procps lsof net-tools && \
    update-ca-certificates && \
    rm -rf /var/lib/apt/lists/*
```

No changes to installed packages, build stages, base images, or any
other files.
2026-08-07 06:46:46 +00:00

39 lines
1.3 KiB
Docker

# syntax=docker/dockerfile:1
FROM public.ecr.aws/docker/library/node:24-trixie AS webbuilder
WORKDIR /web
COPY ./web /web/
RUN npm install
RUN NODE_OPTIONS="--max-old-space-size=8192" npm run build
FROM public.ecr.aws/zinclabs/rust:trixie-sccache AS builder
ARG AWS_DEFAULT_REGION
ARG AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
# ENV SCCACHE_BUCKET=codepipeline-us-west-2-scccache
# ENV SCCACHE_REGION=us-west-2
# ENV SCCACHE_S3_KEY_PREFIX=zincobserve/dev/amd64/
# ENV SCCACHE_NO_DAEMON=1
# ENV SCCACHE_LOG=debug
RUN rustc --version && sccache --version
WORKDIR /openobserve
COPY . /openobserve
COPY --from=webbuilder /web/dist web/dist
RUN mkdir -p /openobserve/target/release/
RUN --mount=type=cache,target=/root/.cache/sccache cargo build --release --features mimalloc --target x86_64-unknown-linux-gnu \
&& sccache --show-stats
RUN mv /openobserve/target/x86_64-unknown-linux-gnu/release/openobserve /openobserve/target/release/openobserve
FROM public.ecr.aws/debian/debian:trixie-slim AS runtime
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates curl htop iftop sysstat procps lsof net-tools sqlite3 && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /openobserve/target/release/openobserve /
RUN ["/openobserve", "init-dir", "-p", "/data/"]
CMD ["/openobserve"]