Merge pull request #137 from cerc-io/dboreham/missing-stack-error
Error check stack config Former-commit-id: edbf674df7557137d4f64144d40c20ac7cbe347a
This commit is contained in:
commit
50103fcc9c
@ -1,4 +1,4 @@
|
|||||||
# Copyright © 2022 Cerc
|
# Copyright © 2022, 2023 Cerc
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -27,8 +27,7 @@ import subprocess
|
|||||||
import click
|
import click
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
from .util import include_exclude_check, get_parsed_stack_config
|
||||||
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)"
|
||||||
@ -70,12 +69,7 @@ def command(ctx, include, exclude):
|
|||||||
|
|
||||||
containers_in_scope = []
|
containers_in_scope = []
|
||||||
if stack:
|
if stack:
|
||||||
# In order to be compatible with Python 3.8 we need to use this hack to get the path:
|
stack_config = get_parsed_stack_config(stack)
|
||||||
# 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
|
|
||||||
containers_in_scope = stack_config['containers']
|
containers_in_scope = stack_config['containers']
|
||||||
else:
|
else:
|
||||||
containers_in_scope = all_containers
|
containers_in_scope = all_containers
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright © 2022 Cerc
|
# Copyright © 2022, 2023 Cerc
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -23,10 +23,8 @@ import sys
|
|||||||
from decouple import config
|
from decouple import config
|
||||||
import click
|
import click
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
from pathlib import Path
|
|
||||||
from python_on_whales import docker, DockerException
|
from python_on_whales import docker, DockerException
|
||||||
import yaml
|
from .util import include_exclude_check, get_parsed_stack_config
|
||||||
from .util import include_exclude_check
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--include', help="only build these packages")
|
@click.option('--include', help="only build these packages")
|
||||||
@ -62,11 +60,7 @@ def command(ctx, include, exclude):
|
|||||||
|
|
||||||
packages_in_scope = []
|
packages_in_scope = []
|
||||||
if stack:
|
if stack:
|
||||||
# In order to be compatible with Python 3.8 we need to use this hack to get the path:
|
stack_config = get_parsed_stack_config(stack)
|
||||||
# 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
|
# TODO: syntax check the input here
|
||||||
packages_in_scope = stack_config['npms']
|
packages_in_scope = stack_config['npms']
|
||||||
else:
|
else:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright © 2022 Cerc
|
# Copyright © 2022, 2023 Cerc
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -22,8 +22,7 @@ from python_on_whales import DockerClient
|
|||||||
import click
|
import click
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
from .util import include_exclude_check, get_parsed_stack_config
|
||||||
from .util import include_exclude_check
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@ -62,11 +61,7 @@ def command(ctx, include, exclude, cluster, command, services):
|
|||||||
|
|
||||||
pods_in_scope = []
|
pods_in_scope = []
|
||||||
if stack:
|
if stack:
|
||||||
# In order to be compatible with Python 3.8 we need to use this hack to get the path:
|
stack_config = get_parsed_stack_config(stack)
|
||||||
# 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
|
# TODO: syntax check the input here
|
||||||
pods_in_scope = stack_config['pods']
|
pods_in_scope = stack_config['pods']
|
||||||
else:
|
else:
|
||||||
|
28
app/util.py
28
app/util.py
@ -1,4 +1,4 @@
|
|||||||
# Copyright © 2022 Cerc
|
# Copyright © 2022, 2023 Cerc
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -13,6 +13,12 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
import yaml
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def include_exclude_check(s, include, exclude):
|
def include_exclude_check(s, include, exclude):
|
||||||
if include is None and exclude is None:
|
if include is None and exclude is None:
|
||||||
return True
|
return True
|
||||||
@ -22,3 +28,23 @@ def include_exclude_check(s, include, exclude):
|
|||||||
if exclude is not 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
|
||||||
|
|
||||||
|
|
||||||
|
def get_parsed_stack_config(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")
|
||||||
|
try:
|
||||||
|
with stack_file_path:
|
||||||
|
stack_config = yaml.safe_load(open(stack_file_path, "r"))
|
||||||
|
return stack_config
|
||||||
|
except FileNotFoundError as error:
|
||||||
|
# We try here to generate a useful diagnostic error
|
||||||
|
# First check if the stack directory is present
|
||||||
|
stack_directory = stack_file_path.parent
|
||||||
|
if os.path.exists(stack_directory):
|
||||||
|
print(f"Error: stack.yml file is missing from stack: {stack}")
|
||||||
|
else:
|
||||||
|
print(f"Error: stack: {stack} does not exist")
|
||||||
|
print(f"Exiting, error: {error}")
|
||||||
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user