Giter Site home page Giter Site logo

drf_course's Introduction

Django Rest Framework (DRF) Course

Welcome to this full Django Rest Framework (DRF)course. This course is perfect if you are looking to learn DRF and build your own API application.



Prerequisites

  • Python=>3.10

Considerations

I have added optional docker containers to simplify the build. If you want to use the docker build you should install Docker and Docker Compose on your local machine.

We will be calling our API throughout the next 8 modules. I have written the requests in (Curl)[https://curl.se/] and (Httpie)[https://httpie.io/].

(Httpie)[https://httpie.io/] provides a clean terminal output which is handy for this type of project. You will need to install it locally if you want to use the commands.

Note: (Httpie)[https://httpie.io/] is pre-installed in the docker container.



Getting started

First you will need to clone down the first module.

  1. Create a new directory on your local machine. I have called mine drf_course. This is your 'root directory'.

  2. Open a terminal and cd into the root directory.

  3. You can now clone the first module. You can do this a few different ways. I use SSH...

#option 1 - SSH
git clone --branch module_1 [email protected]:bobby-didcoding/drf_course.git .

#option 2 - Github CLI
gh repo clone bobby-didcoding/drf_course .
git checkout module_1

#option 3 - HTTPS
git clone --branch module_1 https://github.com/bobby-didcoding/drf_course.git .


Following along

Each module has a walk through video. All videos can be found in my (Django Rest Framework Course)[https://www.youtube.com/playlist?list=PL5VlxT4gkOFAD2wpucxHY3X2sCzhha5Kz] playlist.

Please open /steps/module_1 to begin.



drf_course's People

Contributors

bobby-customate avatar bobby-didcoding avatar rezajkee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

drf_course's Issues

module_5 migration problem..

When I followed bobby's instructions and made the python manage.py makemigrations and python manage.py migrate in the running docker container, no migrations were made.

In order to get migrations to work, I had to start module_5 from the beginning, but not using the docker terminal. I activated the virtual environment(venv), created the ecommerce app, edited the settings.py and urls.py files. Then I issued the makemigration and migrate commands in the VS Code terminal. They worked. Then I rebuilt the image and ran it in a docker container.

After that, everything worked the way bobby showed in the video.

end of module_5

Module_3 Docker Build Issues (M2 Pro Mac)

My setup: Macbook Pro M2.

Issue: Docker Build - Exit Code 100 due to Package 'netcat' has no installation candidate & Running Docker Issues

Error Code:

#0 2.039   netcat-openbsd 1.219-1
#0 2.039   netcat-traditional 1.10-47
#0 2.039 
#0 2.046 E: Package 'netcat' has no installation candidate
------
failed to solve: process "/bin/sh -c set -e;     apt-get update ;    apt-get -y install netcat ;    apt-get -y install gettext ;" did not complete successfully: exit code: 100

Solutions:

  1. backend/docker/docker_files/Dockerfile && backend/docker/docker_files/Dockerfile_app
  • Change
apt-get -y install netcat ;\ ---> apt-get -y install netcat-traditional ;\
  1. docker-compose-yml
  • Change Dockerfile_app ports to 5001:5001 instead of 5000:5000
  1. backend/docker/docker_files/Dockerfile
  • Change at the bottom
ENTRYPOINT ["/code/docker/entrypoints/entrypoint.sh"] ---> ENTRYPOINT ["bash", "-e", "/code/docker/entrypoints/entrypoint.sh"]

If a few other people could test wether its a good sturdy solution, we can close this.

IF better ways, make it aware to me please. Beginner Here.

Finally got the dockerized module_3 to work. Here is how...

Well, this time I really did find the source of the problem....

The problem was I was using CRLF line endings in the endpoint.sh script. On the linux side, those CRLF added a \r to then end of each line. So, for example, the file name makemigrations in the endpoint.sh script was interpreted in linux as makemigrations\r for the filename. Of course, that file name was not found.

Well I thought I could just run the command RUN dos2unix endpoint.sh, but that did not work either.

Ultimately I found that VS Code allows us to choose the line endings for files ( this link https://medium.com/@csmunuku/windows-and-linux-eol-sequence-configure-vs-code-and-git-37be98ef71df)

In VS Code I chose to use the \n line endings for the endpoint.sh file.
Rebuilt the images and ran the containers.
Everything works just as bobby said it should.

It would have been nice if bobby would have told us this in the tutorial. Then again, I learned a heck-of-a-lot about Docker in the last two days trying to trouble shoot this.

You can close this now.


Well, I think I know why the api container started with no ENTRYPOINT of CMD in the Dockerfile. In the docker-compose.yml file, there is a command instruction which has the following...

command: python manage.py runserver 0.0.0.0:8000.

It appears, the command: instruction in the docker-compose.yml file is all that is needed to start the api.?

While it works after making the change below, my optimism was a little misplaced.
I noticed that I did not get a message in the terminal for the running api container (in docker desktop) that migrations had been performed. If the entrypoint.sh file was executed I should have seen notification in the terminal that migrations were performed. This made me think that the entrypoint.sh script was not executed. So I removed the CMD line entirely from the revised Dockerfile and rebuilt the image. To my surprise, the api started up again. Without any ENTRYPOINT defined or any CMD. So the dockerized image must have used the default entypoint (wherever that is). So, even though it works, I have not been able to execute the entrypoint.sh script.


In a previous issue I described a problem I had regarding the docker images being built in module_3. The app image ran in a container, but the api image always failed to start. It failed with an error "exec /code/docker/entrypoints/entrypoint.sh : file or directory not found".

I finally got it work.

In the Dockerfile for the api (./backend/docker/ dockerfiles/Dockerfile)
I changed the line
ENTRYPOINT ["/code/docker/entrypoints/entrypoint.sh"]
to
CMD /code/docker/entrypoints/entrypoint.sh

Then I rebuilt the images using docker-compose up -d --build.

Brought up Docker Desktop and the app and api were both running. I submitted a request to the api using the apps docker terminal and received the correct response.

I would love to know why this worked.

On to module_4

FMR

Error when trying to use docker-compose

Hi,

I am trying to run the tutorial in a mac os Ventura 13.0.1. I checked out the module_3 branch and tried to run the docker-compose.yml. I get the following error at the end of the process:

  Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/code/docker/entrypoints/entrypoint.sh": permission denied: unknown
`docker-compose` process finished with exit code 1

I have not modified anything beyond what is contained in the training itself. My Docker-Desktop version is:

docker -v
Docker version 20.10.21, build baeda1f

What shall I do in order to run the app in Dockers?

The whole log can be found below:

docker-compose.yml up -d --build
[+] Building 0.0s (0/0)                                                                 
[+] Building 0.0s (0/0)                                                                 
[+] Building 0.0s (0/0)                                                                 
[+] Building 0.0s (0/1)                                                                 
[+] Building 0.1s (2/2)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                     
[+] Building 0.2s (4/4)                                                                                                 ad build definition from Dockerfile                     
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s 32B                                                     
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                     
[+] Building 0.4s (4/5)                                                                                                 ad .dockerignore                                        
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s                                                         
 => => transferring dockerfile: 36B                                                                                0.0soad .dockerignore                                        
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s                                                         
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 0.5s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 0.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 0.8s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.1s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.4s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.6s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 1.9s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.2s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.5s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.6s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.8s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 2.9s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.1s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.2s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.4s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.5s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 3.8s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.1s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.4s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.6s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 4.9s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.2s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.5s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.6s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.8s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 5.9s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.1s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.2s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.4s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.5s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 6.8s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.1s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.4s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.6s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.7s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 7.9s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 8.0s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 8.2s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 8.3s (4/5)                                                                                                 
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
[+] Building 8.4s (6/17)                                                                                                
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [drf_course-app internal] load .dockerignore                                                                   0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [drf_course-api internal] load .dockerignore                                                                   0.0s
[+] Building 8.6s (12/18)                                                                                               
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [drf_course-app internal] load .dockerignore                                                                   0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [drf_course-api internal] load .dockerignore                                                                   0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [drf_course-app internal] load metadata for docker.io/library/python:3.10                                      8.2s
 => [drf_course-api internal] load build context                                                                   0.1s
 => => transferring context: 2.01kB                                                                                0.0s
 => [drf_course-app 1/5] FROM docker.io/library/python:3.10@sha256:aa2724cbd68acc3c56a1ed29d03ecd1b34d6cbcb119f61  0.0s
 => [drf_course-app internal] load build context                                                                   0.0s
[+] Building 8.6s (18/18) FINISHED                                                                                      
 => [drf_course-app internal] load build definition from Dockerfile_app                                            0.0s
 => => transferring dockerfile: 36B                                                                                0.0s
 => [drf_course-api internal] load build definition from Dockerfile                                                0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [drf_course-app internal] load .dockerignore                                                                   0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [drf_course-api internal] load .dockerignore                                                                   0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [drf_course-app internal] load metadata for docker.io/library/python:3.10                                      8.2s
 => [drf_course-api internal] load build context                                                                   0.1s
 => => transferring context: 2.01kB                                                                                0.0s
 => [drf_course-app 1/5] FROM docker.io/library/python:3.10@sha256:aa2724cbd68acc3c56a1ed29d03ecd1b34d6cbcb119f61  0.0s
 => [drf_course-app internal] load build context                                                                   0.0s
 => => transferring context: 31B                                                                                   0.0s
 => CACHED [drf_course-app 2/5] RUN set -e;     apt-get update ;    apt-get -y install netcat ;    apt-get -y ins  0.0s
 => CACHED [drf_course-app 3/5] RUN mkdir /code                                                                    0.0s
 => CACHED [drf_course-app 4/5] WORKDIR /code                                                                      0.0s
 => CACHED [drf_course-app 5/5] COPY ./server.py .                                                                 0.0s
 => [drf_course-api] exporting to image                                                                            0.1s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:862fad9e527013c089020d2982abcf198b19960c15be2491d8c3ff6375fa8d05                       0.0s
 => => naming to docker.io/library/drf_course-app                                                                  0.0s
 => => writing image sha256:045352689e80e7a571c11cc37f8f87de8fb61f3732fd87019794bf952e37ed05                       0.0s
 => => naming to docker.io/library/drf_course-api                                                                  0.0s
 => CACHED [drf_course-api 2/6] RUN set -e;     apt-get update ;    apt-get -y install netcat ;    apt-get -y ins  0.0s
 => CACHED [drf_course-api 3/6] RUN mkdir /code                                                                    0.0s
 => CACHED [drf_course-api 4/6] COPY . /code/                                                                      0.0s
 => CACHED [drf_course-api 5/6] WORKDIR /code                                                                      0.0s
 => CACHED [drf_course-api 6/6] RUN set -e;     /usr/local/bin/python -m pip install --upgrade pip ;    python -m  0.0s
[+] Running 1/0
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                  
[+] Running 1/2            0.0s
 ⠿ Container drf_course-app-1  Running                                                                             0.0s
 ⠏ Container drf_course-api-1  Starting                                                                            0.9s
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/code/docker/entrypoints/entrypoint.sh": permission denied: unknown
`docker-compose` process finished with exit code 1

Thanks

drf_course module 3 not using Docker

I am following your drf_course. In module_3 you use Docker to access the api:8000/contact/... endpoint. Some of us did not want to install Docker. Can you please tell us how we can test the api in module 3 if we did not install Docker? I started the server and I can access localserver:8000 but I cannot access api:8000...

At the very least, please explain to your audience why you chose to use Docker. I have the Docker installer but Docker looks very 'heavy' and I am not sure I want to install it on my system.

I downloaded and installed Docker. It installed properly. But I did not understand how to view the app and api in Docker. This could have been a really good tutorial, but you assumed way too much. You should have told people what you were doing in Docker. Docker is/was a big problem here but you seem to totally oblivious to that. I cannot go on. I suspect you loose 90% of the people who try this tutorial at this point. You need to fix that.

With a little more Docker experience, I can tell you that the api container is not starting. There is a message in the log file that says the entrypoint.sh file was not found.

Also, the docker-compose.yml file has a version: 3.7. Is that supposed to be the version of Docker that we are using? Will it make a difference? I have downloaded DockerDesktop 4.17.1.

Since I just downloaded docker, I deleted drf_course on my computer and started over. My thinking was, that I could start with module_4. You comments in the steps file made me think that if I started in that module, the directory structure on my computer would be correct. However, the .env file was not there. (At least that is what docker told me when I issued the docker-compose up -d --build command. (I cannot remember in which step we created the .env file)

The .gitignore file contains the .env file so it is not saved in the git repository on github. Actually, there are many many files in the .gitignore file. So it is not possible to start at module_4. It appears you have to start at module_1.

Thanks in advance

On module_3, get error: exec /code/docker/entrypoints/entrypoint.sh: no such file or directory

Describe the issue
I followed your tutorial in this Youtube video. In the 3rd module, after running docker-compose, one service (port=8000) is not running due to an error exec /code/docker/entrypoints/entrypoint.sh: no such file or directory.

To Reproduce
Steps to reproduce the behavior:

  1. On root folder, run docker compose up -d --build

Expected behavior
All services (port=5000 and port=8000) can run.

Screenshots
Screenshot (3)
When you open the Container Tab, you will see that there is "Running (1/2)" on the Status.

Screenshot (4)_edit

  1. The logs contain the error message : exec /code/docker/entrypoints/entrypoint.sh: no such file or directory .
  2. One service (port=8000) is Restarting but it doesn't stop on Restarting.

Screenshot (5)
When open the details of the service (port=8000), you will see the logs of this service.

Desktop
Windows 11

Using dos2unix in Dockerfile in github download ....

According to the link, when you clone from Github to a Windows machine, Windows git is set up to automatically convert EOL characters to CRLF, even if the original was created on Linux.

"I hadn't consider this as a potential problem since the files were freshly cloned from Github and were originally created on Linux. What I didn't know is that on Windows Git is set up to automatically convert EOL characters to CRLF."

One solution, is to use VS Code to change the CRLF to LF using the 'select end of line sequence' in the bottom right status bar.

However, I think a better solution is to use dos2unix in the Docker file.
Below is a Dockerfile which uses dos2unix. I want to point out that in order to get the dos2unix command to RUN correctly, I had to copy the entrypoint.sh file from ./backend/docker/entrypoints/ folder to the root folder (/) on the linux machine. And then change the ENTRYPOINT to ["/entrypoint.sh"].

In order to get the dos2unix command to work, the entry point had to be located at the root level in linux.

FROM python:3.10

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

RUN set -e;
apt-get update ;
apt-get -y install netcat ;
apt-get -y install gettext ;
apt-get -y install dos2unix ;

COPY ./docker/entrypoints/entrypoint.sh /

RUN set -e;
dos2unix /entrypoint.sh ;
chmod +w /entrypoint.sh ;

RUN mkdir /code
COPY . /code/
WORKDIR /code

RUN set -e;
/usr/local/bin/python -m pip install --upgrade pip ;
python -m pip install -r /code/requirements.txt ;

EXPOSE 8000
ENTRYPOINT ["/entrypoint.sh"]

https://itecnote.com/tecnote/windows-building-docker-images-on-windows-entrypoint-script-no-such-file-or-directory/

Dockerfile misconfiguration

Hey I don't know if this is a linux issue or may happen in windows too but the docker-compose -d up --build is throwing a: "Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/code/docker/entrypoints/entrypoint.sh": permission denied: unknown"

Solution:
A simple change in "backend/docker/docker_files/Dockerfile" last line from:
ENTRYPOINT [ "/code/docker/entrypoints/entrypoint.sh"]
To:
ENTRYPOINT ["bash", "-e", "/code/docker/entrypoints/entrypoint.sh"]
Solves the issue.
Hope it helps!

non_field_errors Modul 5

Hallo,

I have been working on a project directly on my webserver. Up until now, everything has been functioning well. However, when I attempt to create an admin user, I encounter Error 1.

I tried to create the same user again and realized that the user creation was successful because the console indicated that the user already exists. But when I try to retrieve the token using HTTPie, I face Error 2.

Does anybody know what could be done to resolve this?

ERROR1:
(venv) [11:59:43][root@xxx:/var/www/django/drf_course/backend]$ python manage.py createsuperuser
Username (leave blank to use 'root'): xxxxx
Email address:
Password:
Password (again):
Traceback (most recent call last):
File "/var/www/django/drf_course/backend/manage.py", line 22, in
main()
File "/var/www/django/drf_course/backend/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/core/management/init.py", line 446, in execute_from_command_line
utility.execute()
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/core/management/init.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute
return super().execute(*args, **options)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 233, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/contrib/auth/models.py", line 172, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/contrib/auth/models.py", line 155, in _create_user
user.save(using=self._db)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 68, in save
super().save(*args, **kwargs)
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/db/models/base.py", line 812, in save
self.save_base(
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/db/models/base.py", line 878, in save_base
post_save.send(
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 176, in send
return [
File "/var/www/django/drf_course/venv/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 177, in
(receiver, receiver(signal=self, sender=sender, **named))
File "/var/www/django/drf_course/backend/ecommerce/signals.py", line 9, in report_uploaded
Token.objects.create(user=instance)

ERROR 2:
(venv) [12:17:18][root@xxx:/var/www/django/drf_course/backend]$ http post http://localhostipadress/api-token-auth/ username=xxx password=xxx
HTTP/1.1 400 Bad Request
Allow: POST, OPTIONS
Content-Length: 68
Content-Type: application/json
Cross-Origin-Opener-Policy: same-origin
Date: Wed, 15 Nov 2023 12:52:38 GMT
Referrer-Policy: same-origin
Server: WSGIServer/0.2 CPython/3.9.2
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
"non_field_errors": [
"Unable to log in with provided credentials."
]
}

Token matching query does not exist

Token is not automatically created after creating user or even superuser

I only noticed this after all the module 8 tests return error due to
rest_framework.authtoken.models.Token.DoesNotExist: Token matching query does not exist.

It seems that the token is only created when manually triggering http://api:8000/api-token-auth/ and at this point I am still new to the whole thing. Can someone help me identify the root of the error? So far I am following the course to a T except I am using windows. My suspicion is the signals.py not working but I don't know what to do at the moment.

Module 3. drf_coursee-api-1 container will not start. has error

I deleted the first attempt at the drf_course tutorial.

downloaded Docker Desktop and started the drf_course tutorial again. Starting at module_1.

issued docker-compose up -d --build. Completed fine.

In the docker desktop, the api-1 container is not running. The log file has the message
"/code/docker/entrypoints/entrypoint.sh: no such file or directory"

When I go into the container for api-1, and click on Files tab, I can see the linux enviroment. The file tree looks correct. entrypoint.sh is in the tree code/docker/entrypoints/entrypoint.sh.

Since I could not get the dockerized container to work, I tried using curl.

First, I re-activated the virtual environment (venv\Scripts\activate.bat).

Then I changed to the backend folder.

Then I started the django server python manage.py runserver

Then I opened another terminal in order to post the curl command provided at end of module_3 step file.

curl -X POST -H "Content-type: application/json" -d '{"name": "Bobby Stearman", "message": "test", "email":"[email protected]"}' 'http://api:8000/contact/'

However, the above curl command failed. It thought I had an unmatched curly brace.

After googling, I edited the above curl command to use double quotes instead of single quotes...

curl -X POST -H "Content-type: application/json" -d "{"name": "Bobby Stearman", "message": "test", "email":"[email protected]"}" "http://localhost:8000/contact/"

The above command worked. Notice I used localhost in the url.

Obviously, my local code is correct. However, the docker containerized code does not work (as described above). This is the problem with Docker. It is supposed to ensure that a project will work exactly the same on every machine. This is an example of where it doe s not.

I suspect I am not the only person who had this problem. Please do not sweep it under the rug. Have another tutorial specifically on this issue.

***Still trying to figure out why the api-1 process does not start in the Docker container. So here is what I did...
I started a new drf_course folder (saved the old 1 to a different folder name). I downloaded module_4 from the git repository. But module_4 is not complete. There are things that need to be done to make it complete. Here is what I did to make it complete...
1)create venv (virtual environment)
2)activate venv
3)copy env.template .env
4)pip install -r backend/requirements.txt
5)makemigrations
6)migrate

At this point I deactivated the venv.
Changed directory to the root directory (drf_course)
ran docker-compose up -d --build.
docker ran fine.

Start Docker Desktop.
Same problem as before. api-1 will not start. Log files has "exec /code/docker/entrypoints/entrypoint.sh: no such file or directory"

At this point I am pretty certain that problem is either with my version of Docker Desktop (4.18) or the project has not been dockerized correctly.

As a check, I did run the curl command, and that does work.

bobby there is a very easy way to troubleshoot this problem. If you get a chance, please download a current version of Docker Desktop (4.18) and then run the docker-compose command at the end of module_3. I would love to know if it works.

FMR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.