This Docker multi container can ease the process of configuring a Flask App from scratch.
It includes everything you need to start developing your Flask APIs:
- Python 3.7
- Pipenv
- Flask
- Flask RESTful
- Flask JWT Extended
- Flask SQLAlchemy
- Flask Migrate
- Flask Marshmallow
- Marshmallow SQLAlchemy
- Marshmallow
- MariaDB database engine (as a Docker service)
There are four APIs built for you, so you immediately can manage users registration, login, logout and refresh the JWT token without writing any code:
- /api/v1/register
- /api/v1/login
- /api/v1/logout
- /api/v1/refresh
The only requirement to execute the image is a working Docker engine
and a terminal program where you can execute the docker-compose command.
- You need to make a copy of
.env.exampleto.envfile in the root project and set theJWT_SECRET_KEYas you prefer. - In order to build the container for the first time, open your terminal and execute the following command:
docker-compose build
As you can see in
docker-compose.yml, there are two services for the container: one for the Flask App - thewebservice - and one another for the MariaDB image -dbservice.
- To run the services - the first time you need to download the MariaDB image - type in your console:
docker-compose up db
docker-compose up web
next time you can run both services with:
docker-compose up
modelscontains the models app, managed by SQLAlchemyschemascontains the Marshmallow mapping schemasresourcescontains the Flask-RESTful resourcestemplatescontains the Jinja2 templatestestscontains integration and system testslookup_tablescontains useful lookup tables. Themessages.pycontains the message codes sent by the APIs to the client.migrationscontains theFlask-MigrateandAlembicscripts and files for Database auto migrations
All migrations will be run by the
start.shautomatically, at the container startup. Therefore if you add a new model class than you need to restart the server in order to run migrations
Now the server is up and running, you can test the application in your browser at this address: http://127.0.0.1:5000/.
You should see a message with installed Flask version.
You can test the APIs by running the test suite run_all_tests.py.
Take a look at tests/system/test_user.py to see how perform calls from a client.
Enjoy!