forked from cerc-io/stack-orchestrator
commit
7d943e48ae
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
from decouple import config
|
from decouple import config
|
||||||
import subprocess
|
import subprocess
|
||||||
import click
|
import click
|
||||||
@ -31,6 +30,7 @@ from .util import include_exclude_check
|
|||||||
# TODO: find a place for this
|
# TODO: find a place for this
|
||||||
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these containers")
|
@click.option('--include', help="only build these containers")
|
||||||
@click.option('--exclude', help="don\'t build these containers")
|
@click.option('--exclude', help="don\'t build these containers")
|
||||||
@ -53,7 +53,7 @@ def command(ctx, include, exclude):
|
|||||||
print(f'Dev Root is: {dev_root_path}')
|
print(f'Dev Root is: {dev_root_path}')
|
||||||
|
|
||||||
if not os.path.isdir(dev_root_path):
|
if not os.path.isdir(dev_root_path):
|
||||||
print(f'Dev root directory doesn\'t exist, creating')
|
print('Dev root directory doesn\'t exist, creating')
|
||||||
|
|
||||||
with open("container-image-list.txt") as container_list_file:
|
with open("container-image-list.txt") as container_list_file:
|
||||||
containers = container_list_file.read().splitlines()
|
containers = container_list_file.read().splitlines()
|
||||||
|
@ -16,15 +16,14 @@
|
|||||||
# Deploys the system components using docker-compose
|
# Deploys the system components using docker-compose
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import argparse
|
|
||||||
from decouple import config
|
|
||||||
from python_on_whales import DockerClient
|
from python_on_whales import DockerClient
|
||||||
import click
|
import click
|
||||||
from .util import include_exclude_check
|
from .util import include_exclude_check
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only start these components")
|
@click.option("--include", help="only start these components")
|
||||||
@click.option('--exclude', help="don\'t start these components")
|
@click.option("--exclude", help="don\'t start these components")
|
||||||
@click.argument('command') # help: command: up|down|ps
|
@click.argument('command') # help: command: up|down|ps
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def command(ctx, include, exclude, command):
|
def command(ctx, include, exclude, command):
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
from decouple import config
|
from decouple import config
|
||||||
import git
|
import git
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
|
||||||
class GitProgress(git.RemoteProgress):
|
class GitProgress(git.RemoteProgress):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -34,6 +34,7 @@ class GitProgress(git.RemoteProgress):
|
|||||||
self.pbar.n = cur_count
|
self.pbar.n = cur_count
|
||||||
self.pbar.refresh()
|
self.pbar.refresh()
|
||||||
|
|
||||||
|
|
||||||
def is_git_repo(path):
|
def is_git_repo(path):
|
||||||
try:
|
try:
|
||||||
_ = git.Repo(path).git_dir
|
_ = git.Repo(path).git_dir
|
||||||
@ -46,6 +47,7 @@ def is_git_repo(path):
|
|||||||
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--check-only', is_flag=True, default=False)
|
@click.option('--check-only', is_flag=True, default=False)
|
||||||
@click.option('--pull', is_flag=True, default=False)
|
@click.option('--pull', is_flag=True, default=False)
|
||||||
@ -81,7 +83,7 @@ def command(ctx, check_only, pull, branches_file):
|
|||||||
|
|
||||||
if not os.path.isdir(dev_root_path):
|
if not os.path.isdir(dev_root_path):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f'Dev root directory doesn\'t exist, creating')
|
print('Dev root directory doesn\'t exist, creating')
|
||||||
os.makedirs(dev_root_path)
|
os.makedirs(dev_root_path)
|
||||||
|
|
||||||
with open("repository-list.txt") as repository_list_file:
|
with open("repository-list.txt") as repository_list_file:
|
||||||
@ -96,7 +98,8 @@ def command(ctx, check_only, pull, branches_file):
|
|||||||
full_filesystem_repo_path = os.path.join(dev_root_path, repoName)
|
full_filesystem_repo_path = os.path.join(dev_root_path, repoName)
|
||||||
is_present = os.path.isdir(full_filesystem_repo_path)
|
is_present = os.path.isdir(full_filesystem_repo_path)
|
||||||
if not quiet:
|
if not quiet:
|
||||||
present_text = f'already exists active branch: {git.Repo(full_filesystem_repo_path).active_branch}' if is_present else 'Needs to be fetched'
|
present_text = f'already exists active branch: {git.Repo(full_filesystem_repo_path).active_branch}' if is_present \
|
||||||
|
else 'Needs to be fetched'
|
||||||
print(f'Checking: {full_filesystem_repo_path}: {present_text}')
|
print(f'Checking: {full_filesystem_repo_path}: {present_text}')
|
||||||
# Quick check that it's actually a repo
|
# Quick check that it's actually a repo
|
||||||
if is_present:
|
if is_present:
|
||||||
@ -118,7 +121,8 @@ def command(ctx, check_only, pull, branches_file):
|
|||||||
if verbose:
|
if verbose:
|
||||||
print(f'Running git clone for {full_github_repo_path} into {full_filesystem_repo_path}')
|
print(f'Running git clone for {full_github_repo_path} into {full_filesystem_repo_path}')
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
git.Repo.clone_from(full_github_repo_path, full_filesystem_repo_path,
|
git.Repo.clone_from(full_github_repo_path,
|
||||||
|
full_filesystem_repo_path,
|
||||||
progress=None if quiet else GitProgress())
|
progress=None if quiet else GitProgress())
|
||||||
else:
|
else:
|
||||||
print("(git clone skipped)")
|
print("(git clone skipped)")
|
||||||
@ -135,7 +139,5 @@ def command(ctx, check_only, pull, branches_file):
|
|||||||
git_repo = git.Repo(full_filesystem_repo_path)
|
git_repo = git.Repo(full_filesystem_repo_path)
|
||||||
git_repo.git.checkout(branch_to_checkout)
|
git_repo.git.checkout(branch_to_checkout)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for repo in repos:
|
for repo in repos:
|
||||||
process_repo(repo)
|
process_repo(repo)
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
def include_exclude_check(s, include, exclude):
|
def include_exclude_check(s, include, exclude):
|
||||||
if include == None and exclude == None:
|
if include is None and exclude is None:
|
||||||
return True
|
return True
|
||||||
if include != None:
|
if include is not None:
|
||||||
include_list = include.split(",")
|
include_list = include.split(",")
|
||||||
return s in include_list
|
return s in include_list
|
||||||
if exclude != None:
|
if exclude is not None:
|
||||||
exclude_list = exclude.split(",")
|
exclude_list = exclude.split(",")
|
||||||
return s not in exclude_list
|
return s not in exclude_list
|
||||||
|
3
cli.py
3
cli.py
@ -21,6 +21,7 @@ from app import deploy_system
|
|||||||
|
|
||||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||||
|
|
||||||
|
|
||||||
class Options(object):
|
class Options(object):
|
||||||
def __init__(self, quiet, verbose, dry_run, local_stack):
|
def __init__(self, quiet, verbose, dry_run, local_stack):
|
||||||
self.quiet = quiet
|
self.quiet = quiet
|
||||||
@ -33,13 +34,13 @@ class Options(object):
|
|||||||
@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)
|
||||||
@click.option('--local_stack', is_flag=True, default=False)
|
@click.option('--local_stack', 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):
|
def cli(ctx, quiet, verbose, dry_run, local_stack):
|
||||||
"""Laconic Stack Orchestrator"""
|
"""Laconic Stack Orchestrator"""
|
||||||
ctx.obj = Options(quiet, verbose, dry_run, local_stack)
|
ctx.obj = Options(quiet, verbose, dry_run, local_stack)
|
||||||
|
|
||||||
|
|
||||||
cli.add_command(setup_repositories.command, "setup-repositories")
|
cli.add_command(setup_repositories.command, "setup-repositories")
|
||||||
cli.add_command(build_containers.command, "build-containers")
|
cli.add_command(build_containers.command, "build-containers")
|
||||||
cli.add_command(deploy_system.command, "deploy-system")
|
cli.add_command(deploy_system.command, "deploy-system")
|
||||||
|
Loading…
Reference in New Issue
Block a user