From 470f8a385180847706694cf1026de5263abb3829 Mon Sep 17 00:00:00 2001 From: Muayyad Alsadi Date: Tue, 3 Sep 2019 00:19:07 +0300 Subject: [PATCH] update readme and no arguments print help --- README.md | 105 ++++++++++++++-------- podman_compose.py | 9 +- scripts/clean_up.sh | 7 +- scripts/make_release.sh | 4 +- scripts/uninstall.sh | 2 +- setup.py | 4 +- {test => tests}/short/docker-compose.yaml | 0 {test => tests}/vol/docker-compose.yaml | 0 8 files changed, 82 insertions(+), 49 deletions(-) rename {test => tests}/short/docker-compose.yaml (100%) rename {test => tests}/vol/docker-compose.yaml (100%) diff --git a/README.md b/README.md index 9089af7..5f942ce 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,95 @@ -# podman-compose +# Podman Compose -A script to run `docker-compose.yml` using [podman](https://podman.io/), -doing necessary mapping to make it work rootless. +An implementation of `docker-compose` with [podman](https://podman.io/) backend. +The main objective of this project is to be able to run `docker-compose.yml` unmodified and rootless. +This project is aimed to provide drop-in replacement for `docker-compose`, +and it's very useful for certain cases because: + +- can run rootless +- only depend on `podman` and Python3 and [PyYAML](https://pyyaml.org/) +- no daemon, no setup. +- can be used by developers to run single-machine containerized stacks using single familiar YAML file + +For production-like single-machine containerized environment consider + +- [k3s](https://k3s.io) | [k3s github](https://github.com/rancher/k3s) +- [MiniKube](https://minikube.sigs.k8s.io/) +- [MiniShift](https://www.okd.io/minishift/) + + +For the real thing (multi-node clusters) check any production +OpenShift/Kubernetes distribution like [OKD](https://www.okd.io/minishift/). + +## NOTE + +This project is still underdevelopment. ## Installation Install latest stable version from PyPI: ``` -pip install podman-compose +pip3 install podman-compose ``` -Or latest stable version from GitHub: - -``` -pip install https://github.com/muayyad-alsadi/podman-compose/archive/master.tar.gz -``` +pass `--user` to install inside regular user home without being root. Or latest development version from GitHub: ``` -pip install https://github.com/muayyad-alsadi/podman-compose/archive/devel.tar.gz +pip3 install https://github.com/containers/podman-compose/archive/devel.tar.gz ``` -## Mappings - -* `1podfw` - create all containers in one pod (inter-container communication is done via `localhost`), doing port mapping in that pod. -* `1pod` - create all containers in one pod, doing port mapping in each container. -* `identity` - no mapping. -* `hostnet` - use host network, and inter-container communication is done via host gateway and published ports. -* `cntnet` - create a container and use it via `--network container:name` (inter-container communication via `localhost`). -* `publishall` - publish all ports to host (using `-P`) and communicate via gateway. - -## Examples - -When testing the `AWX`, if you got errors just wait for db migrations to end. - -### Working Example - -*Tested on latest ``podman`` (commit `349e69..` on 2019-03-11).* - -By using many containers on a single pod that shares the network (services talk -via localhost): +or ``` -podman-compose -t 1podfw -f examples/awx3/docker-compose.yml up +curl -o /usr/local/bin/podman_compose https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py +chmod +x /usr/local/bin/podman_compose ``` -Or by reusing a container network and `--add-host`: +or ``` -podman-compose -t cntnet -f examples/awx3/docker-compose.yml up +curl -o ~/.local/bin/podman_compose https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py +chmod +x ~/.local/bin/podman_compose ``` -Or by using host network and localhost works as follows: +## Basic Usage + +We have included fully functional sample stacks inside `examples/` directory. + +A quick example would be ``` -podman-compose -t hostnet -f examples/awx3-hostnet-localhost/docker-compose.yml up +cd examples/busybox +podman-compose --help +podman-compose up --help +podman-compose up ``` -### Work in progress +A more rich example can be found in [examples/awx3](examples/awx3) +which have + +- A Postgres Database +- RabbitMQ server +- MemCached server +- a django web server +- a django tasks + + +When testing the `AWX3` example, if you got errors just wait for db migrations to end. + + +## Tests + +Inside `tests/` directory we have many useless docker-compose stacks +that are meant to test as much cases as we can to make sure we are compatible + +## How it works + +The default mapping `1podfw` creates a single pod and attach all containers to +its network namespace so that all containers talk via localhost. +For more information see [docs/Mappings.md](docs/Mappings.md). + +If you are running as root, you might use identity mapping. -``` -podman-compose -t 1pod -f examples/awx3/docker-compose.yml up -``` diff --git a/podman_compose.py b/podman_compose.py index 36aa27b..fea8f40 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -734,12 +734,14 @@ class PodmanCompose: parser = argparse.ArgumentParser() self._init_global_parser(parser) subparsers = parser.add_subparsers(title='command', dest='command') - subparsers.default = 'up' for cmd_name, cmd in self.commands.items(): subparser = subparsers.add_parser(cmd_name, help=cmd._cmd_desc) for cmd_parser in cmd._parse_args: cmd_parser(subparser) self.global_args = parser.parse_args() + if not self.global_args.command: + parser.print_help() + exit(-1) return self.global_args def _init_global_parser(self, parser): @@ -893,8 +895,9 @@ def compose_up(compose, args): podman_args = container_to_args(compose, cnt, detached=args.detach, podman_command=podman_command) compose.podman.run(podman_args) - if args.no_start or args.detach: return - + if args.no_start or args.detach or args.dry_run: return + # TODO: handle already existing + # TODO: if error creating do not enter loop # TODO: colors if sys.stdout.isatty() threads = [] diff --git a/scripts/clean_up.sh b/scripts/clean_up.sh index e909bb9..562b8c3 100755 --- a/scripts/clean_up.sh +++ b/scripts/clean_up.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -find . -name "*.pyc" -exec rm -rf {} \; -find . -name "__pycache__" -exec rm -rf {} \; -find . -name "*.orig" -exec rm -rf {} \; + +find . -name "*.pyc" -delete +find . -name "__pycache__" -delete +find . -name "*.orig" -delete rm -rf .cache/ rm -rf build/ rm -rf builddocs/ diff --git a/scripts/make_release.sh b/scripts/make_release.sh index abc6e12..507bbee 100755 --- a/scripts/make_release.sh +++ b/scripts/make_release.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash ./scripts/uninstall.sh ./scripts/clean_up.sh -python setup.py register -python setup.py sdist bdist_wheel +python3 setup.py register +python3 setup.py sdist bdist_wheel twine upload dist/* diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 613747b..a8e4a26 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -pip uninstall podman-compose -y +pip3 uninstall podman-compose -y ./scripts/clean_up.sh diff --git a/setup.py b/setup.py index 1da77c8..0cb939e 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ try: except: readme = '' -version = '0.1.3' +version = '0.1.4' setup( name='podman-compose', @@ -31,7 +31,7 @@ setup( keywords='podman, podman-compose', author='Muayyad Alsadi', author_email='alsadi@gmail.com', - url='https://github.com/muayyad-alsadi/podman-compose', + url='https://github.com/containers/podman-compose', py_modules=['podman_compose'], entry_points={ 'console_scripts': [ diff --git a/test/short/docker-compose.yaml b/tests/short/docker-compose.yaml similarity index 100% rename from test/short/docker-compose.yaml rename to tests/short/docker-compose.yaml diff --git a/test/vol/docker-compose.yaml b/tests/vol/docker-compose.yaml similarity index 100% rename from test/vol/docker-compose.yaml rename to tests/vol/docker-compose.yaml