-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from akretion/UPD-v8_0_0
[UPD+REF] Update for version 8.0.0
- Loading branch information
Showing
9 changed files
with
49 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,7 @@ venv/ | |
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Backup files | ||
*~ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from plumbum import cli, local | ||
from plumbum.commands.modifiers import FG | ||
import logging | ||
|
@@ -15,24 +13,24 @@ | |
|
||
class Docky(cli.Application): | ||
PROGNAME = "docky" | ||
VERSION = '7.1.0' | ||
VERSION = "8.0.0" | ||
SUBCOMMAND_HELPMSG = None | ||
|
||
def _run(self, cmd, retcode=FG): | ||
"""Run a command in a new process and log it""" | ||
logger.debug(str(cmd).replace('/usr/local/bin/', '')) | ||
logger.debug(str(cmd).replace("/usr/local/bin/", "")) | ||
return cmd & retcode | ||
|
||
def _exec(self, cmd, args=[]): | ||
"""Run a command in the same process and log it | ||
this will replace the current process by the cmd""" | ||
logger.debug(cmd + ' '.join(args)) | ||
logger.debug(cmd + " ".join(args)) | ||
os.execvpe(cmd, [cmd] + args, local.env) | ||
|
||
@cli.switch("--verbose", help="Verbose mode", group="Meta-switches") | ||
def set_log_level(self): | ||
logger.setLevel(logging.DEBUG) | ||
logger.debug('Verbose mode activated') | ||
logger.debug("Verbose mode activated") | ||
|
||
|
||
class DockySub(cli.Application): | ||
|
@@ -46,7 +44,7 @@ def _run(self, *args, **kwargs): | |
|
||
def _init_project(self): | ||
self.project = Project() | ||
self.compose = local['docker-compose'] | ||
self.compose = local["docker-compose"] | ||
|
||
def main(self, *args, **kwargs): | ||
if self._project_specific: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
@@ -10,7 +9,7 @@ class DockyForward(DockySub): | |
_cmd = None | ||
|
||
def _main(self, *args): | ||
cmd = self._cmd.split(' ') | ||
cmd = self._cmd.split(" ") | ||
if args: | ||
cmd.append(*args) | ||
return self._run(self.compose[cmd]) | ||
|
@@ -30,7 +29,7 @@ class DockyUp(DockyForward): | |
def _main(self, *args): | ||
self.project.display_service_tooltip() | ||
self.project.create_volume() | ||
return super(DockyUp, self)._main(*args) | ||
return super()._main(*args) | ||
|
||
|
||
@Docky.subcommand("down") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
@@ -15,4 +14,4 @@ def _main(self, *args): | |
# docker compose do not kill the container odoo as is was run | ||
# manually, so we implement our own kill | ||
containers = self.project.get_containers() | ||
parallel_kill(containers, {'signal': 'SIGKILL'}) | ||
parallel_kill(containers, {"signal": "SIGKILL"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from plumbum import cli | ||
from .base import Docky, DockySub | ||
from ..common.api import raise_error | ||
|
@@ -24,9 +22,9 @@ def _get_cmd_line(self, optionnal_command_line): | |
user = self._use_specific_user(self.service) | ||
cmd = [] | ||
if user: | ||
cmd = ['gosu', user] | ||
cmd = ["gosu", user] | ||
if not optionnal_command_line: | ||
cmd.append('bash') | ||
cmd.append("bash") | ||
else: | ||
cmd += list(optionnal_command_line) | ||
return cmd | ||
|
@@ -56,11 +54,11 @@ def _main(self, *optionnal_command_line): | |
super()._main(*optionnal_command_line) | ||
self._check_running() | ||
# Remove useless dead container before running a new one | ||
self._run(self.compose['rm', '-f']) | ||
self._run(self.compose["rm", "-f"]) | ||
self.project.display_service_tooltip() | ||
self.project.create_volume() | ||
self._exec('docker-compose', [ | ||
'run', '--rm', '--service-ports', '--use-aliases', '-e', 'NOGOSU=True', | ||
self._exec("docker-compose", [ | ||
"run", "--rm", "--service-ports", "--use-aliases", "-e", "NOGOSU=True", | ||
self.service] + self.cmd) | ||
|
||
|
||
|
@@ -72,4 +70,4 @@ class DockyOpen(DockyExec): | |
|
||
def _main(self, *optionnal_command_line): | ||
super()._main(*optionnal_command_line) | ||
self._exec('dcpatched', ['exec', '-e', 'NOGOSU=True', self.service] + self.cmd) | ||
self._exec("dcpatched", ["exec", "-e", "NOGOSU=True", self.service] + self.cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
import logging | ||
import sys | ||
# Optionnal code for colorized log | ||
from rainbow_logging_handler import RainbowLoggingHandler | ||
|
||
logger = logging.getLogger('docky') | ||
logger = logging.getLogger("docky") | ||
formatter = logging.Formatter("%(message)s") | ||
logger.setLevel(logging.INFO) | ||
|
||
handler = RainbowLoggingHandler( | ||
sys.stderr, | ||
color_message_info=('green', None, True), | ||
color_message_info=("green", None, True), | ||
) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Akretion (http://www.akretion.com). | ||
# Copyright 2018-TODAY Akretion (http://www.akretion.com). | ||
# @author Sébastien BEAU <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
@@ -16,10 +15,10 @@ class Project(object): | |
|
||
def __init__(self): | ||
try: | ||
self.project = command.project_from_options('.', {}) | ||
self.project = command.project_from_options(".", {}) | ||
except ComposeFileNotFound: | ||
print("No docker-compose found, create one with :") | ||
print('$ docky init') | ||
print("$ docky init") | ||
exit(-1) | ||
|
||
self.name = self.project.name | ||
|
@@ -30,23 +29,23 @@ def _get_main_service(self, project): | |
"""main_service has docky.main.service defined in | ||
his label.""" | ||
for service in project.services: | ||
labels = service.options.get('labels', {}) | ||
labels = service.options.get("labels", {}) | ||
# service.labels() do not contain docky.main.service | ||
# see also compose.service.merge_labels | ||
if labels.get('docky.main.service', False): | ||
if labels.get("docky.main.service", False): | ||
return service.name | ||
|
||
def get_containers(self, service=None): | ||
kwargs = {'one_off': OneOffFilter.include} | ||
kwargs = {"one_off": OneOffFilter.include} | ||
if service: | ||
kwargs['service_names'] = [service] | ||
kwargs["service_names"] = [service] | ||
return self.project.containers(**kwargs) | ||
|
||
def display_service_tooltip(self): | ||
infos = self._get_services_info() | ||
for service in self.project.services: | ||
labels = service.options.get('labels', {}) | ||
if labels.get('docky.access.help'): | ||
labels = service.options.get("labels", {}) | ||
if labels.get("docky.access.help"): | ||
# TODO remove after some versions | ||
logger.warning( | ||
"'docky.access.help' is replaced by 'docky.help'. " | ||
|
@@ -55,8 +54,8 @@ def display_service_tooltip(self): | |
# some applications provide extra parameters to access resource | ||
infos[service.name] += labels.get("docky.url_suffix", "") | ||
logger.info(infos[service.name]) | ||
if labels.get('docky.help'): | ||
logger.info(labels.get('docky.help')) | ||
if labels.get("docky.help"): | ||
logger.info(labels.get("docky.help")) | ||
|
||
def _get_services_info(self): | ||
""" Search IP and Port for each services | ||
|
@@ -94,7 +93,7 @@ def create_volume(self): | |
docker-compose up do not attemps to create it | ||
so we have to do it ourselves""" | ||
for service in self.project.services: | ||
for volume in service.options.get('volumes', []): | ||
for volume in service.options.get("volumes", []): | ||
if volume.external: | ||
path = local.path(local.env.expand(volume.external)) | ||
if not path.exists(): | ||
|
@@ -105,6 +104,6 @@ def create_volume(self): | |
|
||
def get_user(self, service_name): | ||
service = self.project.get_service(name=service_name) | ||
labels = service.options.get('labels') | ||
labels = service.options.get("labels") | ||
if labels: | ||
return labels.get('docky.user', None) | ||
return labels.get("docky.user", None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
def read(*parts): | ||
path = os.path.join(os.path.dirname(__file__), *parts) | ||
with codecs.open(path, encoding='utf-8') as fobj: | ||
with codecs.open(path, encoding="utf-8") as fobj: | ||
return fobj.read() | ||
|
||
|
||
|
@@ -20,26 +20,26 @@ def find_version(*file_paths): | |
|
||
|
||
setup( | ||
name='docky', | ||
name="docky", | ||
version=find_version("docky", "cmd", "base.py"), | ||
author='Akretion', | ||
author_email='[email protected]', | ||
url='https://github.com/akretion/docky/', | ||
description='Make developpement with docker simply', | ||
author="Akretion", | ||
author_email="[email protected]", | ||
url="https://github.com/akretion/docky/", | ||
description="Make developpement with docker simply", | ||
license="AGPLv3+", | ||
long_description=open('README.rst').read(), | ||
long_description=open("README.rst").read(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"Operating System :: POSIX :: Linux", | ||
], | ||
install_requires=[ | ||
r.strip() for r in open('requirements.txt').read().splitlines()], | ||
r.strip() for r in open("requirements.txt").read().splitlines()], | ||
entry_points=""" | ||
[console_scripts] | ||
docky=docky.main:main | ||
dcpatched=docky.dcpatched:main | ||
""", | ||
include_package_data=True, | ||
packages=find_packages() + ['docky'], | ||
packages=find_packages() + ["docky"], | ||
zip_safe=False, | ||
) |