myapp is a universal backbone for flask-dash based apps with user level authentication.
Start by defining your apps folder name
export APP_NAME="myapp"
as seen in the base folder of this repo.
If running myapp on development mode make sure that you change the variable FLASK_ENV to development in docker-compose.yml otherwise use production.
For production export secret variables into .env.prod:
cat << EOF > .env.prod
APP_NAME="${APP_NAME}"
MAIL_PASSWORD="<mail password>"
MYSQL_PASSWORD=$(openssl rand -base64 20)
MYSQL_ROOT_PASSWORD=$(openssl rand -base64 20)
REDIS_PASSWORD=$(openssl rand -base64 20)
SECRET_KEY=$(openssl rand -base64 20)
EOFand specify the env file when starting container eg. docker-compose --env-file .env.prod up.
For local development (quote all mail related entries in the docker-compose.yml):
cat << EOF > .env
APP_NAME="${APP_NAME}"
MYSQL_PASSWORD=$(openssl rand -base64 20)
MYSQL_ROOT_PASSWORD=$(openssl rand -base64 20)
REDIS_PASSWORD=$(openssl rand -base64 20)
SECRET_KEY=$(openssl rand -base64 20)
EOFCreate local folders:
mkdir -p ~/myapp_backup/stats ~/myapp_backup/users_data ~/myapp_backup/mariadb
To deploy myapp edit the docker-compose.yml accordingly and then:
docker-compose up -d --buildCheck the stdout with:
docker-compose logsor for example:
docker-compose logs -f serverIf running myapp on development mode you will have to start flask from inside the server container:
docker-compose exec server /bin/bash
flask run --host 0.0.0.0 --port 8000
Adding administrator user:
docker-compose run --entrypoint="python3 /myapp/myapp.py admin --add myemail@gmail.com" init
You can connect to any of the running containers by eg.
docker-compose exec mariadb /bin/bashFor stopping and removing a container,
docker-compose stop mariadb && docker-compose rm mariadbStopping and removing all containers:
docker-compose downStopping and removing all containers as well as all volumes (this will destroy the volumes and contained data):
docker-compose down -vTo remove a volume, eg.
docker volume rm dbdocker-compose exec backup /backup.sh
docker-compose exec backup rsync -rtvh --delete /${APP_NAME}_data/users/ /backup/users_data/To use the SMTP debugging server from Python comment all email related env in docker-compose.yml.
You can not using python's fake email server that accepts emails, but instead of sending them, it prints them to the console.
To run this server, open a second terminal session and run the following command on it:
docker-compose exec server python3 -m smtpd -n -c DebuggingServer localhost:8025For handling database entries you can start the flask shell by:
docker-compose exec server flask shell make the required imports:
from myapp import app, db
from myapp.models import User, UserLoggingand then for removing a user from the db:
u=User.query.filter_by(email=<user_email>).first()
db.session.delete(u)
db.session.commit()for editing entries eg.:
user=User.query.filter_by(email=<user_email>).first()
user.active = False
db.session.add(user)
db.session.commit()Collecting usage entries:
docker-compose run --entrypoint="python3 /${APP_NAME}/${APP_NAME}.py stats /backup/stats" initIf you need to re-initiate your database
rm -rf migrations && flask db init && flask db migrate -m "users table" && flask db upgrade upgrading
flask db migrate -m "new fields in user model"
flask db upgradeManually backup a database:
docker-compose exec mariadb /usr/bin/mysqldump -u root --password=mypass ${APP_NAME} > dump.sqlManually restore a database from backup:
cat dump.sql | docker-compose exec mariadb mysql --user=root --password=mypass ${APP_NAME}Builds are currently working for linux/amd64 and linux/arm64 but not for linux/arm/v7.
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg MYAPP_VERSION=local --no-cache --force-rm -t myapp/myapp:latest -f services/server/Dockerfile . --load
To push result image into registry use --push or to load image into docker use --load.