-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDockerfile
More file actions
109 lines (80 loc) · 2.48 KB
/
Dockerfile
File metadata and controls
109 lines (80 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Metasploit-AI Framework
# Multi-stage Docker build for production deployment
# Stage 1: Base image with dependencies
FROM python:3.11-slim as base
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
nmap \
netcat-openbsd \
procps \
&& rm -rf /var/lib/apt/lists/*
# Create app user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Set working directory
WORKDIR /app
# Stage 2: Development dependencies
FROM base as development
# Install additional development tools
RUN apt-get update && apt-get install -y \
vim \
tree \
htop \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt requirements-dev.txt ./
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir -r requirements-dev.txt
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p data logs models reports && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose ports
EXPOSE 8080
# Default command for development
CMD ["python", "app.py", "--mode", "web", "--host", "0.0.0.0", "--port", "8080"]
# Stage 3: Production image
FROM base as production
# Copy requirements
COPY requirements.txt ./
# Install only production dependencies
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir gunicorn
# Copy application code
COPY --chown=appuser:appuser . .
# Create necessary directories with proper permissions
RUN mkdir -p data logs models reports && \
chown -R appuser:appuser /app && \
chmod +x scripts/*.sh
# Remove development files
RUN rm -rf tests/ docs/ .git* *.md requirements-dev.txt
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Expose port
EXPOSE 8080
# Production command
CMD ["gunicorn", "--config", "docker/gunicorn.conf.py", "app:app"]
# Stage 4: Testing image
FROM development as testing
# Install additional testing tools
USER root
RUN pip install --no-cache-dir pytest-xdist pytest-cov
USER appuser
# Run tests by default
CMD ["pytest", "tests/", "-v", "--cov=src", "--cov-report=html"]
# Final stage selection
FROM production as final