Skip to content

Commit d32d67d

Browse files
add docker-compose dev stack, Dockerfile, scripts (kevoreilly#2732)
* add docker-compose dev stack, Dockerfile, scripts * feat: resolve comments * Enhance Docker setup with config and DB initialization Update docker-compose.yml to add environment variables for PostgreSQL and mount additional volumes for configuration and storage. Modify run.sh to initialize configuration files and create a Docker-specific database config if not present, improving container startup and environment consistency. --------- Co-authored-by: doomedraven <doommedraven@gmail.com>
1 parent 64b2e06 commit d32d67d

File tree

7 files changed

+204
-0
lines changed

7 files changed

+204
-0
lines changed

.dockerignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Docker
7+
docker-compose.yml
8+
Dockerfile
9+
.dockerignore
10+
11+
# DB
12+
mongodata
13+
pgdata
14+
*.db
15+
*.sqlite3
16+
17+
# Python
18+
__pycache__
19+
*.py[cod]
20+
*$py.class
21+
*.so
22+
.Python
23+
*.egg
24+
*.egg-info
25+
dist
26+
build
27+
.eggs
28+
.venv
29+
venv
30+
env
31+
32+
# IDE
33+
.vscode
34+
.idea
35+
*.swp
36+
*.swo
37+
*~
38+
39+
# Logs
40+
*.log
41+
logs
42+
43+
# OS
44+
.DS_Store
45+
Thumbs.db
46+
47+
# Others
48+
.env.local
49+
.cache
50+
tmp
51+
temp

docker/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
WEB_PORT=8000
2+
RESULT_PORT=2042
3+
PG_PORT=5432
4+
MONGO_PORT=27017
5+
6+
POSTGRES_USER=cape
7+
POSTGRES_PASSWORD=cape
8+
POSTGRES_DB=cape

docker/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM python:3.11-bookworm
2+
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends git libgraphviz-dev tcpdump libcap2-bin iproute2 libjansson-dev libmagic-dev \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
RUN useradd -ms /bin/bash cape
8+
9+
RUN pip install --no-cache-dir poetry
10+
11+
RUN poetry config virtualenvs.create false
12+
13+
RUN mkdir -p /etc/poetry/bin && ln -s $(which poetry) /etc/poetry/bin/poetry
14+
RUN mkdir -p /opt && ln -s /cape /opt/CAPEv2
15+
16+
WORKDIR /cape
17+
18+
COPY pyproject.toml poetry.lock* ./
19+
20+
RUN poetry install --no-interaction --no-ansi --no-root
21+
22+
COPY . .
23+
24+
RUN poetry install --no-interaction --no-ansi
25+
26+
RUN pip install --no-cache-dir -U flare-floss
27+
RUN bash extra/yara_installer.sh
28+
29+
RUN bash docker/pcap.sh
30+
31+
RUN bash conf/copy_configs.sh
32+
RUN chown -R cape:cape /cape
33+
34+
USER cape
35+
36+
CMD ["bash", "docker/run.sh"]

docker/docker-compose.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
services:
2+
cape-db:
3+
image: postgres:bookworm
4+
hostname: cape-db
5+
restart: unless-stopped
6+
ports:
7+
- "127.0.0.1:${PG_PORT:-5432}:5432"
8+
environment:
9+
POSTGRES_USER: ${POSTGRES_USER:-cape}
10+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-cape}
11+
POSTGRES_DB: ${POSTGRES_DB:-cape}
12+
PGDATA: /var/lib/postgresql/data/pgdata
13+
volumes:
14+
- cape-db-data:/var/lib/postgresql/data
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-cape} -d ${POSTGRES_DB:-cape}"]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 10
20+
start_period: 30s
21+
22+
mongodb:
23+
image: mongo:6
24+
command: ["--bind_ip_all"]
25+
volumes:
26+
- cape-mongo-data:/data/db
27+
ports:
28+
- "127.0.0.1:${MONGO_PORT:-27017}:27017"
29+
restart: unless-stopped
30+
healthcheck:
31+
test: ["CMD", "mongosh", "--eval", "db.runCommand({ ping: 1 })"]
32+
interval: 10s
33+
timeout: 5s
34+
retries: 12
35+
start_period: 20s
36+
37+
cape-server:
38+
build:
39+
context: ../
40+
dockerfile: docker/Dockerfile
41+
hostname: cape-server
42+
restart: unless-stopped
43+
depends_on:
44+
cape-db:
45+
condition: service_healthy
46+
mongodb:
47+
condition: service_healthy
48+
environment:
49+
- WEB_PORT=${WEB_PORT:-8000}
50+
- POSTGRES_USER=${POSTGRES_USER:-cape}
51+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-cape}
52+
- POSTGRES_DB=${POSTGRES_DB:-cape}
53+
ports:
54+
- "127.0.0.1:${RESULT_PORT:-2042}:2042" # result server
55+
- "127.0.0.1:${WEB_PORT:-8000}:8000" # web ui
56+
volumes:
57+
- ../conf:/cape/conf
58+
- ../custom/conf:/cape/custom/conf
59+
- ../custom:/cape/custom
60+
- ../storage:/cape/storage
61+
cap_add:
62+
- NET_ADMIN
63+
- NET_RAW
64+
65+
volumes:
66+
cape-db-data:
67+
cape-mongo-data:

docker/pcap.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
groupadd pcap
2+
usermod -a -G pcap cape
3+
chgrp pcap /usr/bin/tcpdump
4+
setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump

docker/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is not official docker soluction!
2+
Is community based contribution so use on your own risks!
3+
4+
No support here from core devs!

docker/run.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -e
3+
4+
cd /cape
5+
6+
# Initialize configs if mounted volume is empty
7+
if [ ! -f "conf/cuckoo.conf" ]; then
8+
echo "Initializing configuration files..."
9+
bash conf/copy_configs.sh
10+
fi
11+
12+
# Configure Database connection for Docker environment
13+
mkdir -p conf/cuckoo.conf.d
14+
DB_CONF="conf/cuckoo.conf.d/00_docker_db.conf"
15+
if [ ! -f "$DB_CONF" ]; then
16+
echo "Creating Docker DB configuration..."
17+
cat > "$DB_CONF" <<EOF
18+
[database]
19+
connection = postgresql://${POSTGRES_USER:-cape}:${POSTGRES_PASSWORD:-cape}@cape-db:5432/${POSTGRES_DB:-cape}
20+
EOF
21+
fi
22+
23+
cd web
24+
python manage.py migrate
25+
cd ..
26+
27+
python cuckoo.py &
28+
CUCKOO_PID=$!
29+
30+
cd web
31+
32+
: "${WEB_PORT:=8000}"
33+
34+
python manage.py runserver 0.0.0.0:${WEB_PORT}

0 commit comments

Comments
 (0)