Skip to content

Commit d411d6c

Browse files
Merge pull request #41 from baloise-incubator/feat/deploy-handle-missing-file
deploy: print error message if values file not found
2 parents 3599e53 + 04e3738 commit d411d6c

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

gitopscli/__main__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import logging
2+
import sys
23

34
from gitopscli.cliparser import create_cli
45
from gitopscli.commands.add_pr_comment import pr_comment_command
56
from gitopscli.commands.create_preview import create_preview_command
67
from gitopscli.commands.deploy import deploy_command
78
from gitopscli.commands.sync_apps import sync_apps_command
9+
from gitopscli.gitops_exception import GitOpsException
810

911

1012
def main():
@@ -13,16 +15,19 @@ def main():
1315
args = create_cli()
1416

1517
if args.command == "deploy":
16-
deploy_command(**vars(args))
17-
18-
if args.command == "sync-apps":
19-
sync_apps_command(**vars(args))
20-
21-
if args.command == "add-pr-comment":
22-
pr_comment_command(**vars(args))
23-
24-
if args.command == "create-preview":
25-
create_preview_command(**vars(args))
18+
command = deploy_command
19+
elif args.command == "sync-apps":
20+
command = sync_apps_command
21+
elif args.command == "add-pr-comment":
22+
command = pr_comment_command
23+
elif args.command == "create-preview":
24+
command = create_preview_command
25+
26+
try:
27+
command(**vars(args))
28+
except GitOpsException as ex:
29+
logging.error(ex)
30+
sys.exit(1)
2631

2732

2833
if __name__ == "__main__":

gitopscli/commands/deploy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from gitopscli.git.create_git import create_git
77
from gitopscli.yaml.yaml_util import update_yaml_file, yaml_dump
8+
from gitopscli.gitops_exception import GitOpsException
89

910

1011
def deploy_command(
@@ -46,7 +47,11 @@ def deploy_command(
4647
logging.info("Master checkout successful")
4748
git.new_branch(branch)
4849
logging.info("Created branch %s", branch)
50+
4951
full_file_path = git.get_full_file_path(file)
52+
if not os.path.isfile(full_file_path):
53+
raise GitOpsException(f"No such file: {file}")
54+
5055
updated_values = {}
5156
for key in values:
5257
value = values[key]

gitopscli/commands/sync_apps.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from gitopscli.git.create_git import create_git
1010
from gitopscli.yaml.yaml_util import merge_yaml_element
11+
from gitopscli.gitops_exception import GitOpsException
1112

1213

1314
def sync_apps_command(
@@ -92,7 +93,9 @@ def __find_apps_config_from_repo(apps_git, root_git):
9293
if "applications" in app_config_content and app_config_content["applications"] is not None:
9394
apps_from_other_repos += app_config_content["applications"].keys()
9495
if found_app_config_file is None:
95-
raise Exception(f"Could't find config file with .repository={apps_git.get_clone_url()} in apps/ directory")
96+
raise GitOpsException(
97+
f"Could't find config file with .repository={apps_git.get_clone_url()} in apps/ directory"
98+
)
9699
return found_app_config_file, found_app_config_file_name, apps_from_other_repos
97100

98101

@@ -134,4 +137,4 @@ def __get_application_directories(full_file_path):
134137
def __check_if_app_already_exists(apps_dirs, apps_from_other_repos):
135138
for app_key in apps_dirs:
136139
if app_key in apps_from_other_repos:
137-
raise Exception("application: " + app_key + " already exists in a different repository")
140+
raise GitOpsException(f"application: {app_key} already exists in a different repository")

gitopscli/gitops_exception.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class GitOpsException(Exception):
2+
pass

0 commit comments

Comments
 (0)