From 9b9002e751435b1ce8f66e2a09ebd9cb42cd5b02 Mon Sep 17 00:00:00 2001 From: Chris Kiriakou Date: Wed, 19 Mar 2025 16:56:23 +0100 Subject: [PATCH 1/2] Create a custom Dockerfile to decouple application dependencies from host. * Create a dockerfile based on alpine. * Create a start script to startup scraper. --- Dockerfile | 18 ++++++++++++++++++ startup.sh | 14 ++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Dockerfile create mode 100644 startup.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79f2a03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM alpine:latest + +WORKDIR /root + +RUN apk update && \ + apk add --no-cache \ + openssh \ + python3 \ + sqlite \ + pip \ + +EXPOSE 80 +EXPOSE 22 + +VOLUME /root/data +VOLUME /root/app + +ENTRYPOINT /root/startup.sh; diff --git a/startup.sh b/startup.sh new file mode 100644 index 0000000..7915cf1 --- /dev/null +++ b/startup.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Starup the predictify scraper + +if test -f ./requirements.txt +then + pip install -r ./requirements.txt +else + printf "Missing requirements file! aborting...\n" + exit 1 +fi + +python3 ./src/scraper.py + From 3fe19fd41f93c0f399d8d1aa86c8e8c4c9d99b02 Mon Sep 17 00:00:00 2001 From: Chris Kiriakou Date: Wed, 19 Mar 2025 20:54:13 +0100 Subject: [PATCH 2/2] Fix Dockerfile. --- Dockerfile | 28 +++++++++++++++++----------- startup.sh | 6 +++--- 2 files changed, 20 insertions(+), 14 deletions(-) mode change 100644 => 100755 startup.sh diff --git a/Dockerfile b/Dockerfile index 79f2a03..45f0f04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,24 @@ FROM alpine:latest -WORKDIR /root +WORKDIR /root -RUN apk update && \ - apk add --no-cache \ - openssh \ - python3 \ - sqlite \ - pip \ +RUN apk update && \ + apk add --no-cache \ + openssh \ + python3 \ + py3-pip \ + sqlite -EXPOSE 80 EXPOSE 22 -VOLUME /root/data -VOLUME /root/app +RUN mkdir /root/src -ENTRYPOINT /root/startup.sh; +COPY ./startup.sh /root +COPY ./requirements.txt /root +COPY ./src/ /root/src/ + +RUN ls -la + +VOLUME /root + +ENTRYPOINT ["/bin/sh", "/root/startup.sh"] diff --git a/startup.sh b/startup.sh old mode 100644 new mode 100755 index 7915cf1..5fb7fd1 --- a/startup.sh +++ b/startup.sh @@ -4,11 +4,11 @@ if test -f ./requirements.txt then - pip install -r ./requirements.txt + python3 -m venv .venv + .venv/bin/pip install -r ./requirements.txt else printf "Missing requirements file! aborting...\n" exit 1 fi -python3 ./src/scraper.py - +.venv/bin/python3 src/scraper.py