openverse-api
openverse-api copied to clipboard
Add a recipe `ps` that runs after `up`
Fixes
Fixes #952 by @zackkrida
Description
This PR adds a recipe ps that invokes a Python script to parse the output of docker-compose ps and generate a list of URLs for each running service.
It currently does not see to verify if something is indeed running at that URLs (notably API port 50230, which is usually bound but rarely used).
Testing Instructions
- Checkout this PR and run
just up. - See the list of services being printed automatically after
upis complete. - Run
just ps. - See the list of services.
Screenshots
In iTerm2, these URLs are clickable with Cmd held down, super helpful!
Checklist
- [x] My pull request has a descriptive title (not a vague title like
Update index.md). - [x] My pull request targets the default branch of the repository (
main) or a parent feature branch. - [x] My commit messages follow best practices.
- [x] My code follows the established code style of the repository.
- [ ] I added or updated tests for the changes I made (if applicable).
- [x] I added or updated documentation (if applicable).
- [x] I tried running the project locally and verified that there are no visible errors.
Developer Certificate of Origin
Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
API Developer Docs Preview: Ready
https://wordpress.github.io/openverse-api/_preview/959
Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.
You can check the GitHub pages deployment action list to see the current status of the deployments.
@stacimc you might be right, I have docker-compose and docker compose set to the same thing! This means that this PR will not work for anyone using the docker-compose v1.
$ docker-compose --version
Docker Compose version v2.10.2
$ docker compose version
Docker Compose version v2.10.2
I might have to find a different way to do this that works across Docker Compose v1 and v2. It might be difficult though, would be easier if we could just support the new versions and put the version requirements in our prerequisites.
@dhruvkb both my docker compose and docker-compose are version 2.10.2 yet I still see this error:
openverse-api on just_ps +/- [$] took 3m18s
❯ just ps
Traceback (most recent call last):
File "/Users/zackkrida/Code/openverse/openverse-api/scripts/ps.py", line 85, in <module>
print_ps()
File "/Users/zackkrida/Code/openverse/openverse-api/scripts/ps.py", line 80, in print_ps
for service in parse_ps():
File "/Users/zackkrida/Code/openverse/openverse-api/scripts/ps.py", line 65, in parse_ps
for publisher in publishers:
TypeError: 'NoneType' object is not iterable
error: Recipe `ps` failed on line 56 with exit code 1
@zackkrida can you post the output of the following command?
$ docker compose ps --format json
Technically the value of Publishers in the JSON can be null, which would explain the error you're seeing but all our services have either expose a port or bind to a port on the host so that shouldn't be happening.
Hey @dhruvkb, I'm checking on draft PRs. Is there anything blocking you from completing the PR? Should be closed or can be resumed soon?
I'm waiting for @zackkrida's response to this comment. That'll help identify the difference in the JSON that's causing the error. I made this a draft because so that it doesn't disturb reviewers.
@dhruvkb here is the output:
[
{
"ID": "c2f1d732e98379418a938acd4c14d62030e9b777dc98469bf25f52552aadb92b",
"Name": "openverse-api_cache_1",
"Command": "docker-entrypoint.sh redis-server",
"Project": "openverse-api",
"Service": "cache",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 6379,
"PublishedPort": 50263,
"Protocol": "tcp"
}
]
},
{
"ID": "ebf9c9d88432c0ed8e6c17bfc69e24d7a2c7b4d2e17ab27f2e85962f11685a10",
"Name": "openverse-api_db_1",
"Command": "docker-entrypoint.sh postgres",
"Project": "openverse-api",
"Service": "db",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 5432,
"PublishedPort": 50254,
"Protocol": "tcp"
}
]
},
{
"ID": "fa5ae4ff3231abeef55d2d3068770dab1aec5f1aa7939c9e82aa6fc2bd33270c",
"Name": "openverse-api_es_1",
"Command": "/bin/tini -- /usr/local/bin/docker-entrypoint.sh eswrapper",
"Project": "openverse-api",
"Service": "es",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 9200,
"PublishedPort": 50292,
"Protocol": "tcp"
},
{
"URL": "",
"TargetPort": 9300,
"PublishedPort": 0,
"Protocol": "tcp"
}
]
},
{
"ID": "3e2356c09bbe378db708515f59f332ca3735e8edbc15ae5a0fd761e6669de3fa",
"Name": "openverse-api_indexer_worker_1",
"Command": "gunicorn -c ./gunicorn_worker.conf.py",
"Project": "openverse-api",
"Service": "indexer_worker",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "",
"TargetPort": 8001,
"PublishedPort": 0,
"Protocol": "tcp"
},
{
"URL": "",
"TargetPort": 8002,
"PublishedPort": 0,
"Protocol": "tcp"
}
]
},
{
"ID": "ff866d680ba45a63c538c5f26a0d7461e0d4ac665ce40a4fd4a8e0363f8f1fb4",
"Name": "openverse-api_ingestion_server_1",
"Command": "gunicorn -c ./gunicorn.conf.py",
"Project": "openverse-api",
"Service": "ingestion_server",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 8001,
"PublishedPort": 50281,
"Protocol": "tcp"
},
{
"URL": "",
"TargetPort": 8002,
"PublishedPort": 0,
"Protocol": "tcp"
}
]
},
{
"ID": "b795ed180a4a6d9c12457215189387890c6ba9fd78a41b4f439c72aa1b0ab371",
"Name": "openverse-api_proxy_1",
"Command": "/docker-entrypoint.sh nginx -g 'daemon off;'",
"Project": "openverse-api",
"Service": "proxy",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "",
"TargetPort": 80,
"PublishedPort": 0,
"Protocol": "tcp"
},
{
"URL": "0.0.0.0",
"TargetPort": 9080,
"PublishedPort": 50200,
"Protocol": "tcp"
},
{
"URL": "0.0.0.0",
"TargetPort": 9443,
"PublishedPort": 50243,
"Protocol": "tcp"
}
]
},
{
"ID": "6b66d48c2388719d5e776cd4f014db637e155705c311c75bc94108032ec868cf",
"Name": "openverse-api_thumbnails_1",
"Command": "/usr/local/bin/imaginary -enable-url-source -forward-headers User-Agent",
"Project": "openverse-api",
"Service": "thumbnails",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "",
"TargetPort": 8222,
"PublishedPort": 0,
"Protocol": "tcp"
},
{
"URL": "",
"TargetPort": 9000,
"PublishedPort": 0,
"Protocol": "tcp"
}
]
},
{
"ID": "ef52be6a30eaf5331146c3c3e3d037d072459a65b5962a8cd15d201a69927fa0",
"Name": "openverse-api_upstream_db_1",
"Command": "docker-entrypoint.sh postgres",
"Project": "openverse-api",
"Service": "upstream_db",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "",
"TargetPort": 5432,
"PublishedPort": 0,
"Protocol": "tcp"
}
]
},
{
"ID": "ecea6ee5b704942c358449dd448924a2b8aca657d92871779943ee96d158bb1e",
"Name": "openverse-api_web_1",
"Command": "./run.sh python manage.py runserver 0.0.0.0:8000",
"Project": "openverse-api",
"Service": "web",
"State": "exited",
"Health": "",
"ExitCode": 255,
"Publishers": [
{
"URL": "0.0.0.0",
"TargetPort": 3000,
"PublishedPort": 50230,
"Protocol": "tcp"
},
{
"URL": "0.0.0.0",
"TargetPort": 8000,
"PublishedPort": 50280,
"Protocol": "tcp"
}
]
}
]
Since none of those items has Publishers not present or empty or null, it's unclear why
for publisher in publishers:
TypeError: 'NoneType' object is not iterable
would appear. I'll just close this PR and maybe come back to this issue sometime in the future.