diff --git a/.env.example b/.env.example index e210892..fe4e910 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,4 @@ DATABASE_PORT=3306 DATABASE_NAME=database DATABASE_USERNAME=user DATABASE_PASSWORD=password +DATABASE_SSL_MODE=REQUIRED diff --git a/Dockerfile b/Dockerfile index 9e8f202..3ee08ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,16 @@ FROM docker.elastic.co/logstash/logstash-oss:8.13.4 USER root -RUN apt-get update && apt-get install -y mariadb-client -RUN curl -O -L https://dlm.mariadb.com/3824147/Connectors/java/connector-java-3.4.0/mariadb-java-client-3.4.0.jar +RUN apt-get update && apt-get install -y mysql-client +RUN curl -O -L https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-9.1.0.tar.gz +RUN tar -zxvf mysql-connector-j-9.1.0.tar.gz RUN bin/logstash-plugin install logstash-output-opensearch USER 1000 -ENV JDBC_DRIVER_LIBRARY=/usr/share/logstash/mariadb-java-client-3.4.0.jar -ENV JDBC_DRIVER_CLASS=org.mariadb.jdbc.Driver -ENV JDBC_DRIVER_DATABASE=mariadb +ENV JDBC_DRIVER_LIBRARY=/usr/share/logstash/mysql-connector-j-9.1.0/mysql-connector-j-9.1.0.jar +ENV JDBC_DRIVER_CLASS=com.mysql.cj.jdbc.Driver +ENV JDBC_DRIVER_DATABASE=mysql COPY --chown=1000 config /usr/share/logstash/config COPY --chown=1000 pipeline /usr/share/logstash/pipeline diff --git a/docker-compose.yaml b/docker-compose.yaml index 17dae0b..6663fc2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,6 +10,7 @@ services: - DATABASE_NAME=${DATABASE_NAME} - DATABASE_USERNAME=${DATABASE_USERNAME} - DATABASE_PASSWORD=${DATABASE_PASSWORD} + - DATABASE_SSL_MODE=${DATABASE_SSL_MODE} volumes: - data:/usr/share/logstash/data extra_hosts: diff --git a/entrypoint.sh b/entrypoint.sh index 325e39a..c12bb87 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,7 @@ set -euo pipefail export DATABASE_PORT=${DATABASE_PORT:-3306} +export DATABASE_SSL_MODE=${DATABASE_SSL_MODE:-REQUIRED} cards="'headquarters','company',\ 'metric','source','phrase','wikirate_title','topic','project',\ @@ -14,13 +15,14 @@ FROM cards WHERE codename IN ($cards) OR name IN ($cards)" echo -n "Fetching cards from database..." ids=$( - mariadb \ + mysql \ --host=$DATABASE_HOST \ --port=$DATABASE_PORT \ --database=$DATABASE_NAME \ --user=$DATABASE_USERNAME \ --password=$DATABASE_PASSWORD \ --protocol tcp \ + --ssl-mode $DATABASE_SSL_MODE \ --skip-column-names \ --silent \ --execute="$query" diff --git a/pipeline/wikirate.conf b/pipeline/wikirate.conf index 390b409..b3f6fa6 100644 --- a/pipeline/wikirate.conf +++ b/pipeline/wikirate.conf @@ -2,7 +2,7 @@ input { jdbc { jdbc_driver_library => "${JDBC_DRIVER_LIBRARY}" jdbc_driver_class => "${JDBC_DRIVER_CLASS}" - jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}" + jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?sslMode=${DATABASE_SSL_MODE}" jdbc_user => "${DATABASE_USERNAME}" jdbc_password => "${DATABASE_PASSWORD}" last_run_metadata_path => "/usr/share/logstash/data/plugins/inputs/jdbc/logstash_jdbc_last_run_general" @@ -25,7 +25,7 @@ input { jdbc { jdbc_driver_library => "${JDBC_DRIVER_LIBRARY}" jdbc_driver_class => "${JDBC_DRIVER_CLASS}" - jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}" + jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?sslMode=${DATABASE_SSL_MODE}" jdbc_user => "${DATABASE_USERNAME}" jdbc_password => "${DATABASE_PASSWORD}" last_run_metadata_path => "/usr/share/logstash/data/plugins/inputs/jdbc/logstash_jdbc_last_run_metrics" @@ -43,7 +43,7 @@ input { jdbc { jdbc_driver_library => "${JDBC_DRIVER_LIBRARY}" jdbc_driver_class => "${JDBC_DRIVER_CLASS}" - jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}" + jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?sslMode=${DATABASE_SSL_MODE}" jdbc_user => "${DATABASE_USERNAME}" jdbc_password => "${DATABASE_PASSWORD}" last_run_metadata_path => "/usr/share/logstash/data/plugins/inputs/jdbc/logstash_jdbc_last_run_sources" @@ -63,7 +63,7 @@ input { jdbc { jdbc_driver_library => "${JDBC_DRIVER_LIBRARY}" jdbc_driver_class => "${JDBC_DRIVER_CLASS}" - jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}" + jdbc_connection_string => "jdbc:${JDBC_DRIVER_DATABASE}://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?sslMode=${DATABASE_SSL_MODE}" jdbc_user => "${DATABASE_USERNAME}" jdbc_password => "${DATABASE_PASSWORD}" last_run_metadata_path => "/usr/share/logstash/data/plugins/inputs/jdbc/logstash_jdbc_last_run_companies"