|
| 1 | +# {{project_name}} |
| 2 | + |
| 3 | +## Back end local development |
| 4 | + |
| 5 | +* Update your local `hosts` file, set the IP `127.0.0.1` (your `localhost`) to `{{cookiecutter.domain_dev}}`. The `docker-compose.override.yml` file will set the environment variable `SERVER_NAME` to that host. Otherwise you would receive 404 errors. |
| 6 | + |
| 7 | +* Modify your hosts file, probably in `/etc/hosts` to include: |
| 8 | + |
| 9 | +``` |
| 10 | +0.0.0.0 {{cookiecutter.domain_dev}} |
| 11 | +``` |
| 12 | + |
| 13 | +...that will make your browser talk to your locally running server. |
| 14 | + |
| 15 | +* Start the stack with Docker Compose: |
| 16 | + |
| 17 | +```bash |
| 18 | +docker-compose up -d |
| 19 | +``` |
| 20 | + |
| 21 | +* Start an interactive session in the server container that is running an infinite loop doing nothing: |
| 22 | + |
| 23 | +```bash |
| 24 | +docker-compose exec server bash |
| 25 | +``` |
| 26 | + |
| 27 | +* Run the local debugging Flask server, all the command is in the `RUN` environment variable: |
| 28 | + |
| 29 | +```bash |
| 30 | +$RUN |
| 31 | +``` |
| 32 | + |
| 33 | +* Your OS will handle redirecting `{{cookiecutter.domain_dev}}` to your local stack. So, in your browser, go to: http://{{cookiecutter.domain_dev}}. |
| 34 | + |
| 35 | +Add and modify SQLAlchemy models to `./backend/app/app/models/`, Marshmallow schemas to `./backend/app/app/schemas` and API endpoints to `./backend/app/app/api/`. |
| 36 | + |
| 37 | +Add and modify tasks to the Celery worker in `./backend/app/app/worker.py`. |
| 38 | + |
| 39 | +If you need to install any additional package to the worker, add it to the file `./backend/app/Dockerfile-celery-worker`. |
| 40 | + |
| 41 | + |
| 42 | +### Back end tests |
| 43 | + |
| 44 | +To test the back end run: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Build the testing stack |
| 48 | +docker-compose -f docker-compose.test.yml build |
| 49 | +# Start the testing stack |
| 50 | +docker-compose -f docker-compose.test.yml up -d |
| 51 | +# Run the REST tests |
| 52 | +docker-compose -f docker-compose.test.yml exec -T backend-rest-tests pytest |
| 53 | +# Stop and eliminate the testing stack |
| 54 | +docker-compose -f docker-compose.test.yml down -v |
| 55 | +``` |
| 56 | + |
| 57 | +The tests run with Pytest, modify and add tests to `./backend/app/app/rest_tests/`. |
| 58 | + |
| 59 | +If you need to install any additional package for the REST tests, add it to the file `./backend/app/Dockerfile-rest-tests`. |
| 60 | + |
| 61 | +If you use GitLab CI the tests will run automatically. |
| 62 | + |
| 63 | + |
| 64 | +### Migrations |
| 65 | + |
| 66 | +* Start an interactive session in the server container that is running an infinite loop doing nothing: |
| 67 | + |
| 68 | +```bash |
| 69 | +docker-compose exec server bash |
| 70 | +``` |
| 71 | + |
| 72 | +* After changing a model (for example, adding a column), inside the container, create a revision, e.g.: |
| 73 | + |
| 74 | +```bash |
| 75 | +alembic revision -m "Add column last_name to User model" |
| 76 | +``` |
| 77 | + |
| 78 | +* Commit to the git repository the files generated in the alembic directory. |
| 79 | + |
| 80 | +* After creating the revision, run the migration in the database (this is what will actually change the database): |
| 81 | + |
| 82 | +```bash |
| 83 | +alembic upgrade head |
| 84 | +``` |
| 85 | + |
| 86 | +## Front end development |
| 87 | + |
| 88 | +* Enter the `frontend` directory, install the NPM packages and start it the `npm` scrits: |
| 89 | + |
| 90 | +```bash |
| 91 | +cd frontend |
| 92 | +npm install |
| 93 | +npm run start |
| 94 | +``` |
| 95 | + |
| 96 | +Check the file `package.json` to see other available options. |
| 97 | + |
| 98 | +## Deployment |
| 99 | + |
| 100 | +To deploy the stack to a Docker Swarm run, e.g.: |
| 101 | + |
| 102 | +```bash |
| 103 | +docker stack deploy -c docker-compose.prod.yml --with-registry-auth {{cookiecutter.docker_swarm_stack_name_main}} |
| 104 | +``` |
| 105 | + |
| 106 | +Using the corresponding Docker Compose file. |
| 107 | + |
| 108 | +If you use GitLab CI, it will automatically deploy it. |
| 109 | + |
| 110 | +GitLab CI is configured assuming 3 environments following GitLab flow: |
| 111 | + |
| 112 | +* `prod` (production) from the `production` branch. |
| 113 | +* `stag` (staging) from the `master` branch. |
| 114 | +* `branch`, from any other branch (a feature in development). |
0 commit comments