From 4a6b011b159bd13c12cd973c3cfd61cd725bf7e0 Mon Sep 17 00:00:00 2001
From: Lunny Xiao <xiaolunwen@gmail.com>
Date: Mon, 18 Mar 2019 03:17:18 +0800
Subject: [PATCH] Add test environment for Mysql8 (#5234)

---
 .drone.yml                   | 25 +++++++++++++
 .gitignore                   |  3 ++
 Makefile                     | 24 ++++++++++--
 integrations/mysql8.ini.tmpl | 72 ++++++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 4 deletions(-)
 create mode 100644 integrations/mysql8.ini.tmpl

diff --git a/.drone.yml b/.drone.yml
index 7fb66c2cd6..311d3fd611 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -164,6 +164,22 @@ pipeline:
     when:
       event: [ tag ]
 
+  test-mysql8:
+    image: golang:1.11
+    pull: true
+    group: test
+    environment:
+      TAGS: bindata
+      TEST_LDAP: "1"
+    commands:
+      - curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
+      - apt-get install -y git-lfs
+      - (sleep 1200 && (echo 'kill -ABRT $(pidof gitea) $(pidof integrations.test)' | sh)) &
+      - make test-mysql8-migration
+      - make test-mysql8
+    when:
+      event: [ push, tag, pull_request ]
+
   test-pgsql:
     image: golang:1.12
     pull: true
@@ -406,6 +422,15 @@ services:
     when:
       event: [ push, tag, pull_request ]
 
+  mysql8:
+    image: mysql:8.0
+    environment:
+      - MYSQL_DATABASE=test
+      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
+      - MYSQL_DATABASE=testgitea
+    when:
+      event: [ push, tag, pull_request ]
+
   pgsql:
     image: postgres:9.5
     environment:
diff --git a/.gitignore b/.gitignore
index 2fe0134f7d..2e2c85df14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,14 +51,17 @@ coverage.all
 /log
 /public/img/avatar
 /integrations/gitea-integration-mysql
+/integrations/gitea-integration-mysql8
 /integrations/gitea-integration-pgsql
 /integrations/gitea-integration-sqlite
 /integrations/gitea-integration-mssql
 /integrations/indexers-mysql
+/integrations/indexers-mysql8
 /integrations/indexers-pgsql
 /integrations/indexers-sqlite
 /integrations/indexers-mssql
 /integrations/mysql.ini
+/integrations/mysql8.ini
 /integrations/pgsql.ini
 /integrations/mssql.ini
 /node_modules
diff --git a/Makefile b/Makefile
index 27d74de52c..bd599b791d 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,10 @@ TEST_MYSQL_HOST ?= mysql:3306
 TEST_MYSQL_DBNAME ?= testgitea
 TEST_MYSQL_USERNAME ?= root
 TEST_MYSQL_PASSWORD ?=
+TEST_MYSQL8_HOST ?= mysql8:3306
+TEST_MYSQL8_DBNAME ?= testgitea
+TEST_MYSQL8_USERNAME ?= root
+TEST_MYSQL8_PASSWORD ?=
 TEST_PGSQL_HOST ?= pgsql:5432
 TEST_PGSQL_DBNAME ?= testgitea
 TEST_PGSQL_USERNAME ?= postgres
@@ -80,9 +84,9 @@ clean:
 	$(GO) clean -i ./...
 	rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
 		integrations*.test \
-		integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ integrations/gitea-integration-mssql/ \
-		integrations/indexers-mysql/ integrations/indexers-pgsql integrations/indexers-sqlite integrations/indexers-mssql \
-		integrations/mysql.ini integrations/pgsql.ini integrations/mssql.ini
+		integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
+		integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
+		integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
 
 .PHONY: fmt
 fmt:
@@ -209,6 +213,11 @@ generate-ini:
 		-e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
 		-e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
 			integrations/mysql.ini.tmpl > integrations/mysql.ini
+	sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
+		-e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
+		-e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
+		-e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
+			integrations/mysql8.ini.tmpl > integrations/mysql8.ini
 	sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
 		-e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
 		-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
@@ -228,6 +237,14 @@ test-mysql: integrations.test generate-ini
 test-mysql-migration: migrations.test generate-ini
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.test
 
+.PHONY: test-mysql8
+test-mysql8: integrations.test generate-ini
+	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.test
+
+.PHONY: test-mysql8-migration
+test-mysql8-migration: migrations.test generate-ini
+	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.test
+
 .PHONY: test-pgsql
 test-pgsql: integrations.test generate-ini
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
@@ -236,7 +253,6 @@ test-pgsql: integrations.test generate-ini
 test-pgsql-migration: migrations.test generate-ini
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.test
 
-
 .PHONY: test-mssql
 test-mssql: integrations.test generate-ini
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test
diff --git a/integrations/mysql8.ini.tmpl b/integrations/mysql8.ini.tmpl
new file mode 100644
index 0000000000..246ec800a6
--- /dev/null
+++ b/integrations/mysql8.ini.tmpl
@@ -0,0 +1,72 @@
+APP_NAME = Gitea: Git with a cup of tea
+RUN_MODE = prod
+
+[database]
+DB_TYPE  = mysql
+HOST     = {{TEST_MYSQL8_HOST}}
+NAME     = {{TEST_MYSQL8_DBNAME}}
+USER     = {{TEST_MYSQL8_USERNAME}}
+PASSWD   = {{TEST_MYSQL8_PASSWORD}}
+SSL_MODE = disable
+
+[indexer]
+ISSUE_INDEXER_PATH = integrations/indexers-mysql8/issues.bleve
+REPO_INDEXER_ENABLED = true
+REPO_INDEXER_PATH = integrations/indexers-mysql8/repos.bleve
+
+[repository]
+ROOT = integrations/gitea-integration-mysql8/gitea-repositories
+
+[repository.local]
+LOCAL_COPY_PATH = tmp/local-repo-mysql8
+LOCAL_WIKI_PATH = tmp/local-wiki-mysql8
+
+[server]
+SSH_DOMAIN       = localhost
+HTTP_PORT        = 3004
+ROOT_URL         = http://localhost:3004/
+DISABLE_SSH      = false
+SSH_LISTEN_HOST  = localhost
+SSH_PORT         = 2204
+START_SSH_SERVER = true
+LFS_START_SERVER = true
+LFS_CONTENT_PATH = data/lfs-mysql8
+OFFLINE_MODE     = false
+LFS_JWT_SECRET   = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
+APP_DATA_PATH    = integrations/gitea-integration-mysql8/data
+
+[mailer]
+ENABLED = false
+
+[service]
+REGISTER_EMAIL_CONFIRM            = false
+ENABLE_NOTIFY_MAIL                = false
+DISABLE_REGISTRATION              = false
+ENABLE_CAPTCHA                    = false
+REQUIRE_SIGNIN_VIEW               = false
+DEFAULT_KEEP_EMAIL_PRIVATE        = false
+DEFAULT_ALLOW_CREATE_ORGANIZATION = true
+NO_REPLY_ADDRESS                  = noreply.example.org
+
+[picture]
+DISABLE_GRAVATAR        = false
+ENABLE_FEDERATED_AVATAR = false
+
+[session]
+PROVIDER = file
+PROVIDER_CONFIG = data/sessions-mysql8
+
+[log]
+MODE      = console,file
+ROOT_PATH = mysql8-log
+
+[log.console]
+LEVEL = Warn
+
+[log.file]
+LEVEL = Debug
+
+[security]
+INSTALL_LOCK   = true
+SECRET_KEY     = 9pCviYTWSb
+INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ