Skip to content

Commit

Permalink
feat(experimental): Add new docker compose commands: attach, cp, ls, …
Browse files Browse the repository at this point in the history
…scale, wait, watch (#122)
  • Loading branch information
xmnlab committed May 16, 2024
1 parent 6b4dca5 commit 4a28eee
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 130 deletions.
13 changes: 13 additions & 0 deletions .makim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ groups:
sugar rm --verbose --group group1 --options --force
sugar down --verbose --group group1
smoke-experimental:
help: Run simple text for experimental commands
dependencies:
- task: docker.killall
run: |
sugar attach --options --help
sugar cp --options --help
sugar ls --options --help
sugar scale --options --help
sugar wait --options --help
sugar watch --options --help
smoke:
help: Run final smoke tests
dependencies:
Expand All @@ -183,6 +195,7 @@ groups:
- task: tests.smoke-defaults
- task: tests.smoke-final
- task: tests.smoke-services
- task: tests.smoke-experimental
run: |
sugar --help
sugar --version
Expand Down
2 changes: 1 addition & 1 deletion .sugar.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1.0
compose-app: docker compose
compose-app: docker-compose
env-file: .env
defaults:
group: {{ env.KXGR_GROUP }}
Expand Down
250 changes: 125 additions & 125 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mkdocs-macros-plugin = ">=0.7.0,<1"
mkdocs-material = ">=9.1.15"
mkdocstrings = {version=">=0.19.0", extras=["python"]}
makim = ">=1.12.1"
compose-go = ">=1.23.0"
compose-go = ">=1.27.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
295 changes: 293 additions & 2 deletions src/sugar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,57 @@ def create_main_group(sugar_app: typer.Typer):
"""
# -- Main commands --

@sugar_app.command()
def attach(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
service: str = Option(
None, help='Set the service for the container call.'
),
options: str = Option(
None,
help=(
'Specify the options for docker-compose command. '
'E.g.: --options -d'
),
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
Attach to a service's running container.
Attach local standard input, output, and error streams to a service's
running container.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'attach'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def build(
ctx: typer.Context,
Expand Down Expand Up @@ -190,6 +241,51 @@ def config(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def cp(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help=(
'Specify the options for docker-compose command. '
'E.g.: --options -d'
),
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
Copy files/folders between a services and local filesystem.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'cp'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def create(
ctx: typer.Context,
Expand Down Expand Up @@ -522,6 +618,49 @@ def logs(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def ls(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
List running compose projects.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'ls'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def pause(
ctx: typer.Context,
Expand Down Expand Up @@ -901,6 +1040,49 @@ def run(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def scale(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
Scale services.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'scale'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def start(
ctx: typer.Context,
Expand Down Expand Up @@ -1185,6 +1367,115 @@ def version(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def wait(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
services: str = Option(
None,
help="Set the services for the container call.\
Use comma to separate the services's name",
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
all: bool = Option(
False,
help='Use all services for the command.',
is_flag=True,
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
Block until the first service container stops.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'wait'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def watch(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
services: str = Option(
None,
help="Set the services for the container call.\
Use comma to separate the services's name",
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
all: bool = Option(
False,
help='Use all services for the command.',
is_flag=True,
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""
Watch build context.
Watch build context for service and rebuild/refresh containers when
files are updated.
Note: This is an experimental feature.
"""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'watch'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()


def create_ext_group(sugar_app: typer.Typer):
"""
Expand Down Expand Up @@ -1473,14 +1764,14 @@ def create_app():
sugar_app = typer.Typer(
name='sugar',
help=(
'sugar (or sugar) is a tool that help you to organize'
'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/sugar'
),
short_help="sugar (or sugar) is a tool that help you \
short_help="Sugar is a tool that help you \
to organize containers' stack",
)

Expand Down
Loading

0 comments on commit 4a28eee

Please sign in to comment.