Flask Boilerplate with MySQL

오픈소스·2020년 8월 17일
0

https://github.com/fromzeroedu/flask-mysql-boilerplate 를 기초로 한다.

Local Installation

MySQL

$ brew services list
$ brew services start mysql
$ mysql -uroot -p
mysql> CREATE DATABASE counter;
mysql> CREATE USER 'counter_user'@'%' IDENTIFIED BY 'counter_password';
mysql> ALTER USER 'counter_user'@'%' IDENTIFIED WITH mysql_native_password BY 'counter_password'; # for mysql 8.0
mysql> GRANT ALL PRIVILEGES ON counter.* TO 'counter_user'@'%';
mysql> FLUSH PRIVILEGES;
mysql> \q

Flask Boilerplate

$ git clone https://github.com/fromzeroedu/flask-mysql-boilerplate.git
$ cd flask-mysql-boilerplate
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install --upgrade pip
$ pip install -r requirements.txt
$ pip install --upgrade Werkzeug
$ pip install cryptography # for mysql 8.0
$ flask db init
$ flask db migrate
$ flask db upgrade
$ flask run

  • Serving Flask app "manage.py" (lazy loading)
  • Environment: development
  • Debug mode: on
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 148-251-086

Docker Installation

Flask Boilerplate

$ git clone https://github.com/fromzeroedu/flask-mysql-boilerplate.git

화일 patch

  • docker-compose.yml
-      - /opt/flask-mysql-boilerplate:/counter_app
+      - .:/counter_app
  • requirements.txt
-Werkzeug==0.15.3
+Werkzeug==1.0.1

$ docker-compose up -d
$ docker logs -f counterappmysql_db_1

[Note] mysqld: ready for connections.

위의 로그를 확인하고, Ctrl+C
$ docker exec -it counterappmysql_web_1 flask db init
$ docker exec -it counterappmysql_web_1 flask db migrate
$ docker exec -it counterappmysql_web_1 flask db upgrade

http://localhost:5000 접속

0개의 댓글