Skip to content
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

feat: build containers for iperf with github actions #1763

Open
wants to merge 3 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
60 changes: 60 additions & 0 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
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 }}
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" ]