From 93a9beac6b4c89709556905c916458de653a1655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 14 Mar 2019 16:05:11 +0400 Subject: [PATCH] :sparkles: Use Live Reload server by default in development --- README.md | 4 ++++ {{cookiecutter.project_slug}}/README.md | 14 ++++++++++---- .../backend/backend.dockerfile | 2 +- .../docker-compose.dev.command.yml | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b829c20..4839793 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,10 @@ After using this generator, your new project (the directory created) will contai * Update generated README. Minor typos. +* Update Couchbase installation, to include Couchbase command line tools. + +* Set `/start-reload.sh` as a command override for development by default. + ### 0.2.0 **PR #7**: diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index eaaf739..3123508 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -81,7 +81,13 @@ The changes to those files only affect the local development environment, not th For example, the directory with the backend code is mounted as a Docker "host volume" (in the file `docker-compose.dev.volumes.yml`), mapping the code you change live to the directory inside the container. That allows you to test your changes right away, without having to build the Docker image again. It should only be done during development, for production, you should build the Docker image with a recent version of the backend code. But during development, it allows you to iterate very fast. -There is also a commented out `command` override (in the file `docker-compose.dev.command.yml`), if you want to enable it, uncomment it. It makes the backend container run a process that does "nothing", but keeps the process running. That allows you to get inside your living container and run commands inside, for example a Python interpreter to test installed dependencies, or start the development server that reloads when it detects changes. +There is a command override in the file `docker-compose.dev.command.yml` that runs `/start-reload.sh` (included in the base image) instead of the default `/start.sh` (also included in the base image). It starts a single server process (instead of multiple, as would be for production) and reloads the process whenever the code changes. As it is in `docker-compose.dev.command.yml`, it only applies to local development. Have in mind that if you have a syntax error and save the Python file, it will break and exit, and the container will stop. After that, you can restart the container by fixing the error and running again: + +```bash +docker-compose up -d +``` + +There is also a commented out `command` override (in the file `docker-compose.dev.command.yml`), you can uncomment it and comment the default one. It makes the backend container run a process that does "nothing", but keeps the process running. That allows you to get inside your living container and run commands inside, for example a Python interpreter to test installed dependencies, or start the development server that reloads when it detects changes, or start a Jupyter Notebook session. To get inside the container with a `bash` session you can start the stack with: @@ -103,7 +109,7 @@ root@7f2607af31c3:/app# that means that you are in a `bash` session inside your container, as a `root` user, under the `/app` directory. -There is also a script `/start-reload.sh` to run the debug live reloading server. You can run that script from inside the container with: +There you use the script `/start-reload.sh` to run the debug live reloading server. You can run that script from inside the container with: ```bash bash /start-reload.sh @@ -115,11 +121,11 @@ bash /start-reload.sh root@7f2607af31c3:/app# bash /start-reload.sh ``` -and then hit enter. That runs the debugging server that auto reloads when it detects code changes. +and then hit enter. That runs the live reloading server that auto reloads when it detects code changes. Nevertheless, if it doesn't detect a change but a syntax error, it will just stop with an error. But as the container is still alive and you are in a Bash session, you can quickly restart it after fixing the error, running the same command ("up arrow" and "Enter"). -...this previous detail is what makes it useful to have the container alive doing nothing and then, in a Bash session, make it run the debugging server. +...this previous detail is what makes it useful to have the container alive doing nothing and then, in a Bash session, make it run the live reload server. ### Backend tests diff --git a/{{cookiecutter.project_slug}}/backend/backend.dockerfile b/{{cookiecutter.project_slug}}/backend/backend.dockerfile index c6a4086..f8ecd34 100644 --- a/{{cookiecutter.project_slug}}/backend/backend.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/backend.dockerfile @@ -3,7 +3,7 @@ FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6 # Dependencies for Couchbase RUN wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | apt-key add - RUN echo "deb http://packages.couchbase.com/ubuntu stretch stretch/main" > /etc/apt/sources.list.d/couchbase.list -RUN apt-get update && apt-get install -y libcouchbase-dev build-essential +RUN apt-get update && apt-get install -y libcouchbase-dev libcouchbase2-bin build-essential RUN pip install celery==4.2.1 passlib[bcrypt] tenacity requests couchbase emails "fastapi>=0.7.1" uvicorn gunicorn pyjwt python-multipart email_validator jinja2 diff --git a/{{cookiecutter.project_slug}}/docker-compose.dev.command.yml b/{{cookiecutter.project_slug}}/docker-compose.dev.command.yml index 1440009..3bddda8 100644 --- a/{{cookiecutter.project_slug}}/docker-compose.dev.command.yml +++ b/{{cookiecutter.project_slug}}/docker-compose.dev.command.yml @@ -10,3 +10,5 @@ services: --web # backend: # command: bash -c "while true; do sleep 1; done" # Infinite loop to keep container live doing nothing + backend: + command: /start-reload.sh