dnephin / dobi

A build automation tool for Docker applications
https://dnephin.github.io/dobi/
Apache License 2.0
309 stars 36 forks source link

Pass arguments to jobs from command line #159

Closed Fuco1 closed 5 years ago

Fuco1 commented 5 years ago

Would it be possible to pass arguments from commandline to dobi jobs?

I can kind of work around it with env variables but it's quite klunky.

dnephin commented 5 years ago

I've been thinking about what that might look like in #91. Right now args are all expected to be task names. I don't see an obvious way to make this work a command for each task.

Fuco1 commented 5 years ago

Let's close this and track in 91, that covers the use-case.

airtonix commented 4 years ago

91 is about build args (which would be great to influence when I run a job on the cli too)

But I feel this ticket is about passing args to commands that would run after the image is built:

We currently use npm-scripts (with npm-run-all, cross-env, cross-var) to provide a cli interface to all our docker-compose tasks... but we want something that supports a help menu with obvious commands the user would use.

currently, we'd have a package.json like:

{
  "name": "the-project",
  "scripts": {
    "compose:run": "docker-compose --rm run",
    "compose:serve": "docker-compose --rm --service-ports run",
    "backend:shell": "npm run compose:run -- backend /bin/bash",
    "frontend:shell": "npm run compose:run -- frontend /bin/bash", 
  }
}

We have many more tasks in there, but for example you see there that we're using the compose:run task again and passing different arguments to docker-compose each time. You do this with the --

So with dobi:

mount=source:
  bind: ./
  path: /opt/app

image=image_backend:
  context: .
  dockerfile: ./docker/backend/Dockerfile
  image: us/backend
  tags: [ "latest" ]

job=backend-shell:
  use: image_backend
  interactive: true
  command: /bin/bash

job=backend-pipenv:
  use: image_backend
  interactive: true
  command: pipenv

So now, it'd be awesome if I could do the following:

$ dobi backend-shell -- ls -al
$ dobi backend-pipenv -- run ./manage.py migrate
$ dobi backend-pipenv -- install django-registration

i've only use -- in the dobi commands there to illustrate that everything after that is an argument for the "inner command"