Browse Source

r/baker/byrd/g

Bertrand Chenal 7 years ago
parent
commit
ec52d6e51e
6 changed files with 57 additions and 54 deletions
  1. 27 27
      README.md
  2. 16 16
      byrd.py
  3. 4 1
      pkg/os.yaml
  4. 8 8
      setup.py
  5. 1 1
      tests/base_test.py
  6. 1 1
      tests/conftest.py

+ 27 - 27
README.md

@@ -1,20 +1,20 @@
-# Baker
+# Byrd
 
 
-Baker is a simple deployment tool based on paramiko. The config file
+Byrd is a simple deployment tool based on paramiko. The config file
 format is inspired by [Sup](https://github.com/pressly/sup) (but not
 format is inspired by [Sup](https://github.com/pressly/sup) (but not
-identical). In contrast to sup, Baker is meant to be invoked from any
+identical). In contrast to sup, Byrd is meant to be invoked from any
 OS (aka Windows support). This project is in alpha stage, please
 OS (aka Windows support). This project is in alpha stage, please
 handle carefully.
 handle carefully.
 
 
-The name Baker is a reference to
-[Chet Baker](https://en.wikipedia.org/wiki/Chet_Baker).
+The name Byrd is a reference to
+[Donald Byrd](https://en.wikipedia.org/wiki/Donald_Byrd.
 
 
 
 
 # Quickstart
 # Quickstart
 
 
 ## Basic Example
 ## Basic Example
 
 
-By default baker will use `bk.yaml` as config file:
+By default byrd will use `bd.yaml` as config file:
 
 
 ```
 ```
 networks:
 networks:
@@ -43,14 +43,14 @@ Based on the above file, one can run the following operations (imagine
 that the INFO lines are colored):
 that the INFO lines are colored):
 
 
 ```
 ```
-$ bk time
-INFO:2018-08-01 23:14:05: Load config bk.yaml
-$ bk  time -v
-INFO:2018-08-01 23:14:21: Load config bk.yaml
+$ bd time
+INFO:2018-08-01 23:14:05: Load config bd.yaml
+$ bd  time -v
+INFO:2018-08-01 23:14:21: Load config bd.yaml
 INFO:2018-08-01 23:14:21: Print current time (on local machine)
 INFO:2018-08-01 23:14:21: Print current time (on local machine)
 2018-08-01T23:14:21+02:00
 2018-08-01T23:14:21+02:00
-$ bk health web -v
-INFO:2018-08-01 23:14:25: Load config bk.yaml
+$ bd health web -v
+INFO:2018-08-01 23:14:25: Load config bd.yaml
 INFO:2018-08-01 23:14:25: web1.example.com: Get basic health info
 INFO:2018-08-01 23:14:25: web1.example.com: Get basic health info
  23:14:26 up 7 days,  6:28,  4 users,  load average: 0,30, 0,26, 0,22
  23:14:26 up 7 days,  6:28,  4 users,  load average: 0,30, 0,26, 0,22
 INFO:2018-08-01 23:14:26: web2.example.com: Get basic health info
 INFO:2018-08-01 23:14:26: web2.example.com: Get basic health info
@@ -60,8 +60,8 @@ INFO:2018-08-01 23:14:26: web2.example.com: Get basic health info
 
 
 You can also pass `--dry-run` (or `-d`) to print what would have been done:
 You can also pass `--dry-run` (or `-d`) to print what would have been done:
 ```
 ```
-$ bk web health --dry-run
-INFO:2018-08-13 14:36:05: Load config bk.yaml
+$ bd web health --dry-run
+INFO:2018-08-13 14:36:05: Load config bd.yaml
 INFO:2018-08-13 14:36:05: web1.example.com: Get basic health info
 INFO:2018-08-13 14:36:05: web1.example.com: Get basic health info
 INFO:2018-08-13 14:36:05: [DRY-RUN] uptime
 INFO:2018-08-13 14:36:05: [DRY-RUN] uptime
 INFO:2018-08-13 14:36:05: web2.example.com: Get basic health info
 INFO:2018-08-13 14:36:05: web2.example.com: Get basic health info
@@ -71,7 +71,7 @@ INFO:2018-08-13 14:36:05: [DRY-RUN] uptime
 
 
 ## Environment
 ## Environment
 
 
-Each command is auto-formatted based on current environment. When Baker
+Each command is auto-formatted based on current environment. When Byrd
 is invoked, the basic environment is initialized with the one from
 is invoked, the basic environment is initialized with the one from
 parent process (literally `os.environ`). It is then augmented by the
 parent process (literally `os.environ`). It is then augmented by the
 top level `env` directive of the config file and then command-line
 top level `env` directive of the config file and then command-line
@@ -92,7 +92,7 @@ sub-task that expect a variable to be set up)
 
 
 ## Multi-tasks
 ## Multi-tasks
 
 
-The following example shows how Baker handles environment variables,
+The following example shows how Byrd handles environment variables,
 and how to assemble tasks.
 and how to assemble tasks.
 
 
 ```
 ```
@@ -113,28 +113,28 @@ tasks:
     desc: Run both tasks
     desc: Run both tasks
     multi:
     multi:
       - task: echo
       - task: echo
-        export: my_var  # tells baker to use task ouput to set my_var
+        export: my_var  # tells byrd to use task ouput to set my_var
       - task: echo-var
       - task: echo-var
 ```
 ```
 
 
 We can then do the following:
 We can then do the following:
 
 
 ```
 ```
-$ bk both -v
-INFO:2018-08-01 23:00:37: Load config bk.yaml
+$ bd both -v
+INFO:2018-08-01 23:00:37: Load config bd.yaml
 INFO:2018-08-01 23:00:37: Simple echo 
 INFO:2018-08-01 23:00:37: Simple echo 
 ECHO!
 ECHO!
 INFO:2018-08-01 23:00:37: Echo an env variable
 INFO:2018-08-01 23:00:37: Echo an env variable
 ECHO!
 ECHO!
-$ bk both -e what="WHAT?" -v
-INFO:2018-08-01 23:01:15: Load config bk.yaml
+$ bd both -e what="WHAT?" -v
+INFO:2018-08-01 23:01:15: Load config bd.yaml
 INFO:2018-08-01 23:01:15: Simple echo
 INFO:2018-08-01 23:01:15: Simple echo
 WHAT?
 WHAT?
 INFO:2018-08-01 23:01:15: Echo an env variable
 INFO:2018-08-01 23:01:15: Echo an env variable
 WHAT?
 WHAT?
 ```
 ```
 
 
-As you can see the `export` directive tells Baker to save the result
+As you can see the `export` directive tells Byrd to save the result
 of a command under a given environment variable.
 of a command under a given environment variable.
 
 
 
 
@@ -176,7 +176,7 @@ and `stderr`.
 
 
 ## SSH Authentication
 ## SSH Authentication
 
 
-Currently, Baker only supports private key authentication. You can add
+Currently, Byrd only supports private key authentication. You can add
 an `auth` section that tells where to find your private key:
 an `auth` section that tells where to find your private key:
 
 
 ```
 ```
@@ -184,7 +184,7 @@ auth:
   ssh_private_key: path/to/deploy_key_rsa
   ssh_private_key: path/to/deploy_key_rsa
 ```
 ```
 
 
-On the following invocation, Baker will ask your passphrase for the
+On the following invocation, Byrd will ask your passphrase for the
 key. This passphrase will be saved in your OS keyring (thanks to
 key. This passphrase will be saved in your OS keyring (thanks to
 [the keyring module](https://github.com/jaraco/keyring).)
 [the keyring module](https://github.com/jaraco/keyring).)
 
 
@@ -192,7 +192,7 @@ key. This passphrase will be saved in your OS keyring (thanks to
 ## Load other config files
 ## Load other config files
 
 
 The top-level directive `load` allows to import other config files and
 The top-level directive `load` allows to import other config files and
-merge them with the current one, so with `bk.yaml` containing:
+merge them with the current one, so with `bd.yaml` containing:
 
 
 ```
 ```
 load:
 load:
@@ -216,8 +216,8 @@ networks:
 We can now run:
 We can now run:
 
 
 ```
 ```
-$ bk net/web echo-host --dry-run' -v
-INFO:2018-08-14 11:27:33: Load config bk.yaml
+$ bd net/web echo-host --dry-run' -v
+INFO:2018-08-14 11:27:33: Load config bd.yaml
 INFO:2018-08-14 11:27:33: Load config network.yaml
 INFO:2018-08-14 11:27:33: Load config network.yaml
 INFO:2018-08-14 11:27:33: echo-host
 INFO:2018-08-14 11:27:33: echo-host
 INFO:2018-08-14 11:27:33: [DRY-RUN] echo web1.example.com
 INFO:2018-08-14 11:27:33: [DRY-RUN] echo web1.example.com

+ 16 - 16
baker.py → byrd.py

@@ -25,7 +25,7 @@ __version__ = '0.0'
 
 
 
 
 log_fmt = '%(levelname)s:%(asctime).19s: %(message)s'
 log_fmt = '%(levelname)s:%(asctime).19s: %(message)s'
-logger = logging.getLogger('baker')
+logger = logging.getLogger('byrd')
 logger.setLevel(logging.INFO)
 logger.setLevel(logging.INFO)
 log_handler = logging.StreamHandler()
 log_handler = logging.StreamHandler()
 log_handler.setLevel(logging.INFO)
 log_handler.setLevel(logging.INFO)
@@ -36,13 +36,13 @@ basedir, _ = os.path.split(__file__)
 PKG_DIR = os.path.join(basedir, 'pkg')
 PKG_DIR = os.path.join(basedir, 'pkg')
 TAB = '\n    '
 TAB = '\n    '
 
 
-class BakerException(Exception):
+class ByrdException(Exception):
     pass
     pass
 
 
-class FmtException(BakerException):
+class FmtException(ByrdException):
     pass
     pass
 
 
-class ExecutionException(BakerException):
+class ExecutionException(ByrdException):
     pass
     pass
 
 
 class RemoteException(ExecutionException):
 class RemoteException(ExecutionException):
@@ -129,7 +129,7 @@ def spellcheck(objdict, word):
     matches = spell(candidates, word)
     matches = spell(candidates, word)
     if matches:
     if matches:
         msg += ', try: %s' % ' or '.join(matches)
         msg += ', try: %s' % ' or '.join(matches)
-    raise BakerException(msg)
+    raise ByrdException(msg)
 
 
 
 
 class ObjectDict(dict):
 class ObjectDict(dict):
@@ -164,7 +164,7 @@ class Node:
     @staticmethod
     @staticmethod
     def fail(path, kind):
     def fail(path, kind):
         msg = 'Error while parsing config: expecting "%s" while parsing "%s"'
         msg = 'Error while parsing config: expecting "%s" while parsing "%s"'
-        raise BakerException(msg % (kind, '->'.join(path)))
+        raise ByrdException(msg % (kind, '->'.join(path)))
 
 
     @classmethod
     @classmethod
     def parse(cls, cfg, path=tuple()):
     def parse(cls, cfg, path=tuple()):
@@ -197,7 +197,7 @@ class Node:
                         matches = spell(candidates, key)
                         matches = spell(candidates, key)
                         if matches:
                         if matches:
                             msg += ', try: %s' % ' or '.join(matches)
                             msg += ', try: %s' % ' or '.join(matches)
-                        raise BakerException(msg)
+                        raise ByrdException(msg)
 
 
                 for name, child_class in children.items():
                 for name, child_class in children.items():
                     if name not in cfg:
                     if name not in cfg:
@@ -387,7 +387,7 @@ def connect(host, auth):
         private_key_file = auth.ssh_private_key
         private_key_file = auth.ssh_private_key
         if not os.path.exists(auth.ssh_private_key):
         if not os.path.exists(auth.ssh_private_key):
             msg = 'Private key file "%s" not found' % auth.ssh_private_key
             msg = 'Private key file "%s" not found' % auth.ssh_private_key
-            raise BakerException(msg)
+            raise ByrdException(msg)
         password = get_passphrase(auth.ssh_private_key)
         password = get_passphrase(auth.ssh_private_key)
     else:
     else:
         password = get_password(host)
         password = get_password(host)
@@ -556,7 +556,7 @@ def run_remote(task, host, env, cli):
         remote_path = env.fmt(task.to)
         remote_path = env.fmt(task.to)
         logger.info(f'[send] {local_path} -> {host}:{remote_path}')
         logger.info(f'[send] {local_path} -> {host}:{remote_path}')
         if not os.path.exists(local_path):
         if not os.path.exists(local_path):
-            BakerException('Path "%s" not found'  % local_path)
+            ByrdException('Path "%s" not found'  % local_path)
         if cli.dry_run:
         if cli.dry_run:
             logger.info('[dry-run]')
             logger.info('[dry-run]')
             return
             return
@@ -576,9 +576,9 @@ def run_remote(task, host, env, cli):
                             sftp.put(os.path.abspath(rel_f), rem_file)
                             sftp.put(os.path.abspath(rel_f), rem_file)
                 else:
                 else:
                     msg = 'Unexpected path "%s" (not a file, not a directory)'
                     msg = 'Unexpected path "%s" (not a file, not a directory)'
-                    BakerException(msg % local_path)
+                    ByrdException(msg % local_path)
     else:
     else:
-        raise BakerException('Unable to run task "%s"' % task.name)
+        raise ByrdException('Unable to run task "%s"' % task.name)
 
 
     if res and res.stdout:
     if res and res.stdout:
         logger.debug(TAB + TAB.join(res.stdout.splitlines()))
         logger.debug(TAB + TAB.join(res.stdout.splitlines()))
@@ -623,7 +623,7 @@ def run_task(task, host, cli, parent_env=None):
         if ok:
         if ok:
             logger.info('Assert ok')
             logger.info('Assert ok')
         else:
         else:
-            raise BakerException('Assert "%s" failed!' % assert_)
+            raise ByrdException('Assert "%s" failed!' % assert_)
     return res
     return res
 
 
 
 
@@ -693,7 +693,7 @@ def load_cfg(path, prefix=None):
         cfg = yaml_load(open(path))
         cfg = yaml_load(open(path))
         cfg = ConfigRoot.parse(cfg)
         cfg = ConfigRoot.parse(cfg)
     else:
     else:
-        raise BakerException('Config file "%s" not found' % path)
+        raise ByrdException('Config file "%s" not found' % path)
 
 
     # Define useful defaults
     # Define useful defaults
     cfg.networks = cfg.networks or ObjectDict()
     cfg.networks = cfg.networks or ObjectDict()
@@ -743,7 +743,7 @@ def load_cli(args=None):
     parser = argparse.ArgumentParser()
     parser = argparse.ArgumentParser()
     parser.add_argument('names',  nargs='*',
     parser.add_argument('names',  nargs='*',
                         help='Hosts and commands to run them on')
                         help='Hosts and commands to run them on')
-    parser.add_argument('-c', '--config', default='bk.yaml',
+    parser.add_argument('-c', '--config', default='bd.yaml',
                         help='Config file')
                         help='Config file')
     parser.add_argument('-R', '--run', nargs='*', default=[],
     parser.add_argument('-R', '--run', nargs='*', default=[],
                         help='Run remote task')
                         help='Run remote task')
@@ -799,7 +799,7 @@ def get_hosts_and_tasks(cli, cfg):
             matches = spell(cfg.networks, name) | spell(cfg.tasks, name)
             matches = spell(cfg.networks, name) | spell(cfg.tasks, name)
             if matches:
             if matches:
                 msg += ', try: %s' % ' or '.join(matches)
                 msg += ', try: %s' % ' or '.join(matches)
-            raise BakerException (msg)
+            raise ByrdException (msg)
 
 
     # Collect custom tasks from cli
     # Collect custom tasks from cli
     customs = []
     customs = []
@@ -872,7 +872,7 @@ def main():
         )
         )
         for task in cli.tasks:
         for task in cli.tasks:
             run_batch(task, cli.hosts, cli, base_env)
             run_batch(task, cli.hosts, cli, base_env)
-    except BakerException as e:
+    except ByrdException as e:
         if cli and cli.verbose > 2:
         if cli and cli.verbose > 2:
             raise
             raise
         abort(str(e))
         abort(str(e))

+ 4 - 1
pkg/os.yaml

@@ -77,8 +77,11 @@ tasks:
       grep {guard} {file} &> /dev/null
       grep {guard} {file} &> /dev/null
       || echo {line} >> {file}
       || echo {line} >> {file}
   add-user:
   add-user:
-    desc: Add a new user
+    desc: Create a new user
     run: id {user} || sudo adduser {user} --disabled-login --gecos ""
     run: id {user} || sudo adduser {user} --disabled-login --gecos ""
+  add-group:
+    desc: Add group to user
+    run: usermod -a -G {user} {group}
   wget:
   wget:
     desc: Download a file
     desc: Download a file
     run: test -f {file} || wget -O {file} {url}
     run: test -f {file} || wget -O {file} {url}

+ 8 - 8
setup.py

@@ -3,33 +3,33 @@ from setuptools import setup
 from glob import glob
 from glob import glob
 import os
 import os
 
 
-import baker
+import byrd
 
 
 long_description = '''
 long_description = '''
 
 
-Baker is yet another deployment tool. Baker is a mashup of Paramiko
+Byrd is yet another deployment tool. Byrd is a mashup of Paramiko
 (https://www.paramiko.org/) and the sup config file layout
 (https://www.paramiko.org/) and the sup config file layout
 (https://github.com/pressly/sup).
 (https://github.com/pressly/sup).
 
 
-The name Baker is a reference to Chet Baker.
+The name Byrd is a reference to Donald Byrd.
 '''
 '''
 
 
 description = ('Simple deployment tool based on Paramiko')
 description = ('Simple deployment tool based on Paramiko')
 basedir, _ = os.path.split(__file__)
 basedir, _ = os.path.split(__file__)
 pkg_yaml = glob(os.path.join(basedir, 'pkg', '*yaml'))
 pkg_yaml = glob(os.path.join(basedir, 'pkg', '*yaml'))
 
 
-setup(name='Baker',
-      version=baker.__version__,
+setup(name='Byrd',
+      version=byrd.__version__,
       description=description,
       description=description,
       long_description=long_description,
       long_description=long_description,
       author='Bertrand Chenal',
       author='Bertrand Chenal',
       author_email='bertrand@adimian.com',
       author_email='bertrand@adimian.com',
-      url='https://bitbucket.org/bertrandchenal/baker',
+      url='https://bitbucket.org/bertrandchenal/byrd',
       license='MIT',
       license='MIT',
-      py_modules=['baker'],
+      py_modules=['byrd'],
       entry_points={
       entry_points={
           'console_scripts': [
           'console_scripts': [
-              'bk = baker:main',
+              'bd = byrd:main',
           ],
           ],
       },
       },
       data_files=[('pkg', pkg_yaml)],
       data_files=[('pkg', pkg_yaml)],

+ 1 - 1
tests/base_test.py

@@ -3,7 +3,7 @@ from shlex import shlex
 
 
 import pytest
 import pytest
 
 
-from baker import run_batch, load_cli, Env
+from byrd import run_batch, load_cli, Env
 
 
 
 
 def test_all_conf(test_cfg, log_buff):
 def test_all_conf(test_cfg, log_buff):

+ 1 - 1
tests/conftest.py

@@ -4,7 +4,7 @@ import logging
 
 
 import pytest
 import pytest
 
 
-from baker import logger, log_handler, yaml_load, ObjectDict
+from byrd import logger, log_handler, yaml_load, ObjectDict
 
 
 # Disable default handler
 # Disable default handler
 logger.removeHandler(log_handler)
 logger.removeHandler(log_handler)