The tutorial assumes that the user's OS is UNIX based, if not make the appropriate changes and select the correct OS in the documentation. If running on Windows remember to enable Hyper-V and virtual environments.
sudo apt-get install python3-pip
Create docker group, you'll need to reboot after this.
sudo groupadd docker
sudo usermod -aG docker $USER
cd ~/path/to/project/
git clone https://github.com/RenatoAAraujo/Star-Wars-API.git
cd Star-Wars-API
First deploy
docker-compose up --build
Regular Deploy
docker-compose up
You're ready to go!
The local variables are contained in the .env file, when readying to production deployment make the appropriate changes.
Make sure that the "APP_ENV" variable is set to "production".
The black, isort and pylint libs are installed in the development env, use the after every commit.
python3 clean_code.py
The pytest lib is used forr unit testing.
python3 run_tests.py
The API will be documented using flask-restx which has Swagger integration builtin. To access it, run in your browser the fallowing link:
http://localhost:5000/doc
The database is versioned using flask-migrate, all database changes must be done using it.
After making the appropriates changes to the view.py, schema.py and models.py files, make a migration by running:
docker-compose exec api flask db migrate -m"your message"
If your column has a default, make sure to add the server_default parameter to the column in the migration file, like the example below (remember that it has to be a string):
from alembic import op
import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('email_verified', sa.Boolean(), nullable=True, server_default="0"))
When migrations head conflict is encountered run the command bellow, it will make a new migration file resolving the conflict.
python3 db-merge.py
Sometimes a change or a database registry will be made that needs to be reflected in the application dump file, to make a new dump run:
python3 db-dump.py