From 237345b476ac497bafabc0c53ba8e3ed97e3d171 Mon Sep 17 00:00:00 2001 From: Tim Evens Date: Wed, 8 Jun 2022 14:53:55 -0700 Subject: [PATCH] Add ENABLE_DBIP to ```psql-app``` container to auto import DB-IP geo data --- docker-compose.yml | 1 + psql-app/Dockerfile | 3 ++- psql-app/scripts/run | 28 ++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2662be0..bdcfae4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -162,6 +162,7 @@ services: - RPKI_USER=None - ENABLE_RPKI=1 # 1 enables, 0 disables RPKI sync - ENABLE_IRR=1 # 1 enables, 0 disables IRR sync + - ENABLE_DBIP=1 # 1 enables, 0 disables DBIP import - POSTGRES_REPORT_WINDOW='8 minute' # default POSTGRESS window to select when building # summary tables. For deployments that absorb large # bursts increase the value, ex 60 minute diff --git a/psql-app/Dockerfile b/psql-app/Dockerfile index e49d2b2..6bd8781 100644 --- a/psql-app/Dockerfile +++ b/psql-app/Dockerfile @@ -53,6 +53,7 @@ COPY --chmod=755 --from=build /ws/cron_scripts/gen-whois/*.py /usr/local/openbm COPY --chmod=755 --from=build /ws/cron_scripts/peeringdb/*.py /usr/local/openbmp/ COPY --chmod=755 --from=build /ws/cron_scripts/rpki/*.py /usr/local/openbmp/ COPY --chmod=755 --from=build /ws/scripts/geo-csv-to-psql.py /usr/local/openbmp/ +COPY --chmod=755 --from=build /ws/scripts/db-ip-import.sh /usr/local/openbmp/ # Add files ADD --chmod=755 obmp-docker/psql-app/scripts/run /usr/sbin/ @@ -86,7 +87,7 @@ RUN apt-get update \ RUN cd /tmp && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ && python3 get-pip.py -RUN pip install ipaddr pykafka click +RUN pip install ipaddr pykafka click netaddr RUN pip3 install urllib3 requests diff --git a/psql-app/scripts/run b/psql-app/scripts/run index 88868a6..14e922f 100755 --- a/psql-app/scripts/run +++ b/psql-app/scripts/run @@ -116,6 +116,25 @@ SETVAR } +# ----------------------------------------------- +# Enable DB-IP import +# ----------------------------------------------- +enable_dbip() { + echo "===> Enabling DB-IP Import" + + cat > /etc/cron.d/openbmp-dbip < /var/log/cron-dbip-import.log + +SETVAR + + # Load DB-IP on start + echo "Running DB-IP Import" + /usr/local/openbmp/db-ip-import.sh > /var/log/cron-dbip-import.log & +} + + # ----------------------------------------------- # Enable IRR # ----------------------------------------------- @@ -256,15 +275,20 @@ source /usr/local/openbmp/pg_profile config_cron rm -f /etc/cron.d/openbmp-rpki -if [[ ${ENABLE_RPKI:-""} != "" ]]; then +if [[ ${ENABLE_RPKI:-""} != "" && $ENABLE_RPKI == 1 ]]; then enable_rpki fi rm -f /etc/cron.d/openbmp-irr -if [[ ${ENABLE_IRR:-""} != "" ]]; then +if [[ ${ENABLE_IRR:-""} != "" && $ENABLE_IRR == 1 ]]; then enable_irr fi +rm -f /etc/cron.d/openbmp-dbip +if [[ ${ENABLE_DBIP:-""} != "" && $ENABLE_DBIP == 1 ]]; then + enable_dbip +fi + initdb_postgres