From 888da5534af373d43d30ac2c3e3d088f67b8a62d Mon Sep 17 00:00:00 2001
From: Vincent Massol <vincent@massol.net>
Date: Mon, 1 Jun 2020 16:33:53 +0200
Subject: [PATCH] XDOCKER-143: Switch to MySQL JDBC driver 8.x

---
 11/mysql-tomcat/Dockerfile    | 13 +++++++++----
 11/postgres-tomcat/Dockerfile |  2 +-
 12/mysql-tomcat/Dockerfile    | 13 +++++++++----
 12/postgres-tomcat/Dockerfile |  2 +-
 template/Dockerfile           | 21 +++++++++++++--------
 5 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/11/mysql-tomcat/Dockerfile b/11/mysql-tomcat/Dockerfile
index 67c823a..cacf3ee 100644
--- a/11/mysql-tomcat/Dockerfile
+++ b/11/mysql-tomcat/Dockerfile
@@ -37,14 +37,13 @@ RUN apt-get update && \
     curl \
     libreoffice \
     unzip \
-    procps \
-    libmysql-java && \
+    procps && \
   rm -rf /var/lib/apt/lists/*
 
 # Install XWiki as the ROOT webapp context in Tomcat
 # Create the Tomcat temporary directory
 # Configure the XWiki permanent directory
-ENV XWIKI_VERSION=11.10.5
+ENV XWIKI_VERSION="11.10.5"
 ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
 ENV XWIKI_DOWNLOAD_SHA256 b08c8a9f0abbbf2bef5c61852688165dd4b2a9a7217da29047647e81c1ec3058
 RUN rm -rf /usr/local/tomcat/webapps/* && \
@@ -56,7 +55,13 @@ RUN rm -rf /usr/local/tomcat/webapps/* && \
   rm -f xwiki.war
 
 # Copy the JDBC driver in the XWiki webapp
-RUN cp /usr/share/java/mysql-connector-java-*.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/
+# For MYSQL, download the MySQL driver version from the Maven Central repository since there's no up to 
+# date Debian repository for it anymore.
+ENV MYSQL_JDBC_VERSION="8.0.20"
+ENV MYSQL_JDBC_PREFIX="https://repo1.maven.org/maven2/mysql/mysql-connector-java/${MYSQL_JDBC_VERSION}"
+ENV MYSQL_JDBC_ARTIFACT="mysql-connector-java-${MYSQL_JDBC_VERSION}.jar"
+ENV MYSQL_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MYSQL_JDBC_ARTIFACT}"
+RUN curl -fSL "${MYSQL_JDBC_PREFIX}/${MYSQL_JDBC_ARTIFACT}" -o $MYSQL_JDBC_TARGET
 
 # Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
 COPY tomcat/setenv.sh /usr/local/tomcat/bin/
diff --git a/11/postgres-tomcat/Dockerfile b/11/postgres-tomcat/Dockerfile
index 7161cdb..3abed1e 100644
--- a/11/postgres-tomcat/Dockerfile
+++ b/11/postgres-tomcat/Dockerfile
@@ -44,7 +44,7 @@ RUN apt-get update && \
 # Install XWiki as the ROOT webapp context in Tomcat
 # Create the Tomcat temporary directory
 # Configure the XWiki permanent directory
-ENV XWIKI_VERSION=11.10.5
+ENV XWIKI_VERSION="11.10.5"
 ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
 ENV XWIKI_DOWNLOAD_SHA256 b08c8a9f0abbbf2bef5c61852688165dd4b2a9a7217da29047647e81c1ec3058
 RUN rm -rf /usr/local/tomcat/webapps/* && \
diff --git a/12/mysql-tomcat/Dockerfile b/12/mysql-tomcat/Dockerfile
index c8c7b4b..7153d54 100644
--- a/12/mysql-tomcat/Dockerfile
+++ b/12/mysql-tomcat/Dockerfile
@@ -37,14 +37,13 @@ RUN apt-get update && \
     curl \
     libreoffice \
     unzip \
-    procps \
-    libmysql-java && \
+    procps && \
   rm -rf /var/lib/apt/lists/*
 
 # Install XWiki as the ROOT webapp context in Tomcat
 # Create the Tomcat temporary directory
 # Configure the XWiki permanent directory
-ENV XWIKI_VERSION=12.4
+ENV XWIKI_VERSION="12.4"
 ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
 ENV XWIKI_DOWNLOAD_SHA256 f42fe7b84a323b0f637c0e9c60e885741821b2fd05f0196d4d41729d5888d2cc
 RUN rm -rf /usr/local/tomcat/webapps/* && \
@@ -56,7 +55,13 @@ RUN rm -rf /usr/local/tomcat/webapps/* && \
   rm -f xwiki.war
 
 # Copy the JDBC driver in the XWiki webapp
-RUN cp /usr/share/java/mysql-connector-java-*.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/
+# For MYSQL, download the MySQL driver version from the Maven Central repository since there's no up to 
+# date Debian repository for it anymore.
+ENV MYSQL_JDBC_VERSION="8.0.20"
+ENV MYSQL_JDBC_PREFIX="https://repo1.maven.org/maven2/mysql/mysql-connector-java/${MYSQL_JDBC_VERSION}"
+ENV MYSQL_JDBC_ARTIFACT="mysql-connector-java-${MYSQL_JDBC_VERSION}.jar"
+ENV MYSQL_JDBC_TARGET="/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/${MYSQL_JDBC_ARTIFACT}"
+RUN curl -fSL "${MYSQL_JDBC_PREFIX}/${MYSQL_JDBC_ARTIFACT}" -o $MYSQL_JDBC_TARGET
 
 # Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
 COPY tomcat/setenv.sh /usr/local/tomcat/bin/
diff --git a/12/postgres-tomcat/Dockerfile b/12/postgres-tomcat/Dockerfile
index 428d41d..3b317d1 100644
--- a/12/postgres-tomcat/Dockerfile
+++ b/12/postgres-tomcat/Dockerfile
@@ -44,7 +44,7 @@ RUN apt-get update && \
 # Install XWiki as the ROOT webapp context in Tomcat
 # Create the Tomcat temporary directory
 # Configure the XWiki permanent directory
-ENV XWIKI_VERSION=12.4
+ENV XWIKI_VERSION="12.4"
 ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/${XWIKI_VERSION}"
 ENV XWIKI_DOWNLOAD_SHA256 f42fe7b84a323b0f637c0e9c60e885741821b2fd05f0196d4d41729d5888d2cc
 RUN rm -rf /usr/local/tomcat/webapps/* && \
diff --git a/template/Dockerfile b/template/Dockerfile
index ab51678..48808c8 100644
--- a/template/Dockerfile
+++ b/template/Dockerfile
@@ -41,15 +41,13 @@ RUN apt-get update && \\
     curl \\
     libreoffice \\
     unzip \\
-    procps \\
-    <% if (db == 'mysql') print 'libmysql-java'
-       if (db == 'postgres') print 'libpostgresql-jdbc-java' %> && \\
+    procps <% if (db == 'postgres') print '\\\n    libpostgresql-jdbc-java ' %>&& \\
   rm -rf /var/lib/apt/lists/*
 
 # Install XWiki as the ROOT webapp context in Tomcat
 # Create the Tomcat temporary directory
 # Configure the XWiki permanent directory
-ENV XWIKI_VERSION=$xwikiVersion
+ENV XWIKI_VERSION="$xwikiVersion"
 ENV XWIKI_URL_PREFIX "https://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-distribution-war/\${XWIKI_VERSION}"
 ENV XWIKI_DOWNLOAD_SHA256 $xwikiSha256
 RUN rm -rf /usr/local/tomcat/webapps/* && \\
@@ -61,10 +59,17 @@ RUN rm -rf /usr/local/tomcat/webapps/* && \\
   rm -f xwiki.war
 
 # Copy the JDBC driver in the XWiki webapp
-<% if (db == 'mysql')
-      print 'RUN cp /usr/share/java/mysql-connector-java-*.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/'
-   else if (db == 'postgres')
-      print 'RUN cp /usr/share/java/postgresql-jdbc4.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/' %>
+<% if (db == 'mysql') {
+  println "# For MYSQL, download the MySQL driver version from the Maven Central repository since there's no up to "
+  println "# date Debian repository for it anymore."
+  println "ENV MYSQL_JDBC_VERSION=\"8.0.20\""
+  println "ENV MYSQL_JDBC_PREFIX=\"https://repo1.maven.org/maven2/mysql/mysql-connector-java/\${MYSQL_JDBC_VERSION}\""
+  println "ENV MYSQL_JDBC_ARTIFACT=\"mysql-connector-java-\${MYSQL_JDBC_VERSION}.jar\""
+  println "ENV MYSQL_JDBC_TARGET=\"/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/\${MYSQL_JDBC_ARTIFACT}\""
+  print "RUN curl -fSL \"\${MYSQL_JDBC_PREFIX}/\${MYSQL_JDBC_ARTIFACT}\" -o \$MYSQL_JDBC_TARGET"
+} else if (db == 'postgres') {
+  print 'RUN cp /usr/share/java/postgresql-jdbc4.jar /usr/local/tomcat/webapps/ROOT/WEB-INF/lib/'
+} %>
 
 # Configure Tomcat. For example set the memory for the Tomcat JVM since the default value is too small for XWiki
 COPY tomcat/setenv.sh /usr/local/tomcat/bin/
-- 
GitLab