Skip to content

Commit

Permalink
feat: Change MySQL to MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Feb 24, 2024
1 parent 1bd7d83 commit 1f3b4a8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ Create an `.env` file in the root of the project with this information. It is im

```
FLASK_APP_NAME=UVLHUB.IO
MYSQL_HOSTNAME=db
MYSQL_DATABASE=uvlhubdb
MYSQL_USER=uvlhubuser
MYSQL_PASSWORD=uvlhubpass
MYSQL_ROOT_PASSWORD=uvlhubrootpass
MARIADB_HOSTNAME=db
MARIADB_PORT=3306
MARIADB_DATABASE=uvlhubdb
MARIADB_USER=uvlhubuser
MARIADB_PASSWORD=uvlhubpass
MARIADB_ROOT_PASSWORD=uvlhubrootpass
ZENODO_ACCESS_TOKEN=<GET_ACCESS_TOKEN_IN_ZENODO>
```

Expand Down
7 changes: 5 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ def create_app(config_name=None):

# Database configuration
app.config['SQLALCHEMY_DATABASE_URI'] = (
f"mysql+pymysql://{os.getenv('MYSQL_USER', 'default_user')}:{os.getenv('MYSQL_PASSWORD', 'default_password')}"
f"@{os.getenv('MYSQL_HOSTNAME', 'localhost')}:3306/{os.getenv('MYSQL_DATABASE', 'default_db')}"
f"mysql+pymysql://{os.getenv('MARIADB_USER', 'default_user')}:"
f"{os.getenv('MARIADB_PASSWORD', 'default_password')}@"
f"{os.getenv('MARIADB_HOSTNAME', 'localhost')}:"
f"{os.getenv('MARIADB_PORT', '3306')}/"
f"{os.getenv('MARIADB_DATABASE', 'default_db')}"
)

# Timezone
Expand Down
21 changes: 13 additions & 8 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '3.8'
services:

web:
container_name: web_app_container
build:
context: .
dockerfile: Dockerfile.dev
Expand All @@ -12,26 +13,30 @@ services:
- "5000"
environment:
FLASK_ENV: development
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MARIADB_HOSTNAME: ${MARIADB_HOSTNAME}
MARIADB_PORT: ${MARIADB_PORT}
MARIADB_USER: ${MARIADB_USER}
MARIADB_PASSWORD: ${MARIADB_PASSWORD}
depends_on:
- db

db:
image: mysql:latest
container_name: mariadb_container
image: mariadb:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MARIADB_DATABASE: ${MARIADB_DATABASE}
MARIADB_USER: ${MARIADB_USER}
MARIADB_PASSWORD: ${MARIADB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
ports:
- "3306:3306"
- "${MARIADB_PORT}:3306"
volumes:
- db_data:/var/lib/mysql

nginx:
container_name: nginx_web_server
image: nginx:latest
volumes:
- ./nginx/nginx.dev.conf:/etc/nginx/nginx.conf
Expand Down
10 changes: 6 additions & 4 deletions scripts/wait-for-db.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh

until mysql -h db -P 3306 -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e 'SELECT 1' &> /dev/null
echo "Hostname: $MARIADB_HOSTNAME, Port: $MARIADB_PORT, User: $MARIADB_USER"

until mysql -h "$MARIADB_HOSTNAME" -P "$MARIADB_PORT" -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" -e 'SELECT 1' &> /dev/null
do
echo "MySQL is unavailable - sleeping"
echo "MariaDB is unavailable - sleeping"
sleep 1
done

echo "MySQL is up - executing command"
exec "$@"
echo "MariaDB is up - executing command"
exec "$@"

0 comments on commit 1f3b4a8

Please sign in to comment.