Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "run" command #24

Open
stefanb2 opened this issue Aug 1, 2019 · 9 comments
Open

add "run" command #24

stefanb2 opened this issue Aug 1, 2019 · 9 comments
Labels
enhancement New feature or request fixed-pending-confirmation it's supposed to be fixed, waiting user to confirm

Comments

@stefanb2
Copy link
Contributor

stefanb2 commented Aug 1, 2019

To quote from docker-compose CLI documentation:

Runs a one-time command against a service. For example, the following command starts the web service and runs bash as its command.

docker-compose run web bash

We use several different docker-compose YAML files in our projects, with various one-shot "helper commands" for different tasks a developer might need to perform, e.g. database setup.

Those tasks are performed by standard non-project specific images provided by our internal repository. I.e. the developer doesn't have to install anything or remember a complicated command line to perform those tasks. He simply types e.g.

docker-compose -f docker-compose.dev.yml run mysql-init

on any project to initialize the MySQL database to such a state that he can start working on the project.

The YAML file provides an easy way to supply the parameters, e.g.

mysql-init:
  env_file:
    - .dev.env
  image: <repo name>/<path>/mysql-init:5.7
  network_mode: host

Furthermore the file is under project version control.

Without the run command I have to translate the exisiting YAML file contents to the following command line:

podman run --rm -it --env-file .dev.env --network host <repo name>:5004/<path>/mysql-init:5.7
@muayyad-alsadi muayyad-alsadi added the enhancement New feature or request label Aug 8, 2019
@muayyad-alsadi
Copy link
Collaborator

it's now much easier to add more commands using @cmd_run(podman_compose, cmd_name, cmd_desc)

see CONTRIBUTING.md

@muayyad-alsadi
Copy link
Collaborator

@stefanb2 there are some missing features like passing custom -l and -e and -v.

please test

$ python3 podman-compose.py -f examples/busybox/docker-compose.yaml run -h
usage: podman-compose.py run [-h] [-d] [--name NAME] [--entrypoint ENTRYPOINT]
                             [-e KEY=VAL] [-l KEY=VAL] [-u USER] [--no-deps]
                             [--rm] [-p PUBLISH] [--service-ports] [-v VOLUME]
                             [-T] [-w WORKDIR]
                             service ...

create a container similar to a service to run a one-off command

positional arguments:
  service               service name
  command               comman and its args

optional arguments:
  -h, --help            show this help message and exit
  -d, --detach          Detached mode: Run container in the background, print
                        new container name.
  --name NAME           Assign a name to the container
  --entrypoint ENTRYPOINT
                        Override the entrypoint of the image.
  -e KEY=VAL            Set an environment variable (can be used multiple
                        times)
  -l KEY=VAL, --label KEY=VAL
                        Add or override a label (can be used multiple times)
  -u USER, --user USER  Run as specified username or uid
  --no-deps             Don't start linked services
  --rm                  Remove container after run. Ignored in detached mode.
  -p PUBLISH, --publish PUBLISH
                        Publish a container's port(s) to the host (can be used
                        multiple times)
  --service-ports       Run command with the service's ports enabled and
                        mapped to the host.
  -v VOLUME, --volume VOLUME
                        Bind mount a volume (can be used multiple times)
  -T                    Disable pseudo-tty allocation. By default `podman-
                        compose run` allocates a TTY.
  -w WORKDIR, --workdir WORKDIR
                        Working directory inside the container
$ python3 podman-compose.py -f examples/busybox/docker-compose.yaml run --rm redis /bin/sh -c 'cat /etc/passwd'
# podman run --rm -i --name=busybox_redis_tmp60155 --pod=busybox ...
root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
...
redis:x:999:1000:Linux User,,,:/home/redis:/sbin/nologin
0

if it's not detached I make it interactive so you can run /bin/sh
please tell me if this behaviour is correct

@muayyad-alsadi muayyad-alsadi added the fixed-pending-confirmation it's supposed to be fixed, waiting user to confirm label Aug 10, 2019
@stefanb2
Copy link
Contributor Author

stefanb2 commented Aug 10, 2019

Looks like you beat me to the punch. I started to work on an implementation yesterday. Unfortunately your changes seem to have broken the script completely.

If I take HEAD (7e0a036) I can't get podman-compose.py run XXX to work at all: the command parser sees XXX as the command instead of run. If I checkout HEAD^ (eb72a71) then it seems podman-compose.py run XXX does what it is supposed to do.

But commit eb72a71 broke podman-compose.py -t identity up completely, so I can't really test your changes:

  File ".../podman-compose.py", line 364, in mount_desc_to_args
    mount_desc = mount_dict_vol_to_bind(compose, fix_mount_dict(mount_desc, srv_name, cnt_name))
  File ".../podman-compose.py", line 334, in mount_dict_vol_to_bind
    proj_name = compose.proj_name
AttributeError: 'PodmanCompose' object has no attribute 'proj_name'

Looks like a typo and that line should instead read:

    proj_name = compose.project_name

muayyad-alsadi added a commit that referenced this issue Aug 10, 2019
@muayyad-alsadi
Copy link
Collaborator

Looks like a typo and that line should instead read:

yes, I've fixed that typo.

@mariushoch
Copy link
Contributor

I got this working, but only with #43

@agriffis
Copy link

This works for me on master, but one note, it always tries to re-create the pod:

✸ docker-compose run app /bin/bash
podman pod create --name=search --share net -p 8000:8000
Error: unable to create pod: error adding pod to state: name search is in use: pod already exists
125
...snip...
root@6bed1a5d3f2d:/app# exit

@westurner
Copy link

Would this make exec easier to implement or would that need a separate implementation?

@stacyharper
Copy link

Got a prob with the run command

#!/bin/sh -x
#/entrypoint.sh

echo "$@"
exit 1
$ podman-compose run app foo bar
+ echo
+ exit 1

It seems my args are not passed to the entrypoint.

Is it a bug? Have I missed something?

@muayyad-alsadi
Copy link
Collaborator

I'll try to look at issue this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed-pending-confirmation it's supposed to be fixed, waiting user to confirm
Projects
None yet
Development

No branches or pull requests

6 participants