From c0ebcc4466982e34488c2d01761d2fde537c3667 Mon Sep 17 00:00:00 2001 From: sofiiako Date: Mon, 15 Jul 2024 14:04:49 +0200 Subject: [PATCH 1/6] removed .db from storage.db in the last two lessons --- .../Add a Dockerfile and requirements.txt/invsys/dal.py | 4 ++-- Building the Gateway Application/Define routes/invsys/dal.py | 4 ++-- Building the Gateway Application/Delete Device/invsys/dal.py | 4 ++-- Building the Gateway Application/Get Devices/invsys/dal.py | 4 ++-- Building the Gateway Application/Introduction/invsys/dal.py | 4 ++-- Building the Gateway Application/Post Device/invsys/dal.py | 4 ++-- Building the Gateway Application/Put Device/invsys/dal.py | 4 ++-- Composing the System/Deploying without Docker/invsys/dal.py | 4 ++-- Composing the System/Docker-compose/invsys/dal.py | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Building the Gateway Application/Add a Dockerfile and requirements.txt/invsys/dal.py b/Building the Gateway Application/Add a Dockerfile and requirements.txt/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Add a Dockerfile and requirements.txt/invsys/dal.py +++ b/Building the Gateway Application/Add a Dockerfile and requirements.txt/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Define routes/invsys/dal.py b/Building the Gateway Application/Define routes/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Define routes/invsys/dal.py +++ b/Building the Gateway Application/Define routes/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Delete Device/invsys/dal.py b/Building the Gateway Application/Delete Device/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Delete Device/invsys/dal.py +++ b/Building the Gateway Application/Delete Device/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Get Devices/invsys/dal.py b/Building the Gateway Application/Get Devices/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Get Devices/invsys/dal.py +++ b/Building the Gateway Application/Get Devices/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Introduction/invsys/dal.py b/Building the Gateway Application/Introduction/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Introduction/invsys/dal.py +++ b/Building the Gateway Application/Introduction/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Post Device/invsys/dal.py b/Building the Gateway Application/Post Device/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Post Device/invsys/dal.py +++ b/Building the Gateway Application/Post Device/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Building the Gateway Application/Put Device/invsys/dal.py b/Building the Gateway Application/Put Device/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Building the Gateway Application/Put Device/invsys/dal.py +++ b/Building the Gateway Application/Put Device/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Composing the System/Deploying without Docker/invsys/dal.py b/Composing the System/Deploying without Docker/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Composing the System/Deploying without Docker/invsys/dal.py +++ b/Composing the System/Deploying without Docker/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value diff --git a/Composing the System/Docker-compose/invsys/dal.py b/Composing the System/Docker-compose/invsys/dal.py index 6ad2de5..e0b8d04 100644 --- a/Composing the System/Docker-compose/invsys/dal.py +++ b/Composing the System/Docker-compose/invsys/dal.py @@ -7,7 +7,7 @@ def pull_db(): db_ = getattr(g, '_database', None) if db_ is None: - db_ = g._database = shelve.open("storage.db") + db_ = g._database = shelve.open("storage") return db_ @@ -89,6 +89,6 @@ def delete_device(identifier): } # Initialize db with some data already in it -with shelve.open('storage.db') as db: +with shelve.open('storage') as db: for key, value, in devices.items(): db[key] = value From 6f8d7259fa1dfd75dcf4d300f9efadd88ac1348d Mon Sep 17 00:00:00 2001 From: sofiiako Date: Mon, 15 Jul 2024 14:10:16 +0200 Subject: [PATCH 2/6] removed task titles from the descriptions in the last two lessons --- .../Add a Dockerfile and requirements.txt/task.md | 2 -- Building the Gateway Application/Define routes/task.md | 2 -- Building the Gateway Application/Delete Device/task.md | 2 -- Building the Gateway Application/Get Devices/task.md | 2 -- Building the Gateway Application/Introduction/task.md | 2 -- Building the Gateway Application/Post Device/task.md | 2 -- Building the Gateway Application/Put Device/task.md | 2 -- Composing the System/Deploying without Docker/task.md | 3 --- Composing the System/Docker-compose/task.md | 1 - Composing the System/What's next/task.md | 2 -- 10 files changed, 20 deletions(-) diff --git a/Building the Gateway Application/Add a Dockerfile and requirements.txt/task.md b/Building the Gateway Application/Add a Dockerfile and requirements.txt/task.md index f8d5d56..6d3ca58 100644 --- a/Building the Gateway Application/Add a Dockerfile and requirements.txt/task.md +++ b/Building the Gateway Application/Add a Dockerfile and requirements.txt/task.md @@ -1,5 +1,3 @@ -## Add Dockerfile and requirements.txt - ### Task Add the files necessary to run the gateway app as a Docker container. diff --git a/Building the Gateway Application/Define routes/task.md b/Building the Gateway Application/Define routes/task.md index 791d324..4b3e836 100644 --- a/Building the Gateway Application/Define routes/task.md +++ b/Building the Gateway Application/Define routes/task.md @@ -1,5 +1,3 @@ -## Define Routes - We added the four functions needed in our gateway application for routing requests (in addition to `index()`, which doesn't really do anything). Each of these four functions will send a request to the other application. In this task, you will add the appropriate routes to all of them. diff --git a/Building the Gateway Application/Delete Device/task.md b/Building the Gateway Application/Delete Device/task.md index 07c42e8..6b50afc 100644 --- a/Building the Gateway Application/Delete Device/task.md +++ b/Building the Gateway Application/Delete Device/task.md @@ -1,5 +1,3 @@ -## Delete Resource - In this task, we will define the `delete_device` function, which will: - Forward the delete request to the relevant endpoint in `invsys`. - Forward the response back to the client by creating a `Response` object from the received `response`. diff --git a/Building the Gateway Application/Get Devices/task.md b/Building the Gateway Application/Get Devices/task.md index 1cdcf00..a7a3fff 100644 --- a/Building the Gateway Application/Get Devices/task.md +++ b/Building the Gateway Application/Get Devices/task.md @@ -1,5 +1,3 @@ -## Get Devices - In this task, we will define the `get_devices` function, which will: - Forward the request to the relevant endpoint in `invsys` (depending on the URL: if the item ID is provided, it needs to be added to the route, which in `invsys` will result in calling the `get` endpoint in the function `device`) diff --git a/Building the Gateway Application/Introduction/task.md b/Building the Gateway Application/Introduction/task.md index 182a8f1..d228344 100644 --- a/Building the Gateway Application/Introduction/task.md +++ b/Building the Gateway Application/Introduction/task.md @@ -1,5 +1,3 @@ -# Gateway Application - The next step will be creating an API gateway backend, which acts as a router for client requests. This means our final application will consist of two backend components: the inventory manager and the API gateway. diff --git a/Building the Gateway Application/Post Device/task.md b/Building the Gateway Application/Post Device/task.md index 233f10b..b4fa04c 100644 --- a/Building the Gateway Application/Post Device/task.md +++ b/Building the Gateway Application/Post Device/task.md @@ -1,5 +1,3 @@ -## POST Resource - In this task, we will define the `post_device` function, which will: - Get the payload from our incoming request. - Forward the POST request to the relevant endpoint in invsys. Do not forget the payload! diff --git a/Building the Gateway Application/Put Device/task.md b/Building the Gateway Application/Put Device/task.md index de68c48..ec81669 100644 --- a/Building the Gateway Application/Put Device/task.md +++ b/Building the Gateway Application/Put Device/task.md @@ -1,5 +1,3 @@ -## Put Resource - In this task we will define the `put_device` function, which will: - Get the payload from our incoming request. - Forward the PUT request to the relevant endpoint in `invsys`. Do not forget the payload! diff --git a/Composing the System/Deploying without Docker/task.md b/Composing the System/Deploying without Docker/task.md index 0c711ee..ffddad2 100644 --- a/Composing the System/Deploying without Docker/task.md +++ b/Composing the System/Deploying without Docker/task.md @@ -1,6 +1,3 @@ -## Deploying locally without Docker - - While this course is focused on deploying with Docker, you can also deploy locally without it. You will need to change the routes in the `gateway`: diff --git a/Composing the System/Docker-compose/task.md b/Composing the System/Docker-compose/task.md index c31fc93..24a56d4 100644 --- a/Composing the System/Docker-compose/task.md +++ b/Composing the System/Docker-compose/task.md @@ -1,4 +1,3 @@ -## Composing our system Now we have two Flask apps: Invsys and Gateway. We want them both to be deployed, and we want Gateway to be able to send requests to Invsys using `invsys` instead of a specific IP. diff --git a/Composing the System/What's next/task.md b/Composing the System/What's next/task.md index 9dc0b80..503c0f6 100644 --- a/Composing the System/What's next/task.md +++ b/Composing the System/What's next/task.md @@ -1,5 +1,3 @@ -## What else to explore - Here are some recommended resources for further reading: [Flask by example: Part 1](https://realpython.com/flask-by-example-part-1-project-setup/) — a tutorial. From 74b3d91108180a062b28c006e72048c84dfbca23 Mon Sep 17 00:00:00 2001 From: sofiiako Date: Mon, 15 Jul 2024 14:33:55 +0200 Subject: [PATCH 3/6] added a more detailed explanation of what happens with ips and docker in building the gateway application / get device --- .../Get Devices/task.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Building the Gateway Application/Get Devices/task.md b/Building the Gateway Application/Get Devices/task.md index a7a3fff..15e86e2 100644 --- a/Building the Gateway Application/Get Devices/task.md +++ b/Building the Gateway Application/Get Devices/task.md @@ -13,7 +13,16 @@ import requests data = ... # from request response = requests.get("http://0.0.0.0:5000/items/") ``` -Let's keep it that way for this task, but let's also keep in mind that +This would be totally okay if you wanted to deploy your applications locally (without Docker), however, by doing this, our application source code becomes coupled with how and where we deploy `invsys`. -Instead, we can post to `http://invsys:5000/items` and ensure that our network is set up to route `invsys` to whichever IP it is hosted on. -We will come back to this later on. +You can use `0.0.0.0` for local deployment if you like, but for checking this task, we ask +you to replace it with `invsys`, so that your url looks something like this: + `http://invsys:5000/items` (check out the url in the `else` clause which is already completed). +We will explain this in more detail in the next lesson, for now you only need to know that +we use Docker under the hood to check these tasks, so `invsys` will be a designated name of a docker-compose service and +Docker will take care of names and routing. + +
+ + To create the right url for getting a specific item you only need to slightly modify the get url that is already provided - add the `item_id` to it. +
From 53f364d110b8d4c14fa42fbce6259a764b01098c Mon Sep 17 00:00:00 2001 From: sofiiako Date: Wed, 17 Jul 2024 14:36:53 +0200 Subject: [PATCH 4/6] minor post-review fixes --- Building the Gateway Application/Get Devices/task.md | 12 ++++++------ Composing the System/Docker-compose/task.md | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Building the Gateway Application/Get Devices/task.md b/Building the Gateway Application/Get Devices/task.md index 15e86e2..a5454ac 100644 --- a/Building the Gateway Application/Get Devices/task.md +++ b/Building the Gateway Application/Get Devices/task.md @@ -13,16 +13,16 @@ import requests data = ... # from request response = requests.get("http://0.0.0.0:5000/items/") ``` -This would be totally okay if you wanted to deploy your applications locally (without Docker), however, +This would be totally okay if you wanted to deploy your applications locally (without Docker). However, by doing this, our application source code becomes coupled with how and where we deploy `invsys`. You can use `0.0.0.0` for local deployment if you like, but for checking this task, we ask -you to replace it with `invsys`, so that your url looks something like this: - `http://invsys:5000/items` (check out the url in the `else` clause which is already completed). -We will explain this in more detail in the next lesson, for now you only need to know that -we use Docker under the hood to check these tasks, so `invsys` will be a designated name of a docker-compose service and +you to replace it with `invsys`, so that your URL looks something like this: + `http://invsys:5000/items` (check out the URL in the `else` clause which is already completed). +We will explain this in more detail in the next lesson. For now, you only need to know that +we use Docker under the hood to check these tasks, so `invsys` will be a designated name of a Docker Compose service and Docker will take care of names and routing.
- To create the right url for getting a specific item you only need to slightly modify the get url that is already provided - add the `item_id` to it. + To create the right URL for getting a specific item, you only need to slightly modify the `get` URL that is already provided by adding the `item_id` to it.
diff --git a/Composing the System/Docker-compose/task.md b/Composing the System/Docker-compose/task.md index 24a56d4..5fb02cb 100644 --- a/Composing the System/Docker-compose/task.md +++ b/Composing the System/Docker-compose/task.md @@ -31,6 +31,6 @@ the image. The `ports` flag is the same as the one used in the `docker run` comm external Docker machine port to the internally exposed port of our containers. You'll notice that we haven't added a port mapping for `invsys`. This is intentional because we want to ensure that requests go through the gateway. If you want to allow direct targeting of `invsys` as well, you would -just need to add `ports: - "5000:5000"`. +just need to add `ports: - "5000:5000"` to the `invsys` service description. -Now, add the contents to the `docker-compose.yaml` file and run the application. Test it with Postman like you did before. +Now, add the contents to the `docker-compose.yaml` file and run the application. Test it with HTTPie like you did before. From 5dfe1713b7374dbc3fb398766216b89abe6df1a6 Mon Sep 17 00:00:00 2001 From: Konstantin Chaika Date: Thu, 18 Jul 2024 12:52:46 +0400 Subject: [PATCH 5/6] Note about secure port publishing --- Composing the System/Docker-compose/task.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Composing the System/Docker-compose/task.md b/Composing the System/Docker-compose/task.md index 5fb02cb..378c8c5 100644 --- a/Composing the System/Docker-compose/task.md +++ b/Composing the System/Docker-compose/task.md @@ -27,10 +27,20 @@ of the service is what we use to target that service in the network. Since we ar Invsys service as `invsys`, any requests from our application targeting `invsys` will be routed to the correct IP for that service. We are using the `build` flag in each case, which instructs the tool to search for the `gateway` and `invsys` subdirectories and use their Dockerfiles to build -the image. The `ports` flag is the same as the one used in the `docker run` command: it routes the +the image. + +The `ports` flag is the same as the one used in the `docker run` command: it routes the external Docker machine port to the internally exposed port of our containers. You'll notice that we haven't added a port mapping for `invsys`. This is intentional because we want to ensure that requests go through the gateway. If you want to allow direct targeting of `invsys` as well, you would just need to add `ports: - "5000:5000"` to the `invsys` service description. +
+By default, when you bindings container ports to host, they become available on all network interfaces. +For experiments this is not critical, but when deploying real applications, +you should pay careful attention to which ports should be accessible from an outside world and which should not. + +You can read more about how to properly publish ports [here](https://docs.docker.com/network/#published-ports). +
+ Now, add the contents to the `docker-compose.yaml` file and run the application. Test it with HTTPie like you did before. From bbbaf7de37d3eba6948676ae356f515e9694a14b Mon Sep 17 00:00:00 2001 From: Konstantin Chaika Date: Thu, 18 Jul 2024 15:22:35 +0400 Subject: [PATCH 6/6] Fixes after proofreading --- Composing the System/Docker-compose/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Composing the System/Docker-compose/task.md b/Composing the System/Docker-compose/task.md index 378c8c5..c8f45df 100644 --- a/Composing the System/Docker-compose/task.md +++ b/Composing the System/Docker-compose/task.md @@ -36,9 +36,9 @@ go through the gateway. If you want to allow direct targeting of `invsys` as wel just need to add `ports: - "5000:5000"` to the `invsys` service description.
-By default, when you bindings container ports to host, they become available on all network interfaces. -For experiments this is not critical, but when deploying real applications, -you should pay careful attention to which ports should be accessible from an outside world and which should not. +By default, when you bind container ports to the host, they become available on all network interfaces. +For experiments, this is not critical, but when deploying real applications, +you should pay careful attention to which ports should be accessible from the outside world and which should not. You can read more about how to properly publish ports [here](https://docs.docker.com/network/#published-ports).