diff --git a/.dockerignore b/.dockerignore index 27077efc..09a31677 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,3 +6,4 @@ !Pipfile.lock !lokbot !config.example.json +!docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 5ad9a8b8..55d9ec28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,6 @@ ENV PATH="/app/.venv/bin:$PATH" HEALTHCHECK --retries=1 \ CMD if grep -q Exception /app/data/output.log; then exit 1; else exit 0; fi -ENTRYPOINT ["/bin/sh", "-c", "python -m lokbot $TOKEN $CAPTCHA_SOLVER_CONFIG 2>&1 | tee -a data/output.log"] +ENTRYPOINT ["/app/docker-entrypoint.sh"] + +CMD ["/bin/sh", "-c", "python -m lokbot $TOKEN $CAPTCHA_SOLVER_CONFIG 2>&1 | tee -a /app/data/output.log"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..15b93c4b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +set -e + +DATA_FOLDER=/app/data +OUTPUT_LOG_FILE=$DATA_FOLDER/output.log + +# if the output log file exists, backup it with timestamp suffix +if [ -f "$OUTPUT_LOG_FILE" ]; then + mv $OUTPUT_LOG_FILE $OUTPUT_LOG_FILE.$(date +%Y%m%d%H%M%S) +else + mkdir -p $DATA_FOLDER + touch $OUTPUT_LOG_FILE +fi + +exec "$@"