From 381b4ba7ffb31891288eaa7cb81c988541e97a82 Mon Sep 17 00:00:00 2001 From: Heiko Joerg Schick Date: Wed, 30 Aug 2023 14:16:25 +0200 Subject: [PATCH] Minor changes in Docker container --- Dockerfile | 40 +++++++++++++++++++++++++++++++--------- cron.sh | 10 ++++++++++ cronjob | 24 ++++++++++++++++++++++++ entrypoint.sh | 7 +++++++ requirements.txt | 3 ++- 5 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 cron.sh diff --git a/Dockerfile b/Dockerfile index ce1f3dd..e20bc8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,20 @@ ENV PYTHONDONTWRITEBYTECODE=1 # the application crashes without emitting any logs due to buffering. ENV PYTHONUNBUFFERED=1 -# Install additional binary packages. +# Install required binary packages. +RUN apt-get update && apt-get install -y \ + imagemagick \ + && rm -rf /var/lib/apt/lists/* + +# Add PDF processing to the ImageMagic policy. +RUN sed -i 's///g' /etc/ImageMagick-6/policy.xml + +# DEBUG. Only for debug purposes. RUN apt-get update && apt-get install -y \ curl \ + procps \ + sudo \ + vim \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -24,14 +35,22 @@ WORKDIR /app # Create a non-privileged user that the app will run under. # See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - appuser +#RUN adduser \ +# --disabled-password \ +# --gecos "" \ +# --home "/nonexistent" \ +# --shell "/sbin/nologin" \ +# --no-create-home \ +# --uid "${UID}" \ +# appuser + +# DEBUG. Only for debug purposes. +RUN useradd -r -u ${UID} -s /sbin/nologin -d /nonexistent appuser +RUN echo "appuser:12345678" | chpasswd +RUN echo 'appuser ALL=(ALL) NOPASSWD:ALL' | tee -a /etc/sudoers + +# Upgrade pip +RUN python -m pip install --upgrade pip # Download dependencies as a separate step to take advantage of Docker's caching. # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. @@ -47,6 +66,9 @@ USER appuser # Copy the source code into the container. COPY --chown=appuser . . +# Change file mode(s). +RUN chmod 0744 cron.sh + # Expose the port that the application listens on. EXPOSE 5000 diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..8ba2dc1 --- /dev/null +++ b/cron.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +python3 /app/arxiv_daemon.py --num 100 + +if [ $? -eq 0 ]; then + echo "New papers detected! Running compute.py" + python3 /app/compute.py +else + echo "No new papers were added, skipping feature computation" +fi diff --git a/cronjob b/cronjob index e69de29..4223015 100644 --- a/cronjob +++ b/cronjob @@ -0,0 +1,24 @@ +# Edit this file to introduce tasks to be run by cron. +# +# Each task to run has to be defined through a single line +# indicating with different fields when the task will be run +# and what command to run for the task +# +# To define the time you can provide concrete values for +# minute (m), hour (h), day of month (dom), month (mon), +# and day of week (dow) or use '*' in these fields (for 'any').# +# Notice that tasks will be started based on the cron's system +# daemon's notion of time and timezones. +# +# Output of the crontab jobs (including errors) is sent through +# email to the user the crontab file belongs to (unless redirected). +# +# For example, you can run a backup of all your user accounts +# at 5 a.m every week with: +# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ +# +# For more information see the manual pages of crontab(5) and cron(8) +# +# m h dom mon dow command +*/1 * * * * /app/cron.sh +*/1 * * * * echo Hello diff --git a/entrypoint.sh b/entrypoint.sh index e69de29..0ad2ecf 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "Docker container has been started" + +cron && tail -f /var/log/cron.log +export FLASK_APP=serve.py; flask run --host=0.0.0.0 +# sudo crontab cronjob +# sudo cron -f \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a676515..b2ef35a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ feedparser -Flask +flask numpy +requests scikit-learn sqlitedict