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/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/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/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/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/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/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/Get Devices/task.md b/Building the Gateway Application/Get Devices/task.md index 1cdcf00..a5454ac 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`) @@ -15,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 by adding the `item_id` to it. +
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/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/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/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/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/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/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/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/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 diff --git a/Composing the System/Docker-compose/task.md b/Composing the System/Docker-compose/task.md index c31fc93..c8f45df 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. @@ -28,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"`. +just need to add `ports: - "5000:5000"` to the `invsys` service description. + +
+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). +
-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. 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.