diff --git a/docker/Dockerfile b/docker/Dockerfile --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,6 +21,7 @@ ngrep \ rsync \ nodejs \ + cron \ yarn && \ apt-get install -y --no-install-recommends \ r-base-core \ @@ -29,6 +30,8 @@ rm -rf /var/lib/apt/lists/* RUN useradd -md /srv/softwareheritage -s /bin/bash swh +RUN echo swh >> /etc/cron.allow +RUN cron -f & USER swh RUN python3 -m venv /srv/softwareheritage/venv diff --git a/docker/Dockerfile.cron b/docker/Dockerfile.cron new file mode 100644 --- /dev/null +++ b/docker/Dockerfile.cron @@ -0,0 +1,13 @@ +FROM swh/stack + +USER root + +RUN apt-get update && apt-get install -y cron + +COPY ./services/swh-web/refresh-savecodenow-statuses /usr/local/bin/ +COPY ./services/swh-web/refresh-savecodenow-statuses.cron /etc/cron.d/ + +RUN touch /var/log/refresh-statuses.log && \ + chmod 0755 /usr/local/bin/refresh-savecodenow-statuses && \ + chmod 0644 /etc/cron.d/refresh-savecodenow-statuses.cron && \ + crontab /etc/cron.d/refresh-savecodenow-statuses.cron diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -240,6 +240,16 @@ volumes: - "./conf/web.yml:/web.yml:ro" - "./services/swh-web/entrypoint.sh:/entrypoint.sh:ro" + - "./services/swh-web/refresh-savecodenow-statuses.cron:/etc/cron.d/refresh-savecodenow-statuses.cron" + + swh-web-cron: + build: ./ + image: swh/cron + depends_on: + - swh-web + entrypoint: ["cron", "-f"] + volumes: + - "./conf/web.yml:/web.yml:ro" swh-deposit-db: image: postgres:12 diff --git a/docker/services/swh-web/entrypoint.sh b/docker/services/swh-web/entrypoint.sh --- a/docker/services/swh-web/entrypoint.sh +++ b/docker/services/swh-web/entrypoint.sh @@ -40,6 +40,10 @@ popd fi + # Trigger periodic update of save code now status + crontab -u swh /etc/cron.d/refresh-savecodenow-statuses.cron + crontab -u swh -l + echo "Migrating db using ${DJANGO_SETTINGS_MODULE}" django-admin migrate --settings=${DJANGO_SETTINGS_MODULE} diff --git a/docker/services/swh-web/refresh-savecodenow-statuses.cron b/docker/services/swh-web/refresh-savecodenow-statuses.cron new file mode 100644 --- /dev/null +++ b/docker/services/swh-web/refresh-savecodenow-statuses.cron @@ -0,0 +1 @@ +* * * * * (date && /srv/softwareheritage/venv/bin/django-admin refresh_savecodenow_statuses 2>&1) >> /tmp/refresh-statuses.log