From 70676e69b5fa1983ef5cce23044f0bb31f69b878 Mon Sep 17 00:00:00 2001 From: vadik likholetov Date: Thu, 16 Nov 2023 16:08:08 +0200 Subject: [PATCH] Initial dockerization --- README.md | 4 ++++ app.py | 4 +++- docker-compose.yml | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b8c56d1..bca23a0 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,7 @@ An attempt to create search and rescue database for logging SAR jobs and activit # Update the .po files with new translations ... pybabel compile -d translations + +# How to run the application with docker-compose + + docker-compose up --build diff --git a/app.py b/app.py index 806c078..7f4bd7e 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +import os from flask import Flask, redirect, url_for, request, session from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate @@ -25,7 +26,8 @@ def get_locale(): app = Flask(__name__) app.config['SECRET_KEY'] = 'secret_key' #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3' -app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp' +#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp' +app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp') app.config['BABEL_DEFAULT_LOCALE'] = 'en' babel= Babel(app) babel.init_app(app, locale_selector=get_locale) diff --git a/docker-compose.yml b/docker-compose.yml index 8afdc91..ad61597 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - db environment: - FLASK_ENV=development - - DATABASE_URL=mysql+pymysql://username:password@db/mydatabase + - DATABASE_URL=mysql+mysqlconnector://sarbaseuser:password@db/sarbaseapp db: image: mysql:8.0 @@ -16,9 +16,9 @@ services: - db-data:/var/lib/mysql - ./init-db:/docker-entrypoint-initdb.d environment: - MYSQL_ROOT_PASSWORD: rootpassword - MYSQL_DATABASE: mydatabase - MYSQL_USER: username + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: sarbaseapp + MYSQL_USER: sarbaseuser MYSQL_PASSWORD: password volumes: