From 1aeb3208bfb814058d89dee47755628a74a22e2c Mon Sep 17 00:00:00 2001 From: Manu Date: Fri, 3 May 2019 21:44:18 +0200 Subject: [PATCH 1/5] :sparkles: Use extra pytest arguments forwarded from shell (#17) * removed postgres_password from alembic.ini, read it from env var instead * :recycle: use f-strings for PostgreSQL URL * passes given args --- {{cookiecutter.project_slug}}/backend/app/tests-start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/backend/app/tests-start.sh b/{{cookiecutter.project_slug}}/backend/app/tests-start.sh index 1065fdc57a..a500dfb2e5 100644 --- a/{{cookiecutter.project_slug}}/backend/app/tests-start.sh +++ b/{{cookiecutter.project_slug}}/backend/app/tests-start.sh @@ -3,4 +3,4 @@ set -e python /app/app/tests_pre_start.py -pytest /app/app/tests/ +pytest $* /app/app/tests/ From 6bbd58c76f89a8e6c1e2f137bf0a84501eebe992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 3 May 2019 23:52:23 +0400 Subject: [PATCH 2/5] :memo: Update docs for running tests live --- {{cookiecutter.project_slug}}/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index bc75538feb..752ec0e752 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -134,6 +134,22 @@ If you need to install any additional package for the tests, add it to the file If you use GitLab CI the tests will run automatically. +#### Test running stack + +If your stack is already up and you just want to run the tests, you can use: + +```bash +docker-compose exec backend-tests /tests-start.sh +``` + +That `/tests-start.sh` script inside the `backend-tests` container calls `pytest`. If you need to pass extra arguments to `pytest`, you can pass them to that command and they will be forwarded. + +For example, to stop on first error: + +```bash +docker-compose exec backend-tests /tests-start.sh -x +``` + ### Live development with Python Jupyter Notebooks If you know about Python [Jupyter Notebooks](http://jupyter.org/), you can take advantage of them during local development. From 8ce745b7ef4191079db64d8bc765969a3371b27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 3 May 2019 23:52:42 +0400 Subject: [PATCH 3/5] :memo: Update release notes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7c9a5f4a84..be97394fd6 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,8 @@ After using this generator, your new project (the directory created) will contai ### Next release +* Forward arguments from script to `pytest` inside container. PR [#17](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/17) by [@ebreton](https://github.com/ebreton). + * Update development scripts. * Read Alembic configs from env vars. PR #9 by @ebreton. From 8bf3607d2b2e7eff776f631488ba931de2a03419 Mon Sep 17 00:00:00 2001 From: Manu Date: Fri, 3 May 2019 21:57:12 +0200 Subject: [PATCH 4/5] :memo: Fix the paths of the scripts in README (#19) * removed postgres_password from alembic.ini, read it from env var instead * :recycle: use f-strings for PostgreSQL URL * fix path to scripts --- {{cookiecutter.project_slug}}/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 752ec0e752..defd2dd47e 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -123,10 +123,10 @@ Nevertheless, if it doesn't detect a change but a syntax error, it will just sto To test the backend run: ```bash -DOMAIN=backend sh ./script-test.sh +DOMAIN=backend sh ./scripts/test.sh ``` -The file `./script-test.sh` has the commands to generate a testing `docker-stack.yml` file from the needed Docker Compose files, start the stack and test it. +The file `./scripts/test.sh` has the commands to generate a testing `docker-stack.yml` file from the needed Docker Compose files, start the stack and test it. The tests run with Pytest, modify and add tests to `./backend/app/app/tests/`. @@ -400,7 +400,7 @@ Then you need to have those constraints in your deployment Docker Compose file f To be able to use different environments, like `prod` and `stag`, you should pass the name of the stack as an environment variable. Like: ```bash -STACK_NAME={{cookiecutter.docker_swarm_stack_name_staging}} sh ./script-deploy.sh +STACK_NAME={{cookiecutter.docker_swarm_stack_name_staging}} sh ./scripts/deploy.sh ``` To use and expand that environment variable inside the `docker-compose.deploy.volumes-placement.yml` files you can add the constraints to the services like: @@ -417,7 +417,7 @@ services: - node.labels.${STACK_NAME}.app-db-data == true ``` -note the `${STACK_NAME}`. In the script `./script-deploy.sh`, that `docker-compose.deploy.volumes-placement.yml` would be converted, and saved to a file `docker-stack.yml` containing: +note the `${STACK_NAME}`. In the script `./scripts/deploy.sh`, that `docker-compose.deploy.volumes-placement.yml` would be converted, and saved to a file `docker-stack.yml` containing: ```yaml version: '3' @@ -506,10 +506,10 @@ Here are the steps in detail: * Set these environment variables, prepended to the next command: * `TAG=prod` * `FRONTEND_ENV=production` -* Use the provided `script-build.sh` file with those environment variables: +* Use the provided `scripts/build.sh` file with those environment variables: ```bash -TAG=prod FRONTEND_ENV=production bash ./script-build.sh +TAG=prod FRONTEND_ENV=production bash ./scripts/build.sh ``` 2. **Optionally, push your images to a Docker Registry** @@ -521,10 +521,10 @@ If you are using a registry and pushing your images, you can omit running the pr * Set these environment variables: * `TAG=prod` * `FRONTEND_ENV=production` -* Use the provided `script-build-push.sh` file with those environment variables: +* Use the provided `scripts/build-push.sh` file with those environment variables: ```bash -TAG=prod FRONTEND_ENV=production bash ./script-build.sh +TAG=prod FRONTEND_ENV=production bash ./scripts/build-push.sh ``` 3. **Deploy your stack** @@ -534,14 +534,14 @@ TAG=prod FRONTEND_ENV=production bash ./script-build.sh * `TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}}` * `STACK_NAME={{cookiecutter.docker_swarm_stack_name_main}}` * `TAG=prod` -* Use the provided `script-deploy.sh` file with those environment variables: +* Use the provided `scripts/deploy.sh` file with those environment variables: ```bash DOMAIN={{cookiecutter.domain_main}} \ TRAEFIK_TAG={{cookiecutter.traefik_constraint_tag}} \ STACK_NAME={{cookiecutter.docker_swarm_stack_name_main}} \ TAG=prod \ -bash ./script-deploy.sh +bash ./scripts/deploy.sh ``` --- From 5216fcfd7790f998a8240858677f25d3624cbc68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 4 May 2019 00:04:30 +0400 Subject: [PATCH 5/5] :memo: Update release notes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index be97394fd6..349b82d2c2 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,8 @@ After using this generator, your new project (the directory created) will contai ### Next release +* Fix locations of scripts in generated README. PR [#19](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/19) by [@ebreton](https://github.com/ebreton). + * Forward arguments from script to `pytest` inside container. PR [#17](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/17) by [@ebreton](https://github.com/ebreton). * Update development scripts.