From ba410b019af4b2897a7ee15b62d27d308aa9822d Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 12 Sep 2024 22:28:51 -0700 Subject: [PATCH 1/2] feat: build containers for iperf with github actions --- .github/workflows/container.yaml | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/container.yaml diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml new file mode 100644 index 000000000..2ee7e1ca6 --- /dev/null +++ b/.github/workflows/container.yaml @@ -0,0 +1,58 @@ +--- +name: Build Container + +on: + pull_request: + push: + branches: ["master"] + release: + types: ["published"] + +jobs: + build-container: + if: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request' }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}},prefix=v + type=semver,pattern={{major}}.{{minor}},prefix=v + type=semver,pattern={{major}},prefix=v + type=ref,event=branch + type=ref,event=pr + flavor: | + latest=auto + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push + uses: docker/build-push-action@v6 + with: + context: . + file: ./contrib/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 21d48e02b912bdbd72fbcc8426053e0778858774 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Thu, 12 Sep 2024 23:50:06 -0700 Subject: [PATCH 2/2] chore: modify dockerfile to build rootless containers --- .github/workflows/container.yaml | 2 + contrib/Dockerfile | 67 +++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml index 2ee7e1ca6..b341ec599 100644 --- a/.github/workflows/container.yaml +++ b/.github/workflows/container.yaml @@ -56,3 +56,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + BRANCH=${{ github.ref_name }} diff --git a/contrib/Dockerfile b/contrib/Dockerfile index 79f6c7505..5f0a06da3 100644 --- a/contrib/Dockerfile +++ b/contrib/Dockerfile @@ -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" ] \ No newline at end of file