Skip to content

Commit

Permalink
change approach for ci: initial container build
Browse files Browse the repository at this point in the history
  • Loading branch information
rodonile committed Nov 13, 2024
1 parent 31c32a2 commit 56f56fc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 55 deletions.
87 changes: 32 additions & 55 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,51 @@ on:
workflow_dispatch:

jobs:
build:
docker-build:
runs-on: ubuntu-latest

steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Checkout repo
- name: Checkout traffic-reproducer
uses: actions/checkout@v4
with:
path: traffic-reproducer
submodules: recursive

- name: Install dependencies
- name: Build traffic-reproducer container
shell: bash
run: |
pip install -r requirements.txt
- name: Set up loopback interfaces
run: |
sudo ifconfig lo:1 192.168.100.1 up
sudo ifconfig lo:2 192.168.100.2 up
cd traffic-reproducer
docker build -t traffic-reproducer:latest -f docker/Dockerfile .
- name: Start Listener
- name: Save image as artifact
shell: bash
run: |
touch nc_output.txt
(nc -u -l -k 9991 | hexdump -C > nc_output.txt & echo $! > listener_pid.txt) &
echo "$!" > listener_pid.txt
sleep 5s
echo "Listener PID:"
cat listener_pid.txt
echo "Listener Output:"
cat nc_output.txt
mkdir -p /tmp/docker/
docker save -o /tmp/docker/traffic_reproducer_docker_image.tar traffic-reproducer:latest
- name: Debug IP Configuration
run: |
ip a
- name: Run main.py
run: |
sudo env PATH="$PATH" python main.py -v -t examples/ipfix-traffic.yml
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: traffic_reproducer_docker_image
path: /tmp/docker

- name: Stop Listener
run: |
pid=$(cat listener_pid.txt)
sudo kill -SIGINT $pid
sleep 5s
echo "Listener Output:"
cat nc_output.txt
# TODO idea: send all messages from all examples and then do some basic check on collector logs / print files (no warnings, no error, line counts, etc...)

- name: Preprocess Hexdump Output
run: |
awk '{print substr($0, 11, 47)}' nc_output.txt | tr -d ' \n' > nc_output_cleaned.txt
echo "Listener Output Cleaned:"
cat nc_output_cleaned.txt
regression-tests:
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
pattern: '*_docker_images'
path: /tmp/docker

- name: Count Packets
- name: Import images in the local registry
run: |
packet_count=$(grep -o '000a' nc_output_cleaned.txt | wc -l)
echo $packet_count > packet_count.txt
docker load -i /tmp/docker/traffic_reproducer_docker_image/traffic_reproducer_docker_image.tar
echo "List Images"
docker images | grep 'traffic-reproducer'
- name: Check Packet Count
- name: Run traffic-reproducer container
run: |
packet_count=$(cat packet_count.txt)
echo "Packet Count: $packet_count"
if [ "$packet_count" -eq 6 ]; then
echo "Success: 6 packets received."
else
echo "Error: Expected 6 packets but found $packet_count."
exit 1
fi
docker run --rm --name traffic-reproducer traffic-reproducer:latest
18 changes: 18 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# TODO: make this variable to select different python versions (and manually set a default one)
FROM python:3.12-bookworm

# Set the working directory
WORKDIR /app

# Copy the application files to the container
COPY . /app

# Create /pcap directory for config and pcap files
RUN mkdir /pcap

# Install the Python dependencies
RUN pip install -r requirements.txt

# Set the entry point command
# CMD ["python", "./main.py", "--cfg", "/pcap/traffic-reproducer.conf"]
CMD ["python", "./main.py", "-h"]
27 changes: 27 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
exec > /pcap/run_traffic_reproducer.log
exec 2>&1

echo "$( date ) Running traffic reproducer multi"

pids=()
pcap_folders=( $( ls -d /pcap/*/ ) )
echo "$( date ) ${#pcap_folders[@]} folders found: ${pcap_folders[@]}"

for value in ${pcap_folders[@]}; do
# sleep 1
echo "$( date ) Running ${value}traffic-reproducer.yml"
python3 main.py -t ${value}traffic-reproducer.yml -v > ${value}traffic-reproducer.log 2>&1 &
pid=$!
echo "$( date ) Spawned PID $pid"
pids+=(${pid})
done

echo "$( date ) All spawned PIDs: ${pids[@]}"
echo "$( date ) All processes spawned, now waiting"

for pid in "${pids[@]}"; do
echo "$( date ) Waiting for PID $pid"
wait $pid
done
echo "$( date ) All processes finished"

0 comments on commit 56f56fc

Please sign in to comment.