You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/04/15 10:14:16 UTC

[incubator-inlong] branch master updated: [INLONG-3734][Audit] Add an initialize database step in Docker container (#3735)

This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new fe66a6851 [INLONG-3734][Audit] Add an initialize database step in Docker container (#3735)
fe66a6851 is described below

commit fe66a6851b72556d3da443eeef848adf7ea60444
Author: Yuanhao Ji <ji...@apache.org>
AuthorDate: Fri Apr 15 18:14:10 2022 +0800

    [INLONG-3734][Audit] Add an initialize database step in Docker container (#3735)
---
 docker/kubernetes/templates/audit-statefulset.yaml |  2 +-
 inlong-audit/audit-docker/Dockerfile               |  2 +-
 inlong-audit/audit-docker/audit-docker.sh          | 13 +++++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docker/kubernetes/templates/audit-statefulset.yaml b/docker/kubernetes/templates/audit-statefulset.yaml
index e8a9f970a..2f9a85e07 100644
--- a/docker/kubernetes/templates/audit-statefulset.yaml
+++ b/docker/kubernetes/templates/audit-statefulset.yaml
@@ -103,7 +103,7 @@ spec:
           {{- end }}
           env:
             - name: JDBC_URL
-              value: "jdbc:mysql://{{ template "inlong.mysql.hostname" . }}:{{ .Values.mysql.port }}/apache_inlong_audit?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&nullCatalogMeansCurrent=true&serverTimezone=GMT%2b8"
+              value: "{{ template "inlong.mysql.hostname" . }}:{{ .Values.mysql.port }}"
             - name: USERNAME
               value: {{ include "inlong.mysql.username" . | quote }}
             - name: PASSWORD
diff --git a/inlong-audit/audit-docker/Dockerfile b/inlong-audit/audit-docker/Dockerfile
index 03c99c2fe..870025546 100644
--- a/inlong-audit/audit-docker/Dockerfile
+++ b/inlong-audit/audit-docker/Dockerfile
@@ -19,7 +19,7 @@
 FROM openjdk:8-jdk
 # add tarball from target output
 RUN apt-get update \
-    && apt-get install -y net-tools vim \
+    && apt-get install -y net-tools vim default-mysql-client \
     && rm -rf /var/lib/apt/lists/*
 ARG AUDIT_TARBALL
 ADD ${AUDIT_TARBALL} /opt/inlong-audit
diff --git a/inlong-audit/audit-docker/audit-docker.sh b/inlong-audit/audit-docker/audit-docker.sh
index 2b0f5a27c..6d264e13f 100644
--- a/inlong-audit/audit-docker/audit-docker.sh
+++ b/inlong-audit/audit-docker/audit-docker.sh
@@ -39,6 +39,19 @@ if [ "${MQ_TYPE}" == "tube" ]; then
   sed -i "s/agent1.sinks.tube-sink-msg2.master-host-port-list = .*$/agent1.sinks.tube-sink-msg2.master-host-port-list = ${TUBE_MASTER_LIST}/g" "${proxy_conf_file}"
 fi
 
+# Whether the database table exists. If it does not exist, initialize the database and skip if it exists.
+if [[ "${JDBC_URL}" =~ (.+):([0-9]+) ]]; then
+  datasource_hostname=${BASH_REMATCH[1]}
+  datasource_port=${BASH_REMATCH[2]}
+
+  select_db_sql="SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'apache_inlong_audit'"
+  inlong_audit_count=$(mysql -h${datasource_hostname} -P${datasource_port} -u${USERNAME} -p${PASSWORD} -e "${select_db_sql}")
+  inlong_num=$(echo "$inlong_audit_count" | tr -cd "[0-9]")
+  if [ $inlong_num -eq 0 ]; then
+    mysql -h${datasource_hostname} -P${datasource_port} -u${USERNAME} -p${PASSWORD} < sql/apache_inlong_audit.sql
+  fi
+fi
+
 # start
 bash +x ${file_path}/bin/proxy-start.sh
 bash +x ${file_path}/bin/store-start.sh