Skip to content

Commit

Permalink
Merge pull request #84 from rv2931/docker_various_fixes
Browse files Browse the repository at this point in the history
Docker various fixes
  • Loading branch information
RonanMorgan authored Feb 25, 2024
2 parents 8038003 + 77fa996 commit 0aa29f0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion alembic/init_script/load_amp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
engine = create_engine(db_url, echo=False)

df = pd.read_csv(
Path.joinpath(Path.cwd(), "data/zones_subset_02022024.csv"),
Path(os.path.dirname(__file__)).joinpath("../../data/zones_subset_02022024.csv"),
sep=",",
)

Expand Down
2 changes: 1 addition & 1 deletion alembic/init_script/load_positions_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
engine = create_engine(db_url)

df = pd.read_csv(
Path.joinpath(Path.cwd(), "data/spire_positions_subset_02022024.csv"),
Path(os.path.dirname(__file__)).joinpath("../../data/spire_positions_subset_02022024.csv"),
sep=","
)

Expand Down
2 changes: 1 addition & 1 deletion alembic/init_script/load_vessels_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
engine = create_engine(db_url)
df = pd.read_csv(
Path.joinpath(Path.cwd(), "data/chalutiers_pelagiques.csv"),
Path(os.path.dirname(__file__)).joinpath("../../data/chalutiers_pelagiques.csv"),
sep=";",
dtype={"loa": float, "IMO": str},
)
Expand Down
13 changes: 9 additions & 4 deletions docker-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM python:3.10-slim-bullseye

RUN apt-get update
RUN apt-get -y install wget
RUN apt-get -y install wget gcc g++
RUN apt-get install -y rsyslog

# Define working directory
WORKDIR /source_code
COPY bloom/ ./bloom/
COPY data/ ./data/
COPY app.py .
COPY container.py .
COPY docker-env/rsyslog.conf /etc/rsyslog.conf

# Install requirements package for python with poetry
Expand Down Expand Up @@ -38,7 +39,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install -y
&& rm -rf /etc/cron.*/*

# Create cron task inside container
RUN echo '*/15 * * * * /venv/bin/python3 /source_code/app.py 2>&1 | /usr/bin/logger -t bloom' >> ./cron_scrapper
# Due to the fact that cron process doesn't access to declared ENV vars and doesn't load user profiles
# The entrypoint.sh script stores ENV vars at runtime in the ~/.env file as key=value pairs
# Then the cron line include some command to load these ENV vars from file before launching app.py
# This mecanism allows to give access to the same ENV vars for app.py launch in terminal and launch via cron
RUN echo "*/15 * * * * root export \$(cat ~/.env | grep -v '#' | xargs);/venv/bin/python3 /source_code/app.py 2>&1 | /usr/bin/logger -t bloom" >> ./cron_scrapper
RUN chmod 744 ./cron_scrapper

# Move cron tab into the right directory
Expand All @@ -50,8 +55,8 @@ RUN crontab /etc/cron.d/cron_scrapper
COPY docker-env/entrypoint.sh /entrypoint.sh
RUN ["chmod", "+x", "/entrypoint.sh"]

#ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
# https://manpages.ubuntu.com/manpages/trusty/man8/cron.8.html
# -f | Stay in foreground mode, don't daemonize.
# -L loglevel | Tell cron what to log about jobs (errors are logged regardless of this value) as the sum of the following values:
#CMD ["cron","-f", "-L", "2"]
CMD ["cron","-f", "-L", "2"]
7 changes: 7 additions & 0 deletions docker-env/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

cat /source_code/.env >> /etc/environment

# Store all APP_BLOOM ENV variables to local file accessible to current user to share them with cron task
# Due to the fact that cron process doesn't access to declared ENV vars and doesn't load user profiles
# The entrypoint.sh script stores ENV vars at runtime in the ~/.env file as key=value pairs
# Then the cron line include some command to load these ENV vars from file before launching app.py
# This mecanism allows to give access to the same ENV vars for app.py launch in terminal and launch via cron
env | egrep '^(POSTGRES_.*|SPIRE_TOKEN.*)' > ~/.env

/etc/init.d/rsyslog restart

ln -sf /dev/stdout /var/log/syslog
Expand Down

0 comments on commit 0aa29f0

Please sign in to comment.