Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixing docker build #598

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +38 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awkward that we have those tests folders being required during runtime.


# 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"]