You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,6 @@ The input variables, with their default values (some auto generated) are:
76
76
*`project_slug`: The development friendly name of the project. By default, based on the project name
77
77
*`domain_main`: The domain in where to deploy the project for production (from the branch `production`), used by the load balancer, backend, etc. By default, based on the project slug.
78
78
*`domain_staging`: The domain in where to deploy while staging (before production) (from the branch `master`). By default, based on the main domain.
79
-
*`domain_dev`: The domain to use while developing. It won't be deployed, but you should use it by modifying your local `hosts` file.
80
79
81
80
*`docker_swarm_stack_name_main`: The name of the stack while deploying to Docker in Swarm mode for production. By default, based on the domain.
82
81
*`docker_swarm_stack_name_staging`: The name of the stack while deploying to Docker in Swarm mode for staging. By default, based on the domain.
* Update your local `hosts` file, set the IP `127.0.0.1` (your `localhost`) to `{{cookiecutter.domain_dev}}`. The `docker-compose.dev.env.yml` file(that will be one of the Docker Compose files used by default) will set the environment variable `SERVER_NAME` to that host. Otherwise you would receive 404 HTTP errors and "Cross Origin Resource Sharing" (CORS) errors.
5
+
* Docker
6
+
* Docker Compose
6
7
7
-
* Modify your `hosts` file, for macOS and Linux, probably in `/etc/hosts`. For Windows, in . Make sure you open it with administrative privileges.
8
+
## Frontend Requirements
8
9
9
-
**Note for Windows**: If you are in Windows, open the main Windows menu, search for "notepad", right click it, and select the option "open as Administrator" or similar. Then click the "File" menu, "Open file" and open the file at `c:\Windows\System32\Drivers\etc\hosts`.
10
+
* Node.js (with `npm`)
10
11
11
-
Make sure the `hosts` file contains (additionally to whatever it has):
12
-
13
-
```
14
-
127.0.0.1 {{cookiecutter.domain_dev}}
15
-
```
16
-
17
-
...that will make your browser talk to your locally running server when it is asked to go to `{{cookiecutter.domain_dev}}` and think that it is a remote server while it is actually running in your computer.
18
-
19
-
**Note for Windows and Mac**: If you are on Windows or Mac, and your Docker is running on a virtual machine (like with Docker Toolbox), you should put the IP of the virtual machine. For example:
20
-
21
-
```
22
-
192.168.99.100 {{cookiecutter.domain_dev}}
23
-
```
24
-
25
-
Make sure you save the file as is, without extensions (Windows tends to try to automatically add `.txt` extensions).
12
+
## Backend local development
26
13
27
14
* Start the stack with Docker Compose:
28
15
@@ -32,24 +19,39 @@ docker-compose up -d
32
19
33
20
* Now you can open your browser and interact with these URLs:
34
21
35
-
Frontend, built with Docker, with routes handled based on the path: http://{{cookiecutter.domain_dev}}
22
+
Frontend, built with Docker, with routes handled based on the path: http://localhost
36
23
37
-
Backend, JSON based web API, with Swagger automatic documentation: http://{{cookiecutter.domain_dev}}/api/
24
+
Backend, JSON based web API, with Swagger automatic documentation: http://localhost/api/
38
25
39
-
Swagger UI, frontend user interface to interact with the API live: http://{{cookiecutter.domain_dev}}/swagger/
26
+
Swagger UI, frontend user interface to interact with the API live: http://localhost/swagger/
40
27
41
-
PGAdmin, PostgreSQL web administration: http://{{cookiecutter.domain_dev}}:5050
28
+
PGAdmin, PostgreSQL web administration: http://localhost:5050
42
29
43
-
Flower, administration of Celery tasks: http://{{cookiecutter.domain_dev}}:5555
30
+
Flower, administration of Celery tasks: http://localhost:5555
44
31
45
-
Traefik UI, to see how the routes are being handled by the proxy: http://{{cookiecutter.domain_dev}}:8090
32
+
Traefik UI, to see how the routes are being handled by the proxy: http://localhost:8090
46
33
34
+
**Note**: The first time you start your stack, it might take a minute for it to be ready. While the backend waits for the database to be ready and configures everything. You can check the logs to monitor it.
35
+
36
+
To check the logs, run:
37
+
38
+
```bash
39
+
docker-compose logs
40
+
```
41
+
42
+
To check the logs of a specific service, add the name of the service, e.g.:
43
+
44
+
```bash
45
+
docker-compose logs backend
46
+
```
47
+
48
+
If your Docker is not running in `localhost` (the URLs above wouldn't work) check the sections below on **Development with Docker Toolbox** and **Development with a custom IP**.
47
49
48
50
## Backend local development, additional details
49
51
50
52
### General workflow
51
53
52
-
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/`.
54
+
Add and modify SQLAlchemy models in`./backend/app/app/models/`, Marshmallow schemas in`./backend/app/app/schemas` and API endpoints in`./backend/app/app/api/`.
53
55
54
56
Add and modify tasks to the Celery worker in `./backend/app/app/worker.py`.
55
57
@@ -107,6 +109,22 @@ Nevertheless, if it doesn't detect a change but a syntax error, it will just sto
107
109
108
110
The Celery worker has a `$RUN` variable too, running the Celery worker, so that you can test it while being inside the container and debug errors, etc.
109
111
112
+
### Backend tests
113
+
114
+
To test the backend run:
115
+
116
+
```bash
117
+
DOMAIN=backend sh ./script-test.sh
118
+
```
119
+
120
+
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.
121
+
122
+
The tests run with Pytest, modify and add tests to `./backend/app/app/tests/`.
123
+
124
+
If you need to install any additional package for the tests, add it to the file `./backend/app/tests.dockerfile`.
125
+
126
+
If you use GitLab CI the tests will automatically.
127
+
110
128
### Live development with Python Jupyter Notebooks
111
129
112
130
If you know about Python [Jupyter Notebooks](http://jupyter.org/), you can take advantage of them during local development.
http://(73e0ec1f1ae6 or 127.0.0.1):8888/?token=f20939a41524d021fbfc62b31be8ea4dd9232913476f4397
139
157
```
140
158
141
-
you can copy that URL and modify the "host" to be `localhost` or `{{cookiecutter.domain_dev}}`, in the case above, it would be, e.g.:
159
+
you can copy that URL and modify the "host" to be `localhost` or the domain you are using for development (e.g. `local.dockertoolbox.tiangolo.com`), in the case above, it would be, e.g.:
@@ -151,26 +169,9 @@ You will have a full Jupyter Notebook running inside your container, that has di
151
169
If you use tools like [Hydrogen](https://github.com/nteract/hydrogen) or [Visual Studio Code Jupyter](https://donjayamanne.github.io/pythonVSCodeDocs/docs/jupyter/), you can use that same modified URL.
152
170
153
171
154
-
### Backend tests
155
-
156
-
To test the backend run:
157
-
158
-
```bash
159
-
DOMAIN=backend sh ./script-test.sh
160
-
```
161
-
162
-
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.
163
-
164
-
The tests run with Pytest, modify and add tests to `./backend/app/app/tests/`.
165
-
166
-
If you need to install any additional package for the tests, add it to the file `./backend/app/tests.dockerfile`.
167
-
168
-
If you use GitLab CI the tests will automaticall.dockerfiley.
169
-
170
-
171
172
### Migrations
172
173
173
-
As in local development your app directory is mounted as a volume inside the container (set in the file `docker-compose.dev.volumes.yml`), you can also run the migrations with `alembic` commands inside the container and the migration code will be in your app directory (instead of being only inside the container). So you can add it to your git repository.
174
+
As during local development your app directory is mounted as a volume inside the container (set in the file `docker-compose.dev.volumes.yml`), you can also run the migrations with `alembic` commands inside the container and the migration code will be in your app directory (instead of being only inside the container). So you can add it to your git repository.
174
175
175
176
Make sure you create a "revision" of your models and that you "upgrade" your database with that revision every time you change them. As this is what will update the tables in your database. Otherwise, your application will have errors.
176
177
@@ -208,6 +209,109 @@ alembic upgrade head
208
209
209
210
If you don't want to start with the default models and want to remove them / modify them, from the beginning, without having any previous revision, you can remove the revision files (`.py` Python files) under `./backend/app/alembic/versions/`. And then create a first migration as described above.
210
211
212
+
### Development with Docker Toolbox
213
+
214
+
If you are using **Docker Toolbox** in Windows or macOS instead of **Docker for Windows** or **Docker for Mac**, Docker will be running in a VirtualBox Virtual Machine, and it will have a local IP different than `127.0.0.1`, which is the IP address for `localhost` in your machine.
215
+
216
+
The address of your Docker Toolbox virtual machine would probably be `192.168.99.100` (that is the default).
217
+
218
+
As this is a common case, the domain `local.dockertoolbox.tiangolo.com` points to that (private) IP, just to help with development. That way, you can start the stack in Docker Toolbox, and use that domain for development. You will be able to open that URL in Chrome and it will communicate with your local Docker Toolbox directly as if it was a cloud server, including CORS (Cross Origin Resource Sharing).
219
+
220
+
To use it, you need to tell your backend that it is running on that domain, you will have to edit a couple files.
221
+
222
+
* Open the file located at `./.env`. It would have 2 lines like:
223
+
224
+
```
225
+
DOMAIN=localhost
226
+
# DOMAIN=local.dockertoolbox.tiangolo.com
227
+
```
228
+
229
+
* Switch the comment, change the section to:
230
+
231
+
```
232
+
# DOMAIN=localhost
233
+
DOMAIN=local.dockertoolbox.tiangolo.com
234
+
```
235
+
236
+
That variable will be used by the `docker-compose.dev.env.yml` file. That's one of the Docker Compose files used by default. It will set the environment variable `SERVER_NAME` to that host. Without that change, you would receive 404 HTTP errors and "Cross Origin Resource Sharing" (CORS) errors.
237
+
238
+
* Now open the file located at `./frontend/.env`. It would have a line like:
That variable will make your frontend communicate with that domain when interacting with the API, when the other variable `VUE_APP_ENV` is set to `development`.
253
+
254
+
Now you can open: http://local.dockertoolbox.tiangolo.com and it will be server by your Docker Toolbox.
255
+
256
+
Check all the corresponding available URLs in the section at the end.
257
+
258
+
### Development with a custom IP
259
+
260
+
If you are running Docker in an IP address different than `127.0.0.1` (`localhost`) and `192.168.99.100` (the default of Docker Toolbox), you will need to perform some additional steps. That will be the case if you are running a custom Virtual Machine, a secondary Docker Toolbox or your Docker is located in a different machine in your network.
261
+
262
+
In that case, you will need to use a fake local domain (`dev.{{cookiecutter.domain_main}}`) and make your computer think that the domain is is served by the custom IP (e.g. `192.168.99.150`).
263
+
264
+
* Open your `hosts` file with administrative privileges using a text editor:
265
+
***Note for Windows**: If you are in Windows, open the main Windows menu, search for "notepad", right click on it, and select the option "open as Administrator" or similar. Then click the "File" menu, "Open file", go to the directory `c:\Windows\System32\Drivers\etc\`, select the option to show "All files" instead of only "Text (.txt) files", and open the `hosts` file.
266
+
***Note for Mac and Linux**: Your `hosts` file is probably located at `/etc/hosts`, you can edit it in a terminal running `sudo nano /etc/hosts`.
267
+
268
+
* Additional to the contents it might have, add a new line with the custom IP (e.g. `192.168.99.150`) a space character, and your fake local domain: `dev.{{cookiecutter.domain_main}}`.
269
+
270
+
The new line might look like:
271
+
272
+
```
273
+
192.168.99.100 dev.{{cookiecutter.domain_main}}
274
+
```
275
+
276
+
* Save the file.
277
+
***Note for Windows**: Make sure you save the file as "All files", without an extension of `.txt`. By default, Windows tries to add the extension. Make sure the file is saved as is, without extension.
278
+
279
+
...that will make your computer think that the fake local domain is served by that custom IP, and when you open that URL in your browser, it will talk directly to your locally running server when it is asked to go to `dev.{{cookiecutter.domain_main}}` and think that it is a remote server while it is actually running in your computer.
280
+
281
+
Now you need to make sure the stack uses that domain.
282
+
283
+
* Open the file located at `./.env`. It would have a line like:
284
+
285
+
```
286
+
DOMAIN=localhost
287
+
```
288
+
289
+
* Change that line to:
290
+
291
+
```
292
+
DOMAIN=dev.{{cookiecutter.domain_main}}
293
+
```
294
+
295
+
That variable will be used by the `docker-compose.dev.env.yml` file. That's one of the Docker Compose files used by default. It will set the environment variable `SERVER_NAME` to that host. Without that change, you would receive 404 HTTP errors and "Cross Origin Resource Sharing" (CORS) errors.
296
+
297
+
* Now open the file located at `./frontend/.env`. It would have a line like:
That variable will make your frontend communicate with that domain when interacting with the API, when the other variable `VUE_APP_ENV` is set to `development`.
310
+
311
+
Now you can open: http://dev.{{cookiecutter.domain_main}} and it will be server by your Docker Toolbox.
312
+
313
+
Check all the corresponding available URLs in the section at the end.
314
+
211
315
## Frontend development
212
316
213
317
* Enter the `frontend` directory, install the NPM packages and start the live server using the `npm` scripts:
@@ -218,14 +322,30 @@ npm install
218
322
npm run serve
219
323
```
220
324
221
-
Then open your browser at http://{{cookiecutter.domain_dev}}:8080
325
+
Then open your browser at http://localhost:8080
222
326
223
327
Notice that this live server is not running inside Docker, it is for local development, and that is the recommended workflow. Once you are happy with your frontend, you can build the frontend Docker image and start it, to test it in a production-like environment. But compiling the image at every change will not be as productive as running the local development server.
224
328
225
329
Check the file `package.json` to see other available options.
226
330
227
331
If you have Vue CLI installed, you can also run `vue ui` to control, configure, serve and analyse your application using a nice local web user interface.
228
332
333
+
If you are only developing the frontend (e.g. other team members are developing the backend) and there is a staging environment already deployed, you can make your local development code use that staging API instead of a full local Docker Compose stack.
334
+
335
+
To do that, modify the file `./frontend/.env`, there's a section with:
336
+
337
+
```
338
+
VUE_APP_ENV=development
339
+
# VUE_APP_ENV=staging
340
+
```
341
+
342
+
* Switch the comment, to:
343
+
344
+
```
345
+
# VUE_APP_ENV=development
346
+
VUE_APP_ENV=staging
347
+
```
348
+
229
349
## Deployment
230
350
231
351
You can deploy the stack to a Docker Swarm mode cluster and use CI systems to do it automatically. But you have to configure a couple things first.
0 commit comments