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

fix: support bulk upload when running from docker compose #2940

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kmahelona
Copy link
Contributor

Description

Bulk upload doesn't work when running in a docker-compose environment if the public_url is set to localhost. The fix here sets the api url to LIBRETIME_GENERAL_PUBLIC_URL environment variable if it exists. If it doesn't, then it defaults to the settings.CONFIG.genera.public_url. LIBRETIME_GENERAL_PUBLIC_URL is only set in docker compose (from what I can tell via search).

This is a new feature:
No

I have updated the documentation to reflect these changes:
The documentation, docs/admin-manual/library.md, was updated to show the command for running bulk upload from docker,

docker-compose run --rm api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN

Testing Notes

From main do,

make clean dev
docker-compose run --rm api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN

The command should fail with an connection error.

How you can replicate my testing:
Checkout this PR, then run

make clean dev
docker-compose run --rm api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN

The command should run successfully if the given path has audio files.

Links

https://matrix.to/#/!mkAnQsLsibojOwmqiw:one.ems.host/$vaVktWMuUVUmLdSmXDNbPTKg0ho09V_s2BdR6Uu9wd4?via=one.ems.host&via=matrix.org&via=freie-radios.de

@kmahelona kmahelona changed the title Support bulk upload when running from docker compose fix: Support bulk upload when running from docker compose Feb 7, 2024
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (2b119ad) 70.36% compared to head (70a67b8) 70.37%.
Report is 1 commits behind head on main.

Files Patch % Lines
...ime_api/storage/management/commands/bulk_import.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2940   +/-   ##
=======================================
  Coverage   70.36%   70.37%           
=======================================
  Files         149      149           
  Lines        4033     4034    +1     
=======================================
+ Hits         2838     2839    +1     
  Misses       1195     1195           
Flag Coverage Δ
api 93.73% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kmahelona kmahelona changed the title fix: Support bulk upload when running from docker compose fix: support bulk upload when running from docker compose Feb 7, 2024
@kmahelona
Copy link
Contributor Author

Not sure how to write a test for this, #2940 (comment)

@caveman99
Copy link
Contributor

Not sure about the test, maybe ask copilot to make one for you? I found out most linter errors are avpoidable by including the pre-commit hook on your end. Ref: https://libretime.org/docs/contributor-manual/development-workflows/#pre-commit

Comment on lines +56 to +58
url = os.environ.get(
"LIBRETIME_GENERAL_PUBLIC_URL", settings.CONFIG.general.public_url
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, the config already handle env vars by itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my testing bulk import tries to call http://localhost:8000/api etc. but the docker container can't actually access that. It needs to use http://nginx:8080 instead to access the API to run the import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings.CONFIG.general.public_url = http://localhost:8000/ is the default when you spin up the compose environment.

Comment on lines +89 to +90
environment:
LIBRETIME_GENERAL_PUBLIC_URL: http://nginx:8080
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this feels risky, could we pass the env vars only when we run the bulk import ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion below makes sense rather than changing the compose. The documentation helps ensure that the right URL is set.

See the command usage to get available options.
If you're running from a docker environment, use
```bash
docker-compose run --rm api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
docker-compose run --rm api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN
docker-compose run --rm -e LIBRETIME_GENERAL_PUBLIC_URL=http://nginx:8080 api libretime-api bulk_import --path PATH_THE_DIRECTORY_TO_SCAN

Ideally I would move the import process to python, but this might do the trick for now.

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

Successfully merging this pull request may close these issues.

None yet

3 participants