https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
Full tutorial with minor adaptation done in some monthes
docker pull playerla/flaskmegaturorial:1.0
docker-compose -f docker-compose.yml up --no-build
docker-compose exec web flask shell
User.query.filter(User.username=='user').first().set_password(YOUR_PASSWORD_HERE)
db.session.commit()
exit()
I used Docker toolbox ("Native" Linux container on WSL 2 was still preview). See .env file for password and secret configuration. Now using Docker for windows with WSL2 backend.
https://stackoverflow.com/a/44283611 https://gist.githubusercontent.com/skeep/10c30807e68c2dd7da820bd5cf7afe92/raw/c8c0a8f630f11def57a272eebeed8de630aaf806/docker-compose.yml https://github.com/vishnubob/wait-for-it.git
Usefull on a permission denied, wrong former password stored on volume:
docker-compose stop db
docker-compose rm -v db
docker-compose up -d --build
# Run tool in a client container
docker run --network flask-mega-tuto_default -it --rm mysql mysql -hdb -uroot -p
# or attach in db container
docker-compose exec db mysql -hdb -p
Elastic volume has not been configured in this docker-compose file (not persistent)
docker-compose exec web flask index update
docker-compose logs -f smtp
- Windows 10, VirtualBox, WSL.
- VSCode
- Python 3.8
https://app.sendgrid.com/ with api key for local postfix relay
python -m smtpd -n -c DebuggingServer localhost:25
pybabel extract -F babel.cfg -k _l -o messages.pot .
pybabel init -i messages.pot -d core/translations -l fr
# ... Edit messages.po
pybabel compile -d core/translations
# ... Modify python code and extract new pending translations
pybabel extract -F babel.cfg -k _l -o messages.pot .
pybabel update -i messages.pot -d core/translations
pybabel compile -d core/translations
$env:Path = "$env:LOCALAPPDATA\Programs\Python\Python37\;$env:Path"
Last version of livereload was broken I made a fix (a revert see 4fce73)
Livereload work with <script>
tag injection in <head>
:
return render_template_string("<html><head>world!<!-- script is injected here--></head><html>")
Fix elastic on WSL read only mode : https://stackoverflow.com/a/56143760
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": false}'
- Python
- Jinja
- Gitlens
- Brower Preview
- Remote SSH/WSL
- SQlite
- SFTP
- Docker
- reStructuredText
- AREPL for python
- Better TOML
- TODO Highlight
- Bracket pair colorizer 2
- Toogle
Deployed on /opt with user vagrant (SFTP extension is used here)
chown root:root /opt -R
find /opt -type d -exec setfacl -m "g:ubuntu:r-x" {} +
find /opt -type d -exec setfacl -m "g:vagrant:rwx" {} +
find /opt -type f -exec setfacl -m "g:vagrant:rwx" {} +
find /opt -type f -exec setfacl -m "g:ubuntu:r--" {} +
Check :
- user 'ubuntu' not in sudoers
- ubuntu permissions:executable+x, database+w and its folder +w
chown root:ubuntu /opt/microblog.db
chmod g+w /opt/microblog.db
chown root:ubuntu /opt/venv/bin/*
chmod g+x /opt/venv/bin/*
chown root:ubuntu /opt
chmod g+w /opt
heroku cli use git config to identify remote app, set :
git remote add heroku git@heroku.com:microblog-flask-lopi.git
or on each command you will be asked for app-name : heroku command -a app-name
- Redis
- SendGrid
- Postgres
- SearchBox Elasticsearch
http://www.searchly.com/docs/python
Setup .\google-credentials.json content in $GOOGLE_CREDENTIALS
$GOOGLE_CREDENTIALS= ""; gc .\google-credentials.json | % { $GOOGLE_CREDENTIALS += $_ };
$env:EDITOR="code -w"
heroku config:edit GOOGLE_CREDENTIALS
heroku buildpacks:add --index 1 https://github.com/playerla/heroku-google-application-credentials-buildpack.git
NB: a .profile is executed at startup for manipulating the environment