Skip to content

Commit

Permalink
Switch to MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKostka committed Oct 19, 2024
1 parent 6970520 commit cb1797b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ DATABASE_PORT=3306
DATABASE_NAME=database
DATABASE_USERNAME=user
DATABASE_PASSWORD=password
DATABASE_SSL_MODE=REQUIRED
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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',\
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions pipeline/wikirate.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit cb1797b

Please sign in to comment.