Skip to content

Commit

Permalink
Add initial functionalities (#2)
Browse files Browse the repository at this point in the history
* Add initial functionalities

* Improve CI

* Remove podman from the conda env file
  • Loading branch information
xmnlab committed Jan 20, 2023
1 parent 0878317 commit e73a0b5
Show file tree
Hide file tree
Showing 12 changed files with 2,885 additions and 17 deletions.
27 changes: 27 additions & 0 deletions .containers-sugar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 1.0.0
compose-app: docker-compose
service-groups:
- name: group1
project-name: project1 # optional
compose-path: containers/tests/group1/compose.yaml
env-file: .env
services:
default: service1,service3
list:
- name: service1
health-check: true
- name: service2
health-check: false
- name: service3
health-check: true
- name: group2
project-name: null # optional
compose-path: containers/tests/group2/compose.yaml
env-file: .env
services:
default: null
list:
- name: service1
health-check: true
- name: service1
health-check: false
8 changes: 6 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ jobs:
run: poetry install

- name: Run tests
run: make test
run: |
containers-sugar help
containers-sugar version
containers-sugar build --group group1 --services ""
containers-sugar build --group group2 --services ""
- name: Run style checks
if: success() || failure()
run: |
pre-commit install
make lint
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.formatting.blackPath": "/home/xmn/mambaforge/envs/containers-sugar/bin/blue",
"python.formatting.provider": "black"
}
87 changes: 82 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,93 @@
# containers-sugar

Simplify the usage of containers
Simplify the usage of containers.

You maybe would be thinking, why I need new library that wrap-up
docker-compose or podman-compose if it is really simple to use?

Yes, that is simple to use, but if you have some other parameters to
the compose command line, it could be very tedious to right it every time
such as `--env-file`, `--project-name`, `--file`, etc.

So, in this case we could use something like a script or `make`, right?

Yes, and just for one project it would be good enough. But, if you maintain
or collaborate a bunch of projects, it would be like a boiler plate.

Additionally, if you are maintaining some extra scripts in order to improve
your containers stack, these scripts would be like a boilerplate as well.

So, the idea of this project is to organize the containers stack and
gather some useful scripts and keep this information centralized in a
configuration file. So the command line would be very simple.


* Free software: BSD 3 Clause
* Documentation: https://containers-sugar.readthedocs.io.
* Documentation: https://osl-incubator.github.io/containers-sugar


## Features

* TODO

## Credits
The commands availables now are:
`help`, `version`, `build`, `down`, `get-ip`,
`logs`, `logs-follow`, `pull`, `restart`,
`start`, `stop`, `wait`.

> Note: get-ip and wait were not implemented yet.

## How to use it

First you need to have in the root of your project the config file `.containers-sugar.yaml`. This is an example of a configuration file:

```yaml
version: 1.0.0
compose-app: docker-compose
service-groups:
- name: group1
project-name: project1 # optional
compose-path: containers/tests/group1/compose.yaml
env-file: .env
services:
default: service1,service3
list:
- name: service1
health-check: true
- name: service2
health-check: false
- name: service3
health-check: true
- name: group2
project-name: null # optional
compose-path: containers/tests/group2/compose.yaml
env-file: .env
services:
default: null
list:
- name: service1
health-check: true
- name: service1
health-check: false
```
Some examples of how to use it:
* build the defaults services (service1,service3) for group1:
`containers-sugar build --group group1`

* build the all services (there is no default service defined) for group2:
`containers-sugar build --group group2`

* build all services (ignore default) for group1:
`containers-sugar build --group group1 --service ""`

* start the default services for group1:
`containers-sugar start --group group1`

* restart all services (ignore defaults) for group1:
`containers-sugar restart --group group1 --service ""`

This package was created with Cookiecutter and the `osl-incubator/cookiecutter-python` project template.
* restart service1 and service2 for group1:
`containers-sugar restart --group group1 --service service1,service2`
23 changes: 23 additions & 0 deletions containers/tests/group1/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.4'

services:
service1:
hostname: service1
image: python:latest
ports:
- 18000:8000
command: python -m http.server

service2:
hostname: service2
image: python:latest
ports:
- 18001:8000
command: python -m http.server

service3:
hostname: service2
image: python:latest
ports:
- 18002:8000
command: python -m http.server
16 changes: 16 additions & 0 deletions containers/tests/group2/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.4'

services:
service1:
hostname: service1
image: python:latest
ports:
- 28000:8000
command: python -m http.server

service2:
hostname: service2
image: python:latest
ports:
- 28001:8000
command: python -m http.server
3 changes: 3 additions & 0 deletions containers_sugar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
__author__ = 'Ivan Ogasawara'
__email__ = 'ivan.ogasawara@gmail.com'
__version__ = '1.0.0'


from containers_sugar.sugar import Sugar
68 changes: 68 additions & 0 deletions containers_sugar/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import argparse
import os
from pathlib import Path

from containers_sugar import __version__, Sugar


def _get_args():
parser = argparse.ArgumentParser(
prog='Containers-Sugar',
description=(
'Containers-Sugar is a tool that help you to organize'
"and simplify your containers' stack"
),
epilog=(
'If you have any problem, open an issue at: '
'https://github.com/osl-incubator/containers-sugar'
),
)

parser.add_argument(
'action',
choices=['help', 'version'] + Sugar.ACTIONS,
help='Specify the command to be performed.',
)
parser.add_argument(
'--service-group', '--group',
dest="service_group",
type=str,
help='Specify the group name of the services you want to use',
)
parser.add_argument(
'--services',
type=str,
help=(
'Set the services for the container call. '
"Use comma to separate the services's name"
),
)
parser.add_argument(
'--config-file',
type=str,
default=str(Path(os.getcwd()) / '.containers-sugar.yaml'),
help='Specify a custom location for the config file.',
)
return parser


def show_version():
print(__version__)


def app():
args_parser = _get_args()
args = args_parser.parse_args()

if args.action == 'help':
return args_parser.print_help()

if args.action == 'version':
return show_version()

sugar = Sugar(args)
return sugar.run()


if __name__ == '__main__':
app()
1 change: 0 additions & 1 deletion containers_sugar/containers_sugar.py

This file was deleted.

Loading

0 comments on commit e73a0b5

Please sign in to comment.