Skip to content

Commit

Permalink
chore: modify dockerfile to build rootless containers
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed Sep 13, 2024
1 parent ba410b0 commit 21d48e0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BRANCH=${{ github.ref_name }}
67 changes: 62 additions & 5 deletions contrib/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,66 @@
# - Help: docker run iperf3 --help
# - Server: docker run -p 5201:5201 -it iperf3 -s
# - Client: docker run -it iperf3 -c 192.168.1.1 (note: since this is a minimal image and does not include DNS, name resolution will not work)
FROM scratch
COPY src/iperf3 /iperf3
COPY tmp /tmp
ENTRYPOINT ["/iperf3"]

# Step 1: Build stage

# Building using docker: docker buildx build -t iperf3 -f ./contrib/Dockerfile .

FROM debian:bullseye-slim AS builder

ARG BRANCH=master

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
ca-certificates \
libssl-dev \
libtool \
autoconf \
automake \
git \
--no-install-recommends

WORKDIR /build

# Clone iperf3 source code
RUN git clone https://github.com/esnet/iperf.git .

# Checkout stable version
RUN git checkout ${BRANCH}

# Build iperf3
RUN ./bootstrap.sh && \
./configure && \
make && \
make install

# Step 2: Create the minimal image
FROM gcr.io/distroless/static-debian12:nonroot

# Copy the compiled iperf3 binary from the builder image
COPY --from=builder /usr/local/bin/iperf3 /usr/local/bin/iperf3

# Copy the required libraries from the builder image
COPY --from=builder /usr/local/lib/libiperf.so.0 /usr/local/lib/libiperf.so.0
COPY --from=builder /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=builder /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=builder /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=builder /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2
COPY --from=builder /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0

# Copy required OpenSSL libraries
COPY --from=builder /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
COPY --from=builder /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

# Set the library path
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu

# Expose the default iperf3 port
EXPOSE 5201
CMD ["-s"]

# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/iperf3"]
# Server Mode
CMD [ "-s" ]

0 comments on commit 21d48e0

Please sign in to comment.