-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (53 loc) · 1.63 KB
/
Copy pathDockerfile
File metadata and controls
67 lines (53 loc) · 1.63 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
# Multi stage build
# Stage 1: build nsjail from source
FROM python:3.12-slim AS nsjail-builder
# Build dependencies for nsjail
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
build-essential \
pkg-config \
libprotobuf-dev \
protobuf-compiler \
libnl-route-3-dev \
libcap-dev \
libseccomp-dev \
flex \
bison \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Clone and build nsjail
RUN git clone https://github.com/google/nsjail.git /tmp/nsjail && \
make -C /tmp/nsjail && \
cp /tmp/nsjail/nsjail /usr/local/bin/nsjail
# Stage 2: Final App image
FROM python:3.12-slim
# Runtime dependencies for nsjail (no compilers here)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
libprotobuf-dev \
libnl-route-3-200 \
libcap2 \
libseccomp2 && \
rm -rf /var/lib/apt/lists/*
# Copy nsjail binary
COPY --from=nsjail-builder /usr/local/bin/nsjail /usr/local/bin/nsjail
# Create app and sandbox directories
RUN mkdir -p /app /sandbox
# Make /app the current working directory
WORKDIR /app
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code and nsjail config
COPY app.py executor.py /app/
COPY nsjail.cfg /etc/nsjail.cfg
# Create a non-root user and give permissions
RUN useradd -m appuser && chown -R appuser /app /sandbox
USER appuser
ENV PYTHONUNBUFFERED=1
# Expose port 8080
EXPOSE 8080
# Start the app with gunicorn
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]