Skip to content

Commit 4879089

Browse files
oscar0ursellioscar
andauthored
Add Docker workflow & small features to run.py (#14)
* misc(run.py): [dev] Suricata rules management, save digger mode used, fix stop command. * refactor(webapp): [dev] Small changes to webapp backend code structure. * fix(webapp): [dev] Small fixed in code generation for raw flow data. * chore: [dev] Remove tracking of suricata.rules and small edit to run.py * fix(rules): Update CCIT.rules * Improve run.py features (#13) * feat(run.py): [dev] Preserve CTF config between docker downs * feat(run.py): [dev] Can remove database volume. * feat(run.py): [dev] Check if volume exists before trying to remove it. * refactor(run.py): [dev] Create function for prompts that require y/n ans --------- Co-authored-by: oscar <oscar@debian.oscar> * Add worflow to build and publish Docker images --------- Co-authored-by: oscar <oscar@debian.oscar>
1 parent 664a79c commit 4879089

33 files changed

Lines changed: 850 additions & 590 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Docker Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'suricata/Dockerfile'
9+
- 'webapp/Dockerfile'
10+
- 'grafana/Dockerfile'
11+
- 'pcap_broker/Dockerfile'
12+
- 'suricata/**'
13+
- 'webapp/**'
14+
- 'grafana/**'
15+
- 'pcap_broker/**'
16+
- '.github/workflows/docker-publish.yml'
17+
release:
18+
types:
19+
- published
20+
workflow_dispatch:
21+
22+
env:
23+
REGISTRY: docker.io
24+
IMAGE_NAME: ${{ github.repository_owner }}/digger
25+
26+
jobs:
27+
build-and-push:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
include:
32+
- dockerfile: ./suricata/Dockerfile
33+
image_name: digger-suricata
34+
context: .
35+
- dockerfile: ./webapp/Dockerfile
36+
image_name: digger-webapp
37+
context: ./webapp
38+
- dockerfile: ./grafana/Dockerfile
39+
image_name: digger-grafana
40+
context: ./grafana
41+
- dockerfile: ./pcap_broker/Dockerfile
42+
image_name: digger-pcap-broker
43+
context: ./pcap_broker
44+
45+
permissions:
46+
contents: read
47+
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: Log in to Docker Hub
56+
uses: docker/login-action@v3
57+
with:
58+
registry: ${{ env.REGISTRY }}
59+
username: ${{ secrets.DOCKER_USERNAME }}
60+
password: ${{ secrets.DOCKER_PASSWORD }}
61+
62+
- name: Extract metadata
63+
id: meta
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.image_name }}
67+
tags: |
68+
type=ref,event=branch
69+
type=semver,pattern={{version}}
70+
type=semver,pattern={{major}}.{{minor}}
71+
type=sha,prefix={{branch}}-
72+
type=raw,value=latest,enable={{is_default_branch}}
73+
74+
- name: Build and push Docker image
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: ${{ matrix.context }}
78+
file: ${{ matrix.dockerfile }}
79+
push: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }}
80+
tags: ${{ steps.meta.outputs.tags }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.image_name }}:buildcache
83+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.image_name }}:buildcache,mode=max
84+
85+
summary:
86+
runs-on: ubuntu-latest
87+
needs: build-and-push
88+
if: always()
89+
steps:
90+
- name: Create job summary
91+
run: |
92+
echo "## Docker Images Published" >> $GITHUB_STEP_SUMMARY
93+
echo "" >> $GITHUB_STEP_SUMMARY
94+
echo "The following images have been built and pushed:" >> $GITHUB_STEP_SUMMARY
95+
echo "" >> $GITHUB_STEP_SUMMARY
96+
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-digger-suricata\`" >> $GITHUB_STEP_SUMMARY
97+
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-digger-webapp\`" >> $GITHUB_STEP_SUMMARY
98+
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-digger-grafana\`" >> $GITHUB_STEP_SUMMARY
99+
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-digger-pcap-broker\`" >> $GITHUB_STEP_SUMMARY
100+
echo "" >> $GITHUB_STEP_SUMMARY
101+
echo "**Tags applied:**" >> $GITHUB_STEP_SUMMARY
102+
echo "- Branch name (for push events)" >> $GITHUB_STEP_SUMMARY
103+
echo "- Semantic version (for releases)" >> $GITHUB_STEP_SUMMARY
104+
echo "- Commit SHA" >> $GITHUB_STEP_SUMMARY
105+
echo "- \`latest\` (for main branch)" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright (C) 2024 ANSSI
22
# SPDX-License-Identifier: CC0-1.0
3+
34
input_pcaps/*
5+
!input_pcaps/.gitkeep
46

5-
# Configurazione
6-
.env
7-
services_config.json
7+
# Configuration
8+
config/*
9+
!config/.gitkeep
810

911
# Python
1012
**/__pycache__

docker-compose-a.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ services:
2828
volumes:
2929
- "./input_pcaps:/input_pcaps:ro" # remove to prevent users from downloading pcaps
3030
- "./suricata/output:/suricata/output:ro"
31+
- "./config:/config:rw"
3132
ports:
3233
- 0.0.0.0:8000:8000
3334
depends_on:

docker-compose-b.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- "./input_pcaps:/input_pcaps:rw"
1616
- "./suricata/rules:/suricata/rules:ro"
1717
- "./suricata/output:/suricata/output:rw"
18+
- "./config:/config:rw"
1819

1920
# Mode B: capture interface (fast, requires root on vulnbox and in Docker)
2021
# Drastically reduces ingest delay, but requires to setup traffic mirroring

docker-compose-c.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- "./input_pcaps:/input_pcaps:ro"
1616
- "./suricata/rules:/suricata/rules:ro"
1717
- "./suricata/output:/suricata/output:rw"
18+
- "./config:/config:rw"
1819

1920
# Mode C: PCAP-over-IP (fast, requires root on vulnbox)
2021
# Connects to a PCAP-over-IP server, such as pcap-broker to read PCAP data.

0 commit comments

Comments
 (0)