Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1097 from openedx/farhanumar/psre-2485-1
Browse files Browse the repository at this point in the history
feat: Added mysql 8 container in docker-compose
  • Loading branch information
farhanumar authored Jun 19, 2023
2 parents e5f2fc8 + 8351a43 commit 8dca89e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ services:
volumes:
- mysql57_data:/var/lib/mysql

mysql80:
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.mysql80"
hostname: mysql80.devstack.edx
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
image: mysql:8.0.26
networks:
default:
aliases:
- edx.devstack.mysql80
ports:
- "3406:3306"
volumes:
- mysql80_data:/var/lib/mysql

redis:
container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.redis"
hostname: redis.devstack.edx
Expand Down Expand Up @@ -865,3 +882,4 @@ volumes:
mongo_data:
opensearch12_data:
mysql57_data:
mysql80_data:
11 changes: 11 additions & 0 deletions drop-mysql-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#docker-compose exec -T mysql80 bash -e -c "mysql -uroot mysql" < drop-mysql-user.sql
#docker exec -it edx.devstack.mysql80 mysql

drop user 'credentials001'@'%';
drop user 'discov001'@'%';
drop user 'ecomm001'@'%';
drop user 'notes001'@'%';
drop user 'registrar001'@'%';
drop user 'xqueue001'@'%';
drop user 'analytics001'@'%';
drop user 'edxapp001'@'%';
44 changes: 44 additions & 0 deletions provision-mysql80.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE DATABASE IF NOT EXISTS credentials;
CREATE USER 'credentials001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON credentials.* TO 'credentials001'@'%';

CREATE DATABASE IF NOT EXISTS discovery;
CREATE USER 'discov001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON discovery.* TO 'discov001'@'%';

CREATE DATABASE IF NOT EXISTS ecommerce;
CREATE USER 'ecomm001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON ecommerce.* TO 'ecomm001'@'%';

CREATE DATABASE IF NOT EXISTS notes;
CREATE USER 'notes001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON notes.* TO 'notes001'@'%';

CREATE DATABASE IF NOT EXISTS registrar;
CREATE USER 'registrar001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON registrar.* TO 'registrar001'@'%';

CREATE DATABASE IF NOT EXISTS xqueue;
CREATE USER 'xqueue001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON xqueue.* TO 'xqueue001'@'%';

CREATE DATABASE IF NOT EXISTS `dashboard`;
CREATE USER 'analytics001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON `dashboard`.* TO 'analytics001'@'%';

CREATE DATABASE IF NOT EXISTS `analytics-api`;
GRANT ALL ON `analytics-api`.* TO 'analytics001'@'%';

CREATE DATABASE IF NOT EXISTS `reports`;
GRANT ALL ON `reports`.* TO 'analytics001'@'%';

CREATE DATABASE IF NOT EXISTS `reports_v1`;
GRANT ALL ON `reports_v1`.* TO 'analytics001'@'%';

CREATE DATABASE IF NOT EXISTS edxapp;
CREATE DATABASE IF NOT EXISTS edxapp_csmh;
CREATE USER 'edxapp001'@'%' IDENTIFIED BY 'password';
GRANT ALL ON edxapp.* TO 'edxapp001'@'%';
GRANT ALL ON edxapp_csmh.* TO 'edxapp001'@'%';

FLUSH PRIVILEGES;
23 changes: 21 additions & 2 deletions provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,27 @@ echo -e "${GREEN}Will provision the following:\n ${to_provision_ordered}${NC}"

# Bring the databases online.
docker-compose up -d mysql57
docker-compose up -d mysql80
if needs_mongo "$to_provision_ordered"; then
docker-compose up -d mongo
fi

# Ensure the MySQL server is online and usable
# Ensure the MySQL5 server is online and usable
echo "${GREEN}Waiting for MySQL 5.7.${NC}"
until docker-compose exec -T mysql57 bash -e -c "mysql -uroot -se \"SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')\"" &> /dev/null
do
printf "."
sleep 1
done

# Ensure the MySQL8 server is online and usable
echo "${GREEN}Waiting for MySQL 8.0.${NC}"
until docker-compose exec -T mysql80 bash -e -c "mysql -uroot -se \"SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')\"" &> /dev/null
do
printf "."
sleep 1
done

# In the event of a fresh MySQL container, wait a few seconds for the server to restart
# See https://github.com/docker-library/mysql/issues/245 for why this is necessary.
sleep 10
Expand All @@ -146,13 +155,23 @@ do
sleep 1
done

echo -e "${GREEN}MySQL ready.${NC}"
echo -e "${GREEN}MySQL5 ready.${NC}"

echo "${GREEN}Waiting for MySQL 8.0 to restart.${NC}"
until docker-compose exec -T mysql80 bash -e -c "mysql -uroot -se \"SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')\"" &> /dev/null
do
printf "."
sleep 1
done

echo -e "${GREEN}MySQL8 ready.${NC}"

# Ensure that the MySQL databases and users are created for all IDAs.
# (A no-op for databases and users that already exist).
echo -e "${GREEN}Ensuring MySQL 5.7 databases and users exist...${NC}"
docker-compose exec -T mysql57 bash -e -c "mysql -uroot mysql" < provision.sql
echo -e "${GREEN}Ensuring MySQL 8.0 databases and users exist...${NC}"
docker-compose exec -T mysql80 bash -e -c "mysql -uroot mysql" < provision-mysql80.sql

# If necessary, ensure the MongoDB server is online and usable
# and create its users.
Expand Down

0 comments on commit 8dca89e

Please sign in to comment.