From 352aeecf27116d4df166bf82566151c86dfdf9ec Mon Sep 17 00:00:00 2001 From: Artem Morozov Date: Tue, 25 Apr 2023 23:01:35 +0300 Subject: [PATCH 1/4] Delete print-files after week. --- Dockerfile | 7 ++++++- prestart.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 prestart.sh diff --git a/Dockerfile b/Dockerfile index d063797..9d88725 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV APP_NAME=print_service ENV APP_MODULE=${APP_NAME}.routes.base:app COPY ./requirements.txt /app/ -RUN pip install -U -r /app/requirements.txt +RUN apt-get update && apt-get -y install cron && pip install -U -r /app/requirements.txt COPY ./static /app/static/ @@ -15,3 +15,8 @@ COPY ./logging_test.conf /app/ COPY ./migrations /migrations/ COPY ./${APP_NAME} /app/${APP_NAME} + +COPY ./prestart.sh /app/prestart.sh +RUN (crontab -l 2>/dev/null; echo \ + "* * * * * find /app/static -type f -name $(date -d '-7' days --iso)'*' -print -delete>> /var/log/cron.log 2>&1"\ + ) | crontab - diff --git a/prestart.sh b/prestart.sh new file mode 100644 index 0000000..075585a --- /dev/null +++ b/prestart.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +#set -e +# +## переносим значения переменных из текущего окружения +#env | while read -r LINE; do # читаем результат команды 'env' построчно +# # делим строку на две части, используя в качестве разделителя "=" (см. IFS) +# IFS="=" read VAR VAL <<< ${LINE} +# # удаляем все предыдущие упоминания о переменной, игнорируя код возврата +# sed --in-place "/^${VAR}/d" /etc/security/pam_env.conf || true +# # добавляем определение новой переменной в конец файла +# echo "${VAR} DEFAULT=\"${VAL}\"" >> /etc/security/pam_env.conf +#done + +cron + +exec "$@" + From 9398049c3b1806999191c0e74918983fa3c753e8 Mon Sep 17 00:00:00 2001 From: Artem Morozov Date: Tue, 25 Apr 2023 23:45:47 +0300 Subject: [PATCH 2/4] Delete print-files after week. --- Dockerfile | 4 +--- prestart.sh | 14 ++------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d88725..0d62e68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,4 @@ COPY ./migrations /migrations/ COPY ./${APP_NAME} /app/${APP_NAME} COPY ./prestart.sh /app/prestart.sh -RUN (crontab -l 2>/dev/null; echo \ - "* * * * * find /app/static -type f -name $(date -d '-7' days --iso)'*' -print -delete>> /var/log/cron.log 2>&1"\ - ) | crontab - +RUN diff --git a/prestart.sh b/prestart.sh index 075585a..95be870 100644 --- a/prestart.sh +++ b/prestart.sh @@ -1,17 +1,7 @@ #!/usr/bin/env bash -#set -e -# -## переносим значения переменных из текущего окружения -#env | while read -r LINE; do # читаем результат команды 'env' построчно -# # делим строку на две части, используя в качестве разделителя "=" (см. IFS) -# IFS="=" read VAR VAL <<< ${LINE} -# # удаляем все предыдущие упоминания о переменной, игнорируя код возврата -# sed --in-place "/^${VAR}/d" /etc/security/pam_env.conf || true -# # добавляем определение новой переменной в конец файла -# echo "${VAR} DEFAULT=\"${VAL}\"" >> /etc/security/pam_env.conf -#done + +echo "* * * * * find /app/static -type f -name \$(date -d \"-$STORAGE_TIME days\" --iso)\"*\" -delete" | crontab - cron exec "$@" - From 872a17d17f1aec3f4e9deffddd12f5c4f46be82c Mon Sep 17 00:00:00 2001 From: Artem Morozov Date: Tue, 25 Apr 2023 23:51:23 +0300 Subject: [PATCH 3/4] Delete print-files after week. --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0d62e68..8599091 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,3 @@ COPY ./migrations /migrations/ COPY ./${APP_NAME} /app/${APP_NAME} COPY ./prestart.sh /app/prestart.sh -RUN From ef64cbec1c553f31512a21e57fa9fe9ad8ae15ff Mon Sep 17 00:00:00 2001 From: Artem Morozov Date: Wed, 26 Apr 2023 00:02:35 +0300 Subject: [PATCH 4/4] Delete print-files after week. --- .github/workflows/build_and_publish.yml | 2 ++ Dockerfile | 3 +-- prestart.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 85309c5..cdaac9b 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -107,6 +107,7 @@ jobs: --env GUNICORN_CMD_ARGS='--log-config logging_test.conf' \ --env ALLOW_STUDENT_NUMBER=true \ --env STATIC_FOLDER=/app/static \ + --env STORAGE_TIME=30 \ --env AUTH_URL=https://auth.api.test.profcomff.com/ \ --name ${{ env.CONTAITER_NAME }} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test @@ -172,6 +173,7 @@ jobs: --env GUNICORN_CMD_ARGS='--log-config logging_prod.conf' \ --env ALLOW_STUDENT_NUMBER=true \ --env STATIC_FOLDER=/app/static \ + --env STORAGE_TIME=168 \ --env AUTH_URL=https://auth.api.profcomff.com/ \ --name ${{ env.CONTAITER_NAME }} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest diff --git a/Dockerfile b/Dockerfile index 8599091..c0c67cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,6 @@ COPY ./alembic.ini /alembic.ini COPY ./logging_prod.conf /app/ COPY ./logging_test.conf /app/ COPY ./migrations /migrations/ +COPY ./prestart.sh /app/prestart.sh COPY ./${APP_NAME} /app/${APP_NAME} - -COPY ./prestart.sh /app/prestart.sh diff --git a/prestart.sh b/prestart.sh index 95be870..ebf4e13 100644 --- a/prestart.sh +++ b/prestart.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo "* * * * * find /app/static -type f -name \$(date -d \"-$STORAGE_TIME days\" --iso)\"*\" -delete" | crontab - +echo "0 */1 * * * find $STATIC_FOLDER -type f -name \$(date -d \"-$STORAGE_TIME hours\" --iso)\"*\" -delete" | crontab - cron