diff --git a/BankServices/RoutineEmailService/Dockerfile b/BankServices/RoutineEmailService/Dockerfile index 9793e43..37698b5 100644 --- a/BankServices/RoutineEmailService/Dockerfile +++ b/BankServices/RoutineEmailService/Dockerfile @@ -20,9 +20,6 @@ COPY /BankServices/RoutineEmailService / # Make run_app.sh executable RUN chmod +x /run_app.sh -# 11:00 Istanbul Time (UTC+3) system time is 08:00 UTC -RUN echo "0 8 * * * /run_app.sh >> /var/log/cron.log 2>&1" > /tmp/crontab_list && crontab /tmp/crontab_list - COPY /Schemas /Schemas COPY /Controllers /Controllers COPY /BankServices/ServiceDepends / @@ -33,5 +30,8 @@ ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 # Create log file to grab cron logs RUN touch /var/log/cron.log -# Run cron setup and tail the log file for user to monitor logs -CMD cron && tail -f /var/log/cron.log +# Make entrypoint script executable +RUN chmod +x /entrypoint.sh + +# Use entrypoint script to update run_app.sh with environment variables and start cron +ENTRYPOINT ["/entrypoint.sh"] diff --git a/BankServices/RoutineEmailService/entrypoint.sh b/BankServices/RoutineEmailService/entrypoint.sh new file mode 100644 index 0000000..8f4bbaf --- /dev/null +++ b/BankServices/RoutineEmailService/entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Create environment file that will be available to cron jobs +echo "# Environment variables for cron jobs" > /env.sh +echo "EMAIL_HOST=\"$EMAIL_HOST\"" >> /env.sh +echo "EMAIL_USERNAME=\"$EMAIL_USERNAME\"" >> /env.sh +echo "EMAIL_PASSWORD=\"$EMAIL_PASSWORD\"" >> /env.sh +echo "EMAIL_PORT=$EMAIL_PORT" >> /env.sh +echo "EMAIL_SEND=$EMAIL_SEND" >> /env.sh +echo "DB_HOST=\"$DB_HOST\"" >> /env.sh +echo "DB_USER=\"$DB_USER\"" >> /env.sh +echo "DB_PASSWORD=\"$DB_PASSWORD\"" >> /env.sh +echo "DB_PORT=$DB_PORT" >> /env.sh +echo "DB_NAME=\"$DB_NAME\"" >> /env.sh + +# Add Python environment variables +echo "PYTHONPATH=/" >> /env.sh +echo "PYTHONUNBUFFERED=1" >> /env.sh +echo "PYTHONDONTWRITEBYTECODE=1" >> /env.sh + +# Make the environment file available to cron +echo "0 8 * * * . /env.sh && /run_app.sh >> /var/log/cron.log 2>&1" > /tmp/crontab_list +crontab /tmp/crontab_list + +# Start cron +cron + +# Tail the log file +tail -f /var/log/cron.log diff --git a/BankServices/RoutineEmailService/run_app.sh b/BankServices/RoutineEmailService/run_app.sh index 75c30eb..8a05648 100644 --- a/BankServices/RoutineEmailService/run_app.sh +++ b/BankServices/RoutineEmailService/run_app.sh @@ -10,5 +10,10 @@ export DB_PASSWORD="${DB_PASSWORD}" export DB_PORT=${DB_PORT} export DB_NAME="${DB_NAME}" +# Python environment variables +export PYTHONPATH=/ +export PYTHONUNBUFFERED=1 +export PYTHONDONTWRITEBYTECODE=1 + env >> /var/log/cron.log /usr/local/bin/python /app.py \ No newline at end of file