Skip to content

Commit

Permalink
Make a couple of changes to the Dockerfile
Browse files Browse the repository at this point in the history
1. Update the base image from 8.2 -> 8.3
2. Remove the complicated build steps (used to optimize layer caching and build times) which is largely replaced by sccache
3. Combine a couple RUN commands together to shave off ~10MiB from the final image

Signed-off-by: Jacob Hull <jacob@planethull.com>
  • Loading branch information
jakedipity committed Nov 4, 2020
1 parent 0f21f22 commit 86455a7
Showing 1 changed file with 8 additions and 41 deletions.
49 changes: 8 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@ ENV SCCACHE_REGION=${SCCACHE_REGION}
# Create the directory for agent repo
WORKDIR /opt/logdna-agent-v2

# Only add dependency lists first for caching
COPY Cargo.lock .
COPY Cargo.toml .
COPY bin/Cargo.toml bin/Cargo.toml
COPY common/config-macro/Cargo.toml common/config-macro/
COPY common/config/Cargo.toml common/config/
COPY common/fs/Cargo.toml common/fs/
COPY common/http/Cargo.toml common/http/
COPY common/journald/Cargo.toml common/journald/
COPY common/k8s/Cargo.toml common/k8s/
COPY common/metrics/Cargo.toml common/metrics/
COPY common/middleware/Cargo.toml common/middleware/
COPY common/source/Cargo.toml common/source/

# Create required scaffolding for dependencies
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN LIBDIRS=$(find . -name Cargo.toml -type f -mindepth 2 | sed 's/Cargo.toml//') \
&& for LIBDIR in ${LIBDIRS}; do \
mkdir "${LIBDIR}/src" \
&& touch "${LIBDIR}/src/lib.rs"; \
done \
&& echo "fn main() {}" > bin/src/main.rs

# Build cached dependencies
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
if [ -z "$SCCACHE_BUCKET" ]; then unset RUSTC_WRAPPER; fi; \
cargo build --release && sccache --show-stats

# Delete all cached deps that are local libs
RUN grep -aL "github.com" target/release/deps/* | xargs rm \
&& rm target/release/deps/libconfig_macro*.so

# Add the actual agent source files
COPY . .

Expand All @@ -57,7 +25,7 @@ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
sccache --show-stats

# Use Red Hat Universal Base Image Minimal as the final base image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.2
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3

ARG REPO
ARG BUILD_TIMESTAMP
Expand All @@ -82,17 +50,16 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV _RJEM_MALLOC_CONF="narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0"
ENV JEMALLOC_SYS_WITH_MALLOC_CONF="narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0"

RUN microdnf update -y \
&& microdnf install ca-certificates libcap shadow-utils.x86_64 -y \
&& rm -rf /var/cache/yum

# Copy the agent binary from the build stage
COPY --from=build /opt/logdna-agent-v2/target/release/logdna-agent /work/
WORKDIR /work/
RUN chmod -R 777 .

RUN setcap "cap_dac_read_search+eip" /work/logdna-agent
RUN groupadd -g 5000 logdna && \
useradd -u 5000 -g logdna logdna
RUN microdnf update -y \
&& microdnf install ca-certificates libcap shadow-utils.x86_64 -y \
&& rm -rf /var/cache/yum \
&& chmod -R 777 . \
&& setcap "cap_dac_read_search+eip" /work/logdna-agent \
&& groupadd -g 5000 logdna \
&& useradd -u 5000 -g logdna logdna

CMD ["./logdna-agent"]

0 comments on commit 86455a7

Please sign in to comment.