Add extraRunParams for hooks, commands, and crons#92
Open
emanuelefaja wants to merge 1 commit intoletsdiscodev:mainfrom
Open
Add extraRunParams for hooks, commands, and crons#92emanuelefaja wants to merge 1 commit intoletsdiscodev:mainfrom
emanuelefaja wants to merge 1 commit intoletsdiscodev:mainfrom
Conversation
Adds a new `extraRunParams` field to disco.json services, passed as
extra arguments to `docker container create` when running hooks
(`hook:deploy:start:before`, `hook:deploy:start:after`), `disco run`
commands, cron jobs, and CGI handlers.
This is the counterpart to the existing `extraSwarmParams` (which is
passed to `docker service create` for long-running services). The two
fields are separate because `docker service create` and
`docker container create` accept different flags — for example,
`--host` for services vs `--add-host` for containers.
Example use case in disco.json:
{
"services": {
"web": {
"port": 8000,
"extraSwarmParams": "--host host.docker.internal:host-gateway"
},
"hook:deploy:start:before": {
"type": "command",
"command": "npx prisma migrate deploy",
"extraRunParams": "--add-host host.docker.internal:host-gateway"
}
}
}
This allows hook containers to reach services running on the Docker
host (e.g. a database proxy listening on the host network) via
host.docker.internal, matching the behavior of the web service.
Author
|
@gregsadetsky let me know if you've got any feedback on this PR. |
Member
|
Thank you! We'll take a look and get back to you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
extraSwarmParamsworks great for long-running services (docker service create), but hooks (hook:deploy:start:before,hook:deploy:start:after),disco runcommands, cron jobs, and CGI handlers usedocker container createinstead — and they don't support any extra Docker parameters.This becomes a problem when containers need to reach services on the Docker host. For example, if you run a database proxy (like ProxySQL or PgBouncer) on the host machine, services can reach it via
--host host.docker.internal:host-gatewayinextraSwarmParams. But deploy hooks that need to run database migrations can't reach the proxy at all, because hooks don't support extra params.We ran into this during a database migration: our Prisma migration hook (
npx prisma migrate deploy) needed to connect to a database proxy on the host, but the hook container couldn't resolvehost.docker.internal. We had to remove the migration hook fromdisco.jsonentirely and run migrations manually as a workaround.Solution
Add a new
extraRunParamsfield to the service definition indisco.json. This is passed as extra arguments todocker container createfor:hook:deploy:start:beforehook:deploy:start:afterdisco runcommandsThis is separate from
extraSwarmParamsbecausedocker service createanddocker container createaccept different flags (e.g.--hostvs--add-host).Example
{ "services": { "web": { "port": 8000, "extraSwarmParams": "--host host.docker.internal:host-gateway" }, "hook:deploy:start:before": { "type": "command", "command": "npx prisma migrate deploy", "extraRunParams": "--add-host host.docker.internal:host-gateway" } } }Changes
discofile.py: AddextraRunParamsfield to Service modeldocker.py: Addextra_paramsargument torun()functiondeploymentflow.py: PassextraRunParamsto both before/after deploy hookscommandruns.py: PassextraRunParamstodisco runcommandsasyncworker.py: PassextraRunParamsto cron jobscgi.py: PassextraRunParamsto CGI handlers