Merge pull request #128 from cerc-io/dboreham/stack-for-setup-repositories

Implement stack config file for setup-repositories
This commit is contained in:
David Boreham 2023-01-17 22:40:12 -07:00 committed by GitHub
commit 4e1366df60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 8 deletions

View File

@ -1,5 +1,5 @@
version: "1.0" version: "1.0"
name: laconicd-fixturenet name: fixturenet-laconicd
repos: repos:
- cerc-io/laconicd - cerc-io/laconicd
- cerc-io/laconic-sdk - cerc-io/laconic-sdk

View File

@ -1,2 +1,2 @@
# This file should be re-generated running: scripts/update-version-file.sh script # This file should be re-generated running: scripts/update-version-file.sh script
v1.0.9-alpha-32b4c00 v1.0.9-alpha-04a3049

View File

@ -23,6 +23,8 @@ import git
from tqdm import tqdm from tqdm import tqdm
import click import click
import importlib.resources import importlib.resources
from pathlib import Path
import yaml
from .util import include_exclude_check from .util import include_exclude_check
@ -64,9 +66,11 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file):
quiet = ctx.obj.quiet quiet = ctx.obj.quiet
verbose = ctx.obj.verbose verbose = ctx.obj.verbose
dry_run = ctx.obj.dry_run dry_run = ctx.obj.dry_run
stack = ctx.obj.stack
branches = [] branches = []
# TODO: branches file needs to be re-worked in the context of stacks
if branches_file: if branches_file:
if verbose: if verbose:
print(f"loading branches from: {branches_file}") print(f"loading branches from: {branches_file}")
@ -96,11 +100,25 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file):
with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file: with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file:
all_repos = repository_list_file.read().splitlines() all_repos = repository_list_file.read().splitlines()
repos_in_scope = []
if stack:
# In order to be compatible with Python 3.8 we need to use this hack to get the path:
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
stack_file_path = Path(__file__).absolute().parent.joinpath("data", "stacks", stack, "stack.yml")
with stack_file_path:
stack_config = yaml.safe_load(open(stack_file_path, "r"))
# TODO: syntax check the input here
repos_in_scope = stack_config['repos']
else:
repos_in_scope = all_repos
if verbose: if verbose:
print(f"Repos: {all_repos}") print(f"Repos: {repos_in_scope}")
if stack:
print(f"Stack: {stack}")
repos = [] repos = []
for repo in all_repos: for repo in repos_in_scope:
if include_exclude_check(repo, include, exclude): if include_exclude_check(repo, include, exclude):
repos.append(repo) repos.append(repo)
else: else:

10
cli.py
View File

@ -24,8 +24,11 @@ from app import version
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
# TODO: this seems kind of weird and heavy on boilerplate -- check it is
# the best Python can do for us.
class Options(object): class Options(object):
def __init__(self, quiet, verbose, dry_run, local_stack, debug): def __init__(self, stack, quiet, verbose, dry_run, local_stack, debug):
self.stack = stack
self.quiet = quiet self.quiet = quiet
self.verbose = verbose self.verbose = verbose
self.dry_run = dry_run self.dry_run = dry_run
@ -34,6 +37,7 @@ class Options(object):
@click.group(context_settings=CONTEXT_SETTINGS) @click.group(context_settings=CONTEXT_SETTINGS)
@click.option('--stack', help="specify a stack to build/deploy")
@click.option('--quiet', is_flag=True, default=False) @click.option('--quiet', is_flag=True, default=False)
@click.option('--verbose', is_flag=True, default=False) @click.option('--verbose', is_flag=True, default=False)
@click.option('--dry-run', is_flag=True, default=False) @click.option('--dry-run', is_flag=True, default=False)
@ -41,9 +45,9 @@ class Options(object):
@click.option('--debug', is_flag=True, default=False) @click.option('--debug', is_flag=True, default=False)
# See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone # See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone
@click.pass_context @click.pass_context
def cli(ctx, quiet, verbose, dry_run, local_stack, debug): def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug):
"""Laconic Stack Orchestrator""" """Laconic Stack Orchestrator"""
ctx.obj = Options(quiet, verbose, dry_run, local_stack, debug) ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug)
cli.add_command(setup_repositories.command, "setup-repositories") cli.add_command(setup_repositories.command, "setup-repositories")

View File

@ -3,3 +3,4 @@ GitPython>=3.1.27
tqdm>=4.64.0 tqdm>=4.64.0
python-on-whales>=0.52.0 python-on-whales>=0.52.0
click>=8.1.3 click>=8.1.3
pyyaml>=6.0

View File

@ -6,7 +6,7 @@ with open("requirements.txt", "r", encoding="utf-8") as fh:
requirements = fh.read() requirements = fh.read()
setup( setup(
name='laconic-stack-orchestrator', name='laconic-stack-orchestrator',
version='0.0.5', version='1.0.9',
author='Cerc', author='Cerc',
author_email='info@cerc.io', author_email='info@cerc.io',
license='GNU Affero General Public License', license='GNU Affero General Public License',