This project utilize flask-volt-dashboard which supports running application in docker or on the host. By furtherly following below steps, it can achieve:
- Both docker and host running methods share the same database file
- Source code change will take effect immediately for both running methods
- virtualenv flask
- source flask/bin/activate
- pip3 install -r requirements.txt
Create directory configs
in folder apps
, put your openai API key string to file apps/configs/openai_api_key.txt
Create directory logs
in folder apps
In apps/__init__.py, set database uri:
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
In apps/config.py, also set the database uri:
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
Then init the database:
flask db init
flask db migrate
flask db upgrade
This will create a file db.sqlite3 in folder apps
mv apps/db.sqlite3 /opt/sqlite/flask/
WORKDIR /code
volumes:
- .:/code
- /opt/sqlite/flask/:/opt/sqlite/flask/
The first mounted path is to mount the project folder to container working directory /code. So any code change in source files will take effect with docker running; The second mounted path is to mount the database file directory to container
8. in apps/__init__.py where database path is defined, change url to the mounted database directory:
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI = 'sqlite:////opt/sqlite/flask/db.sqlite3'