Skip to content

Add extraRunParams for hooks, commands, and crons#92

Open
emanuelefaja wants to merge 1 commit intoletsdiscodev:mainfrom
emanuelefaja:feature/extra-run-params
Open

Add extraRunParams for hooks, commands, and crons#92
emanuelefaja wants to merge 1 commit intoletsdiscodev:mainfrom
emanuelefaja:feature/extra-run-params

Conversation

@emanuelefaja
Copy link
Copy Markdown

Problem

extraSwarmParams works great for long-running services (docker service create), but hooks (hook:deploy:start:before, hook:deploy:start:after), disco run commands, cron jobs, and CGI handlers use docker container create instead — 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-gateway in extraSwarmParams. 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 resolve host.docker.internal. We had to remove the migration hook from disco.json entirely and run migrations manually as a workaround.

Solution

Add a new extraRunParams field to the service definition in disco.json. This is passed as extra arguments to docker container create for:

  • hook:deploy:start:before
  • hook:deploy:start:after
  • disco run commands
  • Cron jobs
  • CGI handlers

This is separate from extraSwarmParams because docker service create and docker container create accept different flags (e.g. --host vs --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: Add extraRunParams field to Service model
  • docker.py: Add extra_params argument to run() function
  • deploymentflow.py: Pass extraRunParams to both before/after deploy hooks
  • commandruns.py: Pass extraRunParams to disco run commands
  • asyncworker.py: Pass extraRunParams to cron jobs
  • cgi.py: Pass extraRunParams to CGI handlers

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.
@emanuelefaja
Copy link
Copy Markdown
Author

@gregsadetsky let me know if you've got any feedback on this PR.

@gregsadetsky
Copy link
Copy Markdown
Member

Thank you! We'll take a look and get back to you

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.

2 participants