Giter Site home page Giter Site logo

sugar's Introduction

sugar

Simplify the usage of containers.

You may be thinking, why do I need a new library that wrap-up docker-compose or podman-compose if they are already really simple to use?

Yes, they are simple to use, but if you have some other parameters to the compose command line, it could be very tedious to write them 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 your stack of containers, gathering some useful scripts and keeping this information centralized in a configuration file. So the command line would be very simple.

How to Install

$ pip install containers-sugar

Features

The commands from docker-compose available are:

  • build
  • config
  • create
  • down
  • events
  • exec
  • images
  • kill
  • logs
  • pause
  • port
  • ps
  • pull
  • push
  • restart
  • rm
  • run
  • start
  • stop
  • top
  • unpause
  • up
  • version

These commands are available in the main profile/plugin, so you don't need to specify any extra parameter to access them.

For extra commands, we are gathering them into a profile/plugin called ext, so you can access them using something like: sugar ext restart.

The current available ext commands are:

  • start -> alias for up
  • restart -> runs stop and up

How to use it

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

version: 1.0
compose-app: docker compose
default:
  group: {{ env.ENV }}
groups:
  group1:
    project-name: project1
    compose-path:
      - containers/tests/group1/compose.yaml
    env-file: .env
    services:
      default: service1,service3
      available:
        - name: service1
        - name: service2
        - name: service3
  group2:
    project-name: null
    compose-path: containers/tests/group2/compose.yaml
    env-file: .env
    services:
      available:
        - name: service1
        - name: service3

Some examples of how to use it:

  • build the defaults services (service1,service3) for group1: sugar build --group group1

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

  • build all services (ignore default) for group1: sugar build --group group1 --all

  • start the default services for group1: sugar ext start --group group1

  • restart all services (ignore defaults) for group1: sugar ext restart --group group1 --all

  • restart service1 and service2 for group1: sugar ext restart --group group1 --services service1,service2

NOTE: If you use: default: group: {{ env.ENV }}, you don't need to give --group <GROUP_NAME>, except if you want a different group than the default one.

sugar's People

Contributors

xmnlab avatar semantic-release-bot avatar joel5vega avatar fccoelho avatar jhonnye0 avatar esloch avatar

Stargazers

Tammo Ippen avatar  avatar Roman Hossain Shaon avatar Luã B. Vacaro avatar  avatar Luis Gago Casas avatar

Watchers

 avatar Luis Gago Casas avatar  avatar

sugar's Issues

Create special commands support

in order to keep consistency with docker-compose commands and also create new "sugar" commands, it would be good to have a way to specify if it is a regular command or a special one.

additionally in the future we could allow some commands defined by the user and it would need a different way to specify that as well.

My suggestion is to use something like this:

  • kxgr ext image --service abcd --info

the extension commands should be added in a separated class

Error when not specifying a project-name

  • containers-sugar version:

Version: 1.2.0
docker-compose version 1.29.2, build unknown

  • Python version:

Python 3.9.16

  • Operating System:
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.10
Release:        22.10
Codename:       kinetic
5.19.0-29-generic

Description

The optional argument passed inside the config file as NULL doesn't work.

What I Did

containers-sugar/.containers-sugar.yaml

  - name: group2
    project-name: null  # optional
    compose-path: containers/tests/group2/compose.yaml
    env-file: .env
11:03 $ containers-sugar build --config-file ./.containers-sugar.yaml --group group2
>>> /workspace/virtualenv/mambaforge/envs/alertadengue/bin/docker-compose --env-file .env --file containers/tests/group2/compose.yaml --project-name None build 
--------------------------------------------------------------------------------
No such command: 

Commands:
  build              Build or rebuild services
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove resources
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show version information and quit

AttributeError: type object 'KxgrLogs' has no attribute 'KXGR_INVALID_PARAMETER'

Traceback (most recent call last):
  File "/home/xmn/mambaforge/envs/literev/bin/sugar", line 8, in <module>
    sys.exit(app())
  File "/home/xmn/mambaforge/envs/literev/lib/python3.9/site-packages/containers_sugar/cli.py", line 165, in app
    sugar = Sugar(args_cast, options_args, cmd_args)
  File "/home/xmn/mambaforge/envs/literev/lib/python3.9/site-packages/containers_sugar/sugar.py", line 531, in __init__
    super().__init__(args, options_args, cmd_args)
  File "/home/xmn/mambaforge/envs/literev/lib/python3.9/site-packages/containers_sugar/sugar.py", line 72, in __init__
    self._verify_args()
  File "/home/xmn/mambaforge/envs/literev/lib/python3.9/site-packages/containers_sugar/sugar.py", line 549, in _verify_args
    KxgrLogs.KXGR_INVALID_PARAMETER,
AttributeError: type object 'KxgrLogs' has no attribute 'KXGR_INVALID_PARAMETER'

The flag --all is not working properly

currently, --all doesn't add any parameters for services, that means that it will execute the action for all the services defined in the compose file. that is not what we want, it should uses all the services defined in the attribute list inside the sugar config file.

EPIC: New features

cc @jloehel

  • Some really cool feature would be cli add to
    Where you can specify a template for service X and just add it to a project
    Would speed up the creation a lot. Service X could be redis/postgresql/mysql/mariadb ...
    Those services which you need additionally
  • The get-ip feature is really nice. doing an inspect and then extract the ip from the json via jq is painful. Always need to look that up
    Would be nice to have this also dns entries of the docker dns resolver
    *I think I would not really use the logs feature so much because to get logs is already straight forward in docker/docker-compose. But some correlation feature for logs would be nice. In example you have a service which is scaled on 3 different nodes. Of course you can get the individual logs and the service logs but it's always a pain. It would be nice to easily switch between the logs or have it also side by side. or in example nginx/apache -> app (flask/django). Connect these to logs based on the request-id.
  • What is also some kind of pain for me, is change secrets/configs without shutting down the stacks. It needs a lot of manual steps. Would be also nice to see some naming convention for secrets/configs there.
  • identifying all pre defined volumes of an image would be also a nice feature. Sometimes I have a lot of anonymous volumes. ... and I need manually inspect them to find out what it was

Any commands result in the same error message (help,version,build...)

  • containers-sugar version:
06:28 $ pip show containers-sugar
Name: containers-sugar
Version: 1.0.1
Summary: Simplify the usage of containers
Home-page: 
Author: Ivan Ogasawara
Author-email: [email protected]
License: BSD 3 Clause
Location: /workspace/virtualenv/mambaforge/envs/alertadengue/lib/python3.9/site-packages
Requires: docker-compose, podman-compose, pyyaml, sh, types-pyyaml
Required-by: 
  • Python version:
06:30 $ python --version
Python 3.9.15
  • Operating System:
06:30 $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.10
Release:        22.10
Codename:       kinetic
---
06:32 $ uname -r
5.19.0-29-generic

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

06:26 $ containers-sugar build --group prod
Traceback (most recent call last):
  File "/workspace/virtualenv/mambaforge/envs/alertadengue/bin/containers-sugar", line 3, in <module>
    from containers_sugar.__main__ import app
  File "/workspace/repos/infodengue/AlertaDengue/containers-sugar/containers_sugar/__init__.py", line 9, in <module>
    from containers_sugar.sugar import Sugar  # noqa: F401
  File "/workspace/repos/infodengue/AlertaDengue/containers-sugar/containers_sugar/sugar.py", line 18, in <module>
    class Sugar:
  File "/workspace/repos/infodengue/AlertaDengue/containers-sugar/containers_sugar/sugar.py", line 32, in Sugar
    args: object | None = None
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

SPEC: Add a new key in the root of the config file for services

Add a new key in the root of the config file for services. Example:

version: 1.0.0
compose-app: docker-compose
env-file: .env
services:
  default: service1,service3
  list:
    - name: service1
      health-check: true
    - name: service2
      health-check: false
    - name: service3
      health-check: true

when the services item is given, groups should not be given, otherwise it should raise an error.

Create dependencies for groups and services

Example:

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-1,service1-3
      list:
        - name: service1-1
          depends_on:
            - dep1
        - name: service1-2
        - name: service1-3
    dependencies:
      - name: dep1
        source:
          # local:
          #   wdir: /tmp
          #   path: containers/.containers-sugar.yaml
          # or
          # repo:
          #   url: https://github.com/alertadengue/copernicus
          #   path: .containers-sugar.yaml
          #   branch: ...
          #   commit: ...
        env-file: .env
        services:
          - group1.service-dep1.1
          - group2.service-dep1.2

  - name: group2
    project-name: null  # optional
    compose-path: containers/tests/group2/compose.yaml
    env-file: .env
    services:
      default: null
      list:
        - name: service2-1
        - name: service2-2

  - name: group-mix
    project-name: null  # optional
    compose-path:
      - containers/tests/group1/compose.yaml
      - containers/tests/group2/compose.yaml
    env-file: .env
    services:
      default: null
      list:
        - name: service1-1
        - name: service1-2
        - name: service2-1
        - name: service2-2

Create a TUI for sugar simular to k9s

Development Plan:

  1. Initial Setup: Setting up the project structure and integrating the Textual library.
  2. Interface Design: Designing the layout and navigation of the TUI, including menus and panels.
  3. Feature Implementation: Developing the core functionalities - group selection, service management, log viewing, and displaying service details.
  4. Testing and Refinement: Rigorous testing of the TUI for usability, performance, and compatibility with existing Sugar functionalities.
  5. Documentation and Examples: Creating comprehensive documentation and usage examples to assist users in leveraging the new TUI.

Add support for Deployment

It would be great to add a new configuration into the configuration file for deployment.
This option would be used to define configuration such as servers, credentials, paths, environment variables, etc
in order to run the deployment we could use ansible as a backend. Maybe not the CLI but instead the ansible as a library, so probably we will have much more flexibility.

get the group information from an environment variable

We need a way to get the group information from an environment variable, so user don't need to specify the --group in the CLI.

if the group information is not specified, the --group in the CLI would be mandatory.

Idea:

The default environment variable for that would be: SUGAR_GROUP_NAME
but the user can specify a custom environment variable name, for example:

version: 1.0.0
config:
  env:
    SUGAR_GROUP_NAME: ENV

it looks bit extensive/verbose in this way .. but it would be easy to extend for other custom configuration in the future

Add an alias to the containers-sugar: kxgr

althought containers-sugar is very explicit about what is its purposes, it is a very long command.
it would be nice to have a shorter name for the project.
so my plan for now it would be add an alias to the project, and if it works well, we can rename the project officially.

my proposal is to add the alias kxgar where:

  • "k" would be used to represent "containers"
  • "x" would represent "su" (sounds like "shu")
  • "gr" would reprenset "gar" sound

Extend another service groups

  • containers-sugar version:
  • Python version:
  • Operating System:

Description

Popose:

Use base images created in advance.

Change service groups items from list to dict

Currently, all the groups are inside a list, it is necessary to change from list to dictionary.

Current state:

version: 1.0
compose-app: docker compose
env-file: ./src/.env
defaults:
  group: dev
  project-name: rinchen

groups:
  - name: dev
    compose-path: containers/docker-compose.yaml
    services:
      default: web
      available:
        - name: web

Desired:

version: 1.0
compose-app: docker compose
env-file: ./src/.env
defaults:
  group: dev
  project-name: rinchen

groups:
  dev:
    compose-path: containers/docker-compose.yaml
    services:
      default: web
      available:
        - name: web

PS: this is similar to what we already have in makim (https://github.com/osl-incubator/makim/blob/main/makim/makim.py#L152)
PS2: we don't need to keep support for a default group called default.

containers-sugar doesn't recognize services name in compose file

  • containers-sugar version:

Version: 1.2.0
docker-compose version 1.29.2, build unknown

  • Python version:

Python 3.9.16

  • Operating System:
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.10
Release:        22.10
Codename:       kinetic
5.19.0-29-generic

Description

containers-sugar does not recognize service names in compose file

What I Did

11:13 $ containers-sugar build --group group1
>>> /workspace/virtualenv/mambaforge/envs/alertadengue/bin/docker-compose --env-file .env --file containers/tests/group1/compose.yaml --project-name project1 build service1 service3 
--------------------------------------------------------------------------------
ERROR: No such service: 

Error when trying to install the package in -e

  • containers-sugar version:

Version: 1.2.0
docker-compose version 1.29.2, build unknown

  • Python version:

Python 3.9.16

  • Operating System:
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.10
Release:        22.10
Codename:       kinetic
5.19.0-29-generic

Description

Error when creating the environment and installing the package in editable mode

What I Did

$ pip install -e containers-sugar
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
poetry 1.3.2 requires jsonschema<5.0.0,>=4.10.0, but you have jsonschema 3.2.0 which is incompatible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.