Skip to content

Commit

Permalink
feat: fixing docker build (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
danae-pan authored Dec 24, 2024
1 parent cf90c50 commit 1877c57
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
# Stage 1: Build stage
FROM python:3.8 AS conpot-builder

# Install required dependencies
RUN apt-get update && apt-get install -y \
gcc \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Copy the app from the host folder (probably a cloned repo) to the container
RUN adduser --disabled-password --gecos "" conpot

COPY --chown=conpot:conpot . /opt/conpot/
# Set working directory
WORKDIR /opt/conpot

# Install Conpot
USER conpot
ENV PATH=$PATH:/home/conpot/.local/bin
RUN pip3 install --user --no-cache-dir /opt/conpot
# Copy the source code to the container
COPY . .

# Install specific dependencies
RUN pip3 install --no-cache-dir pysnmp==4.4.12 \
&& pip3 install --no-cache-dir pysmi==0.3.2 \
&& pip3 install --no-cache-dir pyasn1==0.4.8 \
&& pip3 install --no-cache-dir cryptography==3.4.8 \
&& pip3 install --no-cache-dir .

# Run container
# Stage 2: Runtime stage
FROM python:3.8-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN adduser --disabled-password --gecos "" conpot
WORKDIR /home/conpot

COPY --from=conpot-builder --chown=conpot:conpot /home/conpot/.local/ /home/conpot/.local/
# Create required directories and set permissions
RUN mkdir -p /var/log/conpot \
&& mkdir -p /usr/local/lib/python3.8/site-packages/conpot/tests/data/data_temp_fs/ftp \
&& mkdir -p /usr/local/lib/python3.8/site-packages/conpot/tests/data/data_temp_fs/tftp \
&& chown -R conpot:conpot /var/log/conpot \
&& chown -R conpot:conpot /usr/local/lib/python3.8/site-packages/conpot/tests/data

# Set working directory and copy dependencies from build stage
WORKDIR /home/conpot
COPY --from=conpot-builder /usr/local/lib/python3.8/ /usr/local/lib/python3.8/
COPY --from=conpot-builder /usr/local/bin/ /usr/local/bin/

# Create directories
RUN mkdir -p /var/log/conpot/ \
&& mkdir -p /data/tftp/ \
&& chown conpot:conpot /var/log/conpot \
&& chown conpot:conpot -R /data
# Set permissions for non-root user
RUN chown -R conpot:conpot /home/conpot

# Switch to non-root user
USER conpot
WORKDIR /home/conpot
ENV PATH=$PATH:/home/conpot/.local/bin
ENV USER=conpot
ENTRYPOINT ["/home/conpot/.local/bin/conpot"]
CMD ["--template", "default", "--logfile", "/var/log/conpot/conpot.log", "-f", "--temp_dir", "/tmp" ]

# Set the default command
ENTRYPOINT ["conpot"]
CMD ["--template", "default", "--logfile", "/var/log/conpot/conpot.log", "-f", "--temp_dir", "/tmp"]

0 comments on commit 1877c57

Please sign in to comment.