Skip to content

Commit 83cb905

Browse files
committed
change approach for ci: initial container build
1 parent 31c32a2 commit 83cb905

File tree

4 files changed

+79
-57
lines changed

4 files changed

+79
-57
lines changed

.github/workflows/ci.yaml

+34-56
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Basic Checks
1+
name: ci
22

33
on:
44
push:
@@ -8,74 +8,52 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
build:
11+
docker-build:
1212
runs-on: ubuntu-latest
13-
1413
steps:
15-
- name: Set up Python
16-
uses: actions/setup-python@v2
17-
with:
18-
python-version: "3.10"
19-
20-
- name: Checkout repo
14+
- name: Checkout traffic-reproducer
2115
uses: actions/checkout@v4
2216
with:
17+
path: traffic-reproducer
2318
submodules: recursive
2419

25-
- name: Install dependencies
20+
- name: Build traffic-reproducer container
21+
shell: bash
2622
run: |
27-
pip install -r requirements.txt
28-
29-
- name: Set up loopback interfaces
30-
run: |
31-
sudo ifconfig lo:1 192.168.100.1 up
32-
sudo ifconfig lo:2 192.168.100.2 up
23+
cd traffic-reproducer
24+
docker build -t traffic-reproducer:latest -f docker/Dockerfile .
3325
34-
- name: Start Listener
26+
- name: Save image as artifact
27+
shell: bash
3528
run: |
36-
touch nc_output.txt
37-
(nc -u -l -k 9991 | hexdump -C > nc_output.txt & echo $! > listener_pid.txt) &
38-
echo "$!" > listener_pid.txt
39-
sleep 5s
40-
echo "Listener PID:"
41-
cat listener_pid.txt
42-
echo "Listener Output:"
43-
cat nc_output.txt
29+
mkdir -p /tmp/docker/
30+
docker save -o /tmp/docker/traffic_reproducer_docker_images.tar traffic-reproducer:latest
4431
45-
- name: Debug IP Configuration
46-
run: |
47-
ip a
48-
49-
- name: Run main.py
50-
run: |
51-
sudo env PATH="$PATH" python main.py -v -t examples/ipfix-traffic.yml
32+
- name: Upload Artifacts
33+
uses: actions/upload-artifact@v4
34+
with:
35+
retention-days: 7
36+
name: traffic_reproducer_docker_images
37+
path: /tmp/docker
5238

53-
- name: Stop Listener
54-
run: |
55-
pid=$(cat listener_pid.txt)
56-
sudo kill -SIGINT $pid
57-
sleep 5s
58-
echo "Listener Output:"
59-
cat nc_output.txt
39+
# 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...)
6040

61-
- name: Preprocess Hexdump Output
62-
run: |
63-
awk '{print substr($0, 11, 47)}' nc_output.txt | tr -d ' \n' > nc_output_cleaned.txt
64-
echo "Listener Output Cleaned:"
65-
cat nc_output_cleaned.txt
41+
regression-tests:
42+
runs-on: ubuntu-latest
43+
needs: docker-build
44+
steps:
45+
- name: Download Artifacts
46+
uses: actions/download-artifact@v4
47+
with:
48+
pattern: '*_docker_images'
49+
path: /tmp/docker
6650

67-
- name: Count Packets
51+
- name: Import images in the local registry
6852
run: |
69-
packet_count=$(grep -o '000a' nc_output_cleaned.txt | wc -l)
70-
echo $packet_count > packet_count.txt
53+
docker load -i /tmp/docker/traffic_reproducer_docker_images/traffic_reproducer_docker_images.tar
54+
echo "List Images"
55+
docker images | grep 'traffic-reproducer'
7156
72-
- name: Check Packet Count
57+
- name: Run traffic-reproducer container
7358
run: |
74-
packet_count=$(cat packet_count.txt)
75-
echo "Packet Count: $packet_count"
76-
if [ "$packet_count" -eq 6 ]; then
77-
echo "Success: 6 packets received."
78-
else
79-
echo "Error: Expected 6 packets but found $packet_count."
80-
exit 1
81-
fi
59+
docker run --rm --name traffic-reproducer traffic-reproducer:latest

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
**/__pycache__/
22
**/venv/
3-
docker/*
43
**/__tmp**/
54
**/tmp**

docker/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# TODO: make this variable to select different python versions (and manually set a default one)
2+
FROM python:3.12-bookworm
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy the application files to the container
8+
COPY . /app
9+
10+
# Create /pcap directory for config and pcap files
11+
RUN mkdir /pcap
12+
13+
# Install the Python dependencies
14+
RUN pip install -r requirements.txt
15+
16+
# Set the entry point command
17+
# CMD ["python", "./main.py", "--cfg", "/pcap/traffic-reproducer.conf"]
18+
CMD ["python", "./main.py", "-h"]

docker/entrypoint.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
exec > /pcap/run_traffic_reproducer.log
3+
exec 2>&1
4+
5+
echo "$( date ) Running traffic reproducer multi"
6+
7+
pids=()
8+
pcap_folders=( $( ls -d /pcap/*/ ) )
9+
echo "$( date ) ${#pcap_folders[@]} folders found: ${pcap_folders[@]}"
10+
11+
for value in ${pcap_folders[@]}; do
12+
# sleep 1
13+
echo "$( date ) Running ${value}traffic-reproducer.yml"
14+
python3 main.py -t ${value}traffic-reproducer.yml -v > ${value}traffic-reproducer.log 2>&1 &
15+
pid=$!
16+
echo "$( date ) Spawned PID $pid"
17+
pids+=(${pid})
18+
done
19+
20+
echo "$( date ) All spawned PIDs: ${pids[@]}"
21+
echo "$( date ) All processes spawned, now waiting"
22+
23+
for pid in "${pids[@]}"; do
24+
echo "$( date ) Waiting for PID $pid"
25+
wait $pid
26+
done
27+
echo "$( date ) All processes finished"

0 commit comments

Comments
 (0)