wger-project / docker

Production...ish docker-compose image for wger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django permission error

deboy69 opened this issue · comments

Can this help track down any permission errors on static or django?

wger | yarn install v1.22.19
wger | [1/5] Validating package.json...
wger | [2/5] Resolving packages...
wger | [3/5] Fetching packages...
wger | [4/5] Linking dependencies...
wger | [5/5] Building fresh packages...
wger | Done in 42.34s.
wger | yarn run v1.22.19
wger | $ sass wger/core/static/scss/main.scss:wger/core/static/yarn/bootstrap-compiled.css
wger | Done in 14.57s.
wger | Running in production mode, running collectstatic now
wger | Traceback (most recent call last):
wger | File "/home/wger/src/manage.py", line 25, in
wger | execute_from_command_line(sys.argv)
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 419, in execute_from_command_line
wger | utility.execute()
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/management/init.py", line 413, in execute
wger | self.fetch_command(subcommand).run_from_argv(self.argv)
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 354, in run_from_argv
wger | self.execute(*args, **cmd_options)
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 398, in execute
wger | output = self.handle(*args, **options)
wger | File "/usr/local/lib/python3.10/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
wger | collected = self.collect()
wger | File "/usr/local/lib/python3.10/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
wger | handler(path, prefixed_path, storage)
wger | File "/usr/local/lib/python3.10/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 348, in copy_file
wger | self.storage.save(prefixed_path, source_file)
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/files/storage.py", line 54, in save
wger | name = self._save(name, content)
wger | File "/usr/local/lib/python3.10/dist-packages/django/core/files/storage.py", line 260, in _save
wger | os.makedirs(directory, exist_ok=True)
wger | File "/usr/lib/python3.10/os.py", line 215, in makedirs
wger | makedirs(head, exist_ok=exist_ok)
wger | File "/usr/lib/python3.10/os.py", line 225, in makedirs
wger | mkdir(name, mode)
wger | PermissionError: [Errno 13] Permission denied: '/home/wger/static/django_extensions'
wger | Performing database migrations
wger | Operations to perform:
wger | Apply all migrations: actstream, auth, authtoken, axes, config, contenttypes, core, easy_thumbnails, exercises, gallery, gym, mailer, manager, measurements, nutrition, sessions, sites, weight

this would at least explain why later there aren't any files to serve. The django user needs to be able to write there, nginx needs only read permissions

Spent a week trying to figure out why my site was just showing text on the web page. Since I already have nginx running I wanted to use that. I ended up using the whole docker-compose with nginx to get the files. than removed the nginx container and setup my nginx and it worked. dont know if it worked for that reason or if it was just a coincidence.

yeah, I guess that is the best solution, to just leave the whole compose as one unit and add another nginx in front of that

Now to figure out the broken pipe errors

wger_server | [31/Oct/2022 14:33:40] "HEAD / HTTP/1.1" 302 0
wger_server | [31/Oct/2022 14:33:40] "HEAD /en/ HTTP/1.1" 302 0
wger_server | [31/Oct/2022 14:33:40] "HEAD /en/software/features HTTP/1.1" 200 14465
wger_server | [31/Oct/2022 14:33:40,409] - Broken pipe from ('127.0.0.1', 43474)

According to https://stackoverflow.com/questions/7912672/django-broken-pipe-in-debug-mode

According to many sources the 'Broken Pipe' is a normal browser quirk. For example, the browser reads from the socket and then decides that the image it's been reading apparently didn't change. The browser now this (forcefully) closes the connection because it does not need more data. The other end of this socket (the python runserver) now raises a socket exception telling the program that the client 'Broke the socket pipe'.

Thanks. But riddle me this. If i set django_debug=false in the prod.env file or comment it out . wger wont work and just shows text on the webpage. If I set it to true it loads like it should.

In that case there is still something wrong with the static files and nginx. During development Django serves the files itself, but in production some other service needs to do that

How so? What gets blocked with debug mode turned off?

Nothing is "blocked", it's just that Django will ignore any requests to the static files when jn production. So if nginx in misconfigured or something, this will only happen when debug is set to false

https://docs.djangoproject.com/en/4.1/howto/static-files/

this would at least explain why later there aren't any files to serve. The django user needs to be able to write there, nginx needs only read permissions

Is this why its not creating the correct permissions for django for that error?

db_1 | 2022-10-31 20:20:49.579 UTC [1] LOG: starting PostgreSQL 12.12 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
db_1 | 2022-10-31 20:20:49.580 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2022-10-31 20:20:49.580 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2022-10-31 20:20:49.586 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-10-31 20:20:49.624 UTC [52] LOG: database system was shut down at 2022-10-31 20:20:49 UTC
db_1 | 2022-10-31 20:20:49.632 UTC [1] LOG: database system is ready to accept connections
db_1 | 2022-10-31 20:21:00.451 UTC [66] ERROR: relation "auth_user" does not exist at character 35
db_1 | 2022-10-31 20:21:00.451 UTC [66] STATEMENT: SELECT COUNT(*) AS "__count" FROM "auth_user"
wger | *** Database does not exist, creating one now

So I think i narrowed it down. I used volumes to map to my external HD for persistent data for the the containers. Wger/Django doesnt like that. If i map it local just as its written in the compose (static:/home/wger/static) it all works fine. Nginx is served to nginx and it works just fine. Is there something that I need to change to allow it to write/accept that location. Is it settings.py? Think this might be where several people are getting hung up on.

Thanks

Static root is /home/wger/static and media root (for uploaded files) /home/wger/media, but those can be changed by setting DJANGO_MEDIA_ROOT and DJANGO_STATIC_ROOT in the env file. The other paths like STATIC_URL can stay the same. If that folder is writable there shouldn't be any problem. I originally started using volumes because specially under windows mounted paths were a pain and this worked fine.

I dont change /home/wger/static. just the location on my system in the docker-compose file

its srv/dev/Filelocation:/home/wger/static is how its written in the compose file. But django wont write to it.

have you tried to exec into the container and trying to write something? Perhaps you'll get some better error that way? Other than that I'm honestly out of idea

Yup I can go into portainer and root into the container and write to static folder location

I'm having the same issue. How did you figure it out ?

Are you running all three containers? Can't remember what I did. Might have chmod the Wger container static folder.

I solved it by running sudo chmod -R ugo+rw /home/wger/static inside docker container