faint-dress-64989
12/08/2022, 6:45 PMpex_binary
build option has a param restartable
that can be set too true so an application can be restarted automatically when input files changes. This seems to be integrated with the pants run goal. I want to get this same functionality when running applications using docker-compose. Generally I would do this with a volume plus some kind of setting (ie reload w/ fastapi
). I'm not sure how to propagate pex changes to docker-compose to restart my container. I was wondering if any one has a solution to this more specifically with a container running fastapi.enough-analyst-54434
12/08/2022, 6:47 PMPEX_INHERIT_PATH=prefer PYTHONPATH=. ...docker commands ...
.
too.faint-dress-64989
12/08/2022, 6:51 PMenough-analyst-54434
12/08/2022, 6:51 PMfaint-dress-64989
12/08/2022, 6:51 PMenough-analyst-54434
12/08/2022, 6:51 PMfaint-dress-64989
12/08/2022, 6:52 PMversion: "3.9"
services:
service:
build: .
command: uvicorn app.main:app --host 0.0.0.0 --port 80 --reload
ports:
- "80:80"
volumes:
- ./app:/rate-service/app
restart: on-failure
enough-analyst-54434
12/08/2022, 6:52 PMfaint-dress-64989
12/08/2022, 6:53 PMPEX_INHERIT_PATH
are you referring to a volume for the pex file that gets build in dist/
?enough-analyst-54434
12/08/2022, 6:55 PMpex --help-variables
is your friend, but all this is doing is:
1. Breaking PEX hermeticity. PEXes will not allow the environment to leak in by default. PEX_INHERIT_PATH=prefer
tells PEX to pre-pend any PYTHONPATH
env var set to sys.path
2. Adding your volume mounted code to PYTHONPATH
faint-dress-64989
12/08/2022, 6:57 PMenough-analyst-54434
12/08/2022, 6:57 PMfaint-dress-64989
12/08/2022, 6:57 PMdocker-compose up
enough-analyst-54434
12/08/2022, 6:58 PMfaint-dress-64989
12/08/2022, 6:59 PMdocker_image
the container rebuilds, but it doesn't kill the old container meaning I can start the new container on the same portenough-analyst-54434
12/08/2022, 6:59 PMfaint-dress-64989
12/08/2022, 7:00 PMenough-analyst-54434
12/08/2022, 7:00 PMI can run the pex file with hot reload no issuesWHere the PEX file is in the container and the sources you mutate are not, but volume mounted in?
faint-dress-64989
12/08/2022, 7:03 PMenough-analyst-54434
12/08/2022, 7:04 PMpex_binary.restartable
auto-propagates to docker_image.restartable
and that all works? Sounds reasonable, but I'd break that out in a new thread. Sorry for the noise!faint-dress-64989
12/08/2022, 7:07 PMpex_binary.restartable
to a docker-compose set up.docker_image.restartable
has a bug, but I don't really need to use if I'm starting the container with docker-compse. I just need to propagate the pex changes. For now I'll just do a ./pants run
in the background and mount the path to the pex as a volume.enough-analyst-54434
12/08/2022, 7:11 PMdocker {build,run}
faint-dress-64989
12/08/2022, 7:11 PMenough-analyst-54434
12/08/2022, 7:13 PMfaint-dress-64989
12/08/2022, 7:14 PMenough-analyst-54434
12/08/2022, 7:15 PMfaint-dress-64989
12/08/2022, 7:16 PMI already have that 3-combo working with straight up docker run.
?enough-analyst-54434
12/08/2022, 7:16 PMfaint-dress-64989
12/08/2022, 7:17 PMenough-analyst-54434
12/08/2022, 7:17 PMfaint-dress-64989
12/08/2022, 7:18 PMenough-analyst-54434
12/08/2022, 7:19 PMfaint-dress-64989
12/08/2022, 7:22 PMpants run src/python/app: pex && docker-compose up
enough-analyst-54434
12/08/2022, 7:23 PM