Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wger on production docker doesn't use SITE_URL for images #1181

Closed
mohammadrafigh opened this issue Nov 16, 2022 · 18 comments
Closed

Wger on production docker doesn't use SITE_URL for images #1181

mohammadrafigh opened this issue Nov 16, 2022 · 18 comments

Comments

@mohammadrafigh
Copy link
Contributor

Steps to Reproduce

In production deployment using Docker, The images are returning from http://localhost instead of SITE_URL. I tried to clear cache but it doesn't work.

Expected results: The exercise images should be loaded.

Actual results: No image.

@rolandgeider
Copy link
Member

Hi! The SITE_URL setting only controls things like the url used in password reset links and such. The static files are served from /static of the IP where wger is running. Did you change something in the docker compose?

@mohammadrafigh
Copy link
Contributor Author

mohammadrafigh commented Nov 16, 2022 via email

@rolandgeider
Copy link
Member

Interesting. Is there perhaps some error in the logs? During Startup Django should collect and copy all the static files (or drop the volumes and try again)

@mohammadrafigh
Copy link
Contributor Author

mohammadrafigh commented Nov 16, 2022

Thanks for your instant support. Here are the logs without any errors:

wger_cache   | 1:C 16 Nov 2022 16:09:25.638 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
wger_cache   | 1:C 16 Nov 2022 16:09:25.638 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
wger_cache   | 1:C 16 Nov 2022 16:09:25.638 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
wger_cache   | 1:M 16 Nov 2022 16:09:25.640 * monotonic clock: POSIX clock_gettime
wger_cache   | 1:M 16 Nov 2022 16:09:25.643 * Running mode=standalone, port=6379.
wger_cache   | 1:M 16 Nov 2022 16:09:25.643 # Server initialized
wger_cache   | 1:M 16 Nov 2022 16:09:25.644 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
wger_cache   | 1:M 16 Nov 2022 16:09:25.645 * Ready to accept connections
wger_db      | 
wger_db      | PostgreSQL Database directory appears to contain a database; Skipping initialization
wger_db      | 
wger_db      | 2022-11-16 16:09:25.742 UTC [1] LOG:  starting PostgreSQL 12.13 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
wger_db      | 2022-11-16 16:09:25.743 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
wger_db      | 2022-11-16 16:09:25.744 UTC [1] LOG:  listening on IPv6 address "::", port 5432
wger_db      | 2022-11-16 16:09:25.747 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
wger_db      | 2022-11-16 16:09:25.777 UTC [21] LOG:  database system was shut down at 2022-11-16 16:09:07 UTC
wger_db      | 2022-11-16 16:09:25.786 UTC [1] LOG:  database system is ready to accept connections
wger_nginx   | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
wger_nginx   | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
wger_nginx   | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
wger_nginx   | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
wger_nginx   | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
wger_nginx   | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
wger_nginx   | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
wger_nginx   | /docker-entrypoint.sh: Configuration complete; ready for start up
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: using the "epoll" event method
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: nginx/1.22.1
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: OS: Linux 5.15.0-53-generic
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: start worker processes
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: start worker process 28
wger_nginx   | 2022/11/16 16:09:38 [notice] 1#1: start worker process 29
wger_server  | yarn install v1.22.19
wger_server  | [1/5] Validating package.json...
wger_server  | [2/5] Resolving packages...
wger_server  | [3/5] Fetching packages...
wger_server  | [4/5] Linking dependencies...
wger_server  | [5/5] Building fresh packages...
wger_server  | Done in 26.32s.
wger_server  | yarn run v1.22.19
wger_server  | $ sass wger/core/static/scss/main.scss:wger/core/static/yarn/bootstrap-compiled.css
wger_server  | Done in 7.59s.
wger_server  | Running in production mode, running collectstatic now
wger_server  | 
wger_server  | 5726 static files copied to '/home/wger/static', 10002 unmodified.
wger_server  | Performing database migrations
wger_server  | Operations to perform:
wger_server  |   Apply all migrations: actstream, auth, authtoken, axes, config, contenttypes, core, easy_thumbnails, exercises, gallery, gym, mailer, manager, measurements, nutrition, sessions, sites, weight
wger_server  | Running migrations:
wger_server  |   No migrations to apply.
wger_server  |   Your models in app(s): 'config' have changes that are not yet reflected in a migration, and so won't be applied.
wger_server  |   Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
wger_server  | Set site URL to https://wger.junglefries.space
wger_server  | Using gunicorn...
wger_server  | [2022-11-16 16:10:46 +0000] [101] [INFO] Starting gunicorn 20.1.0
wger_server  | [2022-11-16 16:10:46 +0000] [101] [INFO] Listening at: http://0.0.0.0:8000 (101)
wger_server  | [2022-11-16 16:10:46 +0000] [101] [INFO] Using worker: sync
wger_server  | [2022-11-16 16:10:46 +0000] [102] [INFO] Booting worker with pid: 102

The URL of the instance is in the logs. Feel free to take a look with default admin user/pass if it helps (since it's a new installation I don't have any data to loose).

@rolandgeider
Copy link
Member

Mhhh everything looks alright. Serving the static files is what produces the most issues to people, by far and is something I could never reproduce with this docker setup. Also that's something we don't have much control over, since they are just collected by Django but served via another process, in this case an nginx

@mohammadrafigh
Copy link
Contributor Author

Why not just use SITE_URL or another environment variable for images? I don't know how to resolve this problem. Maybe I should go into the container and modify URLs manually to let it work for now. Although it's not a good solution but just to try it where should I look into? I'm not a Python expert, So it would be great if you can guide me.

@rolandgeider
Copy link
Member

You can open the application and see which static files are being retrieved and try if you can access them with SITE_URL + those urs. And in any case, this is something that shouldn't be needed, nginx serves everything and if you want, you can put everything behind a reverse proxy so from the outside wger looks like a single application (which it is, in the end)

@rolandgeider
Copy link
Member

oh, did you do something, it seems to be working now :)

@mohammadrafigh
Copy link
Contributor Author

The server was down because I forgot to restart it sorry. But It's still not working for example see the screenshot below:

Screenshot from 2022-11-16 23-03-42

The image prefixed address is http://localhost...
Reverse proxy won't work because the URL inside image is wrong.

@rolandgeider
Copy link
Member

Ahh, I know why only those don't work. These URLs come from the API which doesn't know the outside domain. There we could definitely use SITE_URL

@mohammadrafigh
Copy link
Contributor Author

Yes but SITE_URL is correctly set as you can see in logs. It seems it's ignored for images.
wger_server | Set site URL to https://wger.junglefries.space

@rolandgeider
Copy link
Member

yeah, it's currently not used in the API

@rolandgeider
Copy link
Member

Alright, have opened a new issue for the fix

@mohammadrafigh
Copy link
Contributor Author

Also it's not working when contributing a new exercise, uploaded image uses localhost too. BTW (It's another issue) can you please take a look at contribute a new exercise? at descriptions stage the UI is completely broken something is not loaded correctly.

Screenshot from 2022-11-16 23-26-28

@rolandgeider
Copy link
Member

I thought I had fixed that. That part of the application is react which is embedded in the regular Django app. Making sure the CSS classes don't class was… fun

@mohammadrafigh
Copy link
Contributor Author

It's fixed as stated in #1182. Thanks for your support.

@mohammadrafigh
Copy link
Contributor Author

@rolandgeider should I create another issue for the screenshot I sent above?

@rolandgeider
Copy link
Member

@mohammadrafigh yes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants