Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

WIP: Use multistage build for docker image (#1005)

Leo Trubachcec332d1bba7
diff --git a/.dockerignore b/.dockerignore
index 9b3529f5..429b6c1a 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -2,3 +2,4 @@ venv/
cache/
spiderfoot.db*
+*.log
diff --git a/Dockerfile b/Dockerfile
index 31e1f606..0dcda94c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -27,41 +27,48 @@
# sudo docker run --rm spiderfoot sf.py -h
#
# Running spiderfoot unit tests in container
-#
-# sudo docker run --rm spiderfoot -m unittest discover -s test/unit
+# sudo docker build -t spiderfoot-test --build-arg REQUIREMENTS=requirements_test.txt .
+# sudo docker run --rm spiderfoot-test -m pytest --flake8 .
-# Pull the base image.
-FROM alpine:3.9.6
+FROM alpine:3.9.6 AS build
+ARG REQUIREMENTS=requirements.txt
+RUN apk add --no-cache gcc git curl python3 python3-dev py3-pip swig tinyxml-dev \
+ python3-dev musl-dev openssl-dev libffi-dev libxslt-dev libxml2-dev jpeg-dev \
+ openjpeg-dev zlib-dev
+RUN python3 -m venv /opt/venv
+ENV PATH="/opt/venv/bin":$PATH
+COPY $REQUIREMENTS requirements.txt ./
+RUN ls
+RUN echo "$REQUIREMENTS"
+RUN pip3 install -r "$REQUIREMENTS"
-WORKDIR /home/spiderfoot
+
+FROM alpine:3.9.6
+WORKDIR /home/spiderfoot
# Place database and configs outside installation directory
ENV SPIDERFOOT_DATA /var/lib/spiderfoot
-COPY requirements.txt .
-
# Run everything as one command so that only one layer is created
-RUN apk --update add --no-cache --virtual build-dependencies gcc git curl py3-pip swig \
- tinyxml-dev python3-dev musl-dev openssl-dev libffi-dev libxslt-dev \
- && apk --update --no-cache add python3 musl openssl libxslt tinyxml jpeg-dev openjpeg-dev zlib-dev \
- && pip3 --no-cache-dir install wheel \
- && pip3 --no-cache-dir install -r requirements.txt \
+RUN apk --update --no-cache add python3 musl openssl libxslt tinyxml libxml2 jpeg zlib openjpeg \
&& addgroup spiderfoot \
&& adduser -G spiderfoot -h /home/spiderfoot -s /sbin/nologin \
-g "SpiderFoot User" -D spiderfoot \
- && apk del --purge build-dependencies \
&& rm -rf /var/cache/apk/* \
&& rm -rf /lib/apk/db \
&& rm -rf /root/.cache \
&& mkdir $SPIDERFOOT_DATA \
- && chown spiderfoot:spiderfoot /var/lib/spiderfoot
+ && chown spiderfoot:spiderfoot $SPIDERFOOT_DATA
+
+COPY --from=build /opt/venv /opt/venv
+ENV PATH="/opt/venv/bin:$PATH"
USER spiderfoot
EXPOSE 5001
# Run the application.
-ENTRYPOINT ["/usr/bin/python3"]
+ENTRYPOINT ["/opt/venv/bin/python"]
CMD ["sf.py", "-l", "0.0.0.0:5001"]
COPY . .