-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jetbrains-academy/konstantin/deploy_on_do…
…cker_fixes Fixes of Deploy API on Docker lesson
- Loading branch information
Showing
57 changed files
with
245 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: LinksChecker | ||
|
||
on: | ||
# Triggers the workflow on push or pull request events for specific branches | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
links-checker-job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Call the action jetbrains-academy/links-checker-action | ||
uses: jetbrains-academy/links-checker-action@main | ||
with: | ||
dir: ./ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Developers need to test their APIs. There are plenty of tools for these tasks, allowing you to send a wide variety of HTTP, REST, and other requests. For example, [Postman](https://www.postman.com/) or the integrated [HTTP Client](https://www.jetbrains.com/help/pycharm/http-client-in-product-code-editor.html) in PyCharm Professional. | ||
|
||
In this task, we will use the open-source tool [HTTPie](https://httpie.io). All such applications are similar in some way, so you can use HTTPie or any other tool by analogy. | ||
|
||
You can download and install a desktop version of HTTPie [here](https://httpie.io/desktop). | ||
|
||
### GET request | ||
As with all such programs, the interface allows you to specify the query type, parameters, headers, authorization type, and more. For the very first request, we only need to specify the URL `http://0.0.0.0:5000/items` and press the **Send** button. | ||
|
||
Remember to launch our Flask application beforehand! | ||
|
||
![](images/httpie_get.png) | ||
|
||
HTTPie automatically detects the language of the response, links, and formats text inside the body to make inspection easy. | ||
|
||
### POST request | ||
Next, create a POST request. To do this, specify the `POST` request type, the URL `http://0.0.0.0:5000/items`, and the Body of the request. Select `Text` as the Body type. | ||
|
||
After executing the request, you should get a response containing the request body. | ||
|
||
![](images/httpie_post.png) | ||
|
||
### Explore your app | ||
Check that all the other methods defined in your API work as expected (getting a specific device, deleting a device, updating a device). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
if __name__ == "__main__": | ||
# Write your solution here | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
type: theory | ||
files: | ||
- name: main.py | ||
visible: true | ||
- name: __init__.py | ||
visible: false | ||
- name: images/img.png | ||
visible: false | ||
- name: images/img_1.png | ||
visible: false | ||
- name: images/img_2.png | ||
visible: false | ||
- name: images/img_3.png | ||
visible: false | ||
- name: images/img_4.png | ||
visible: false | ||
- name: main.py | ||
visible: true | ||
- name: __init__.py | ||
visible: false | ||
- name: images/docker.png | ||
visible: false | ||
- name: images/edit_dark.svg | ||
visible: false | ||
- name: images/edit.svg | ||
visible: false | ||
- name: images/run.svg | ||
visible: false | ||
- name: images/run_dark.svg | ||
visible: false | ||
- name: images/add_dark.svg | ||
visible: false | ||
- name: images/add.svg | ||
visible: false | ||
- name: images/settings_docker_dark.png | ||
visible: false | ||
- name: images/settings_docker.png | ||
visible: false | ||
- name: images/services.png | ||
visible: false | ||
- name: images/services_dark.png | ||
visible: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+519 KB
Deploy API on Docker/Docker run configuration setup/images/add_configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+535 KB
... API on Docker/Docker run configuration setup/images/add_configuration_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/add_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/browse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/browse_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+166 KB
Deploy API on Docker/Docker run configuration setup/images/delete_image.png
Oops, something went wrong.
Binary file added
BIN
+166 KB
Deploy API on Docker/Docker run configuration setup/images/delete_image_dark.png
Oops, something went wrong.
Binary file added
BIN
+207 KB
Deploy API on Docker/Docker run configuration setup/images/port_bindings.png
Oops, something went wrong.
Binary file added
BIN
+178 KB
Deploy API on Docker/Docker run configuration setup/images/port_bindings_dark.png
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/run.svg
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
Deploy API on Docker/Docker run configuration setup/images/run_dark.svg
Oops, something went wrong.
Binary file added
BIN
+35.4 KB
Deploy API on Docker/Docker run configuration setup/images/run_myrunconfig.png
Oops, something went wrong.
Binary file added
BIN
+31.2 KB
...oy API on Docker/Docker run configuration setup/images/run_myrunconfig_dark.png
Oops, something went wrong.
Binary file added
BIN
+112 KB
Deploy API on Docker/Docker run configuration setup/images/stop_container.png
Oops, something went wrong.
Binary file added
BIN
+101 KB
Deploy API on Docker/Docker run configuration setup/images/stop_container_dark.png
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 51 additions & 18 deletions
69
Deploy API on Docker/Docker run configuration setup/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,52 @@ | ||
## Docker run configuration setup | ||
|
||
Another caveat: to connect to the application running in a container, you need to | ||
map specific container ports to specific ports on the host. In the previous task, this setup was already done for you. | ||
To do it yourself, you need to: | ||
|
||
- From the main menu, select **Run | Edit Configurations**. | ||
- In the **Run/Debug Configurations dialog**, click **+**, select **Docker**, and then select the **Dockerfile** configuration. | ||
- In **Build**, select the correct Dockerfile path. | ||
![](config1.png) | ||
- Then click **Modify** and select **Bind ports**. | ||
- In **Bind ports**, click the folder symbol, and in the window that opens (Port Bindings), click **+** and add | ||
the ports to be bound. In our case, add `5000` to both Host post and Container port. Leave everything else as is. | ||
![](config2.png) | ||
- Add the name of the container and image tag. Please use "flask-app-invsys" and "flask-app-invsys-img" respectively. | ||
- Click **Ok** two times. | ||
|
||
Now, if you run the Dockerfile, you should be able to access your app via `http://0.0.0.0:5000/items`. | ||
So, by now, we know that to run our solution in a container, we need to: | ||
- Build an image according to the Dockerfile. | ||
- Start the container from this image. | ||
- Bind the container's port to our host machine's port so that we can access our application in the container. | ||
|
||
The course checking system handles all of this for you, but let's also learn how to do it ourselves. | ||
This is not difficult at all, as all these actions can be delegated to the IDE. | ||
|
||
[Run configurations](https://www.jetbrains.com/help/pycharm/run-debug-configuration.html) are specially designed for these tasks. They allow describing exactly how to run an application and specifying various launch parameters. In this lesson, we will focus only on [Docker run configurations](https://www.jetbrains.com/help/pycharm/docker-run-configurations.html). | ||
|
||
**Note: In this course, do not remove or modify run configurations that you didn't create on your own!** | ||
|
||
### Create Docker run configuration | ||
- From the main menu, select **Run | Edit Configurations…** | ||
- In the opened **Run/Debug Configurations** window, click ![](images/add.svg), select **Docker**, and then select the **Dockerfile** configuration. | ||
- Specify the name of your configuration. It can be anything you like; we chose `MyRunConfig`. | ||
- Specify the path to the required `Dockerfile`. This will be the path to the `Dockerfile` for this lesson. | ||
- Add the **Image tag** and the **Container name**. Please use `flask-app-invsys-img` and `flask-app-invsys`, respectively. | ||
|
||
![](images/add_configuration.png) | ||
|
||
- Next, click **Modify** and select **Bind ports**. | ||
- In the **Bind ports:** field that appears, click on ![](images/browse.svg) to open the **Port Bindings** window. | ||
- Click ![](images/add.svg) and add the ports to be bound. | ||
- In our case, add `5000` to both **Host port** and **Container port**. Leave everything else as is. | ||
![](images/port_bindings.png) | ||
- Click **OK** two times to save your port binding and run configuration! | ||
|
||
### Launch your configuration | ||
In the upper right corner of the IDE, select your run configuration from the list if it is not already selected. Afterward, click on ![](images/run.svg) or use the shortcut &shortcut:Run; to run your configuration. | ||
<div style="text-align:center;"><img src="images/run_myrunconfig.png" style="width:40%;" alt="Run MyRunConfig"></div> | ||
|
||
Now, after you run the Dockerfile, you should be able to access your app via http://0.0.0.0:5000/items. | ||
Otherwise, you will get a "Connection refused" error. | ||
|
||
### Shut down your configuration | ||
To stop your Docker container, just open the panel [Services](tool_window://Services) (or use the shortcut &shortcut:ActivateServicesToolWindow;), right-click the container, and select **Stop Container**. From this context menu, you can also delete the container using the **Delete...** option. This will delete only the container — no local files will be deleted. | ||
<div style="text-align:center;"><img src="images/stop_container.png" style="width:50%;" alt="Run MyRunConfig"></div> | ||
|
||
### Don't forget | ||
A Docker image contains application code, libraries, tools, dependencies, and other files needed to run your application. | ||
When your application does not work as expected and you find an error, correcting it in your project will not save this change to the image you previously created and ran. You should delete an old | ||
Docker image and rebuild it after fixing the problem. | ||
|
||
You can also delete your image from the [Services](tool_window://Services) panel: | ||
<div style="text-align:center;"><img src="images/delete_image.png" style="width:60%;" alt="Run MyRunConfig"></div> | ||
|
||
<style> | ||
img { | ||
display: inline !important; | ||
} | ||
</style> |
Diff not rendered.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ services: | |
container_name: flask-app-invsys | ||
image: flask-app-invsys-img | ||
ports: | ||
- "5000:5000" | ||
- "5000:5000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Flask | ||
flask-restful | ||
marshmallow | ||
marshmallow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.