Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add ci deployment target3 #14

Closed
wants to merge 66 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
318a118
Add generate manifest python
Oct 6, 2023
e4eb5cf
add exec rights to python
Oct 6, 2023
25d06d6
add shebang
Oct 6, 2023
1eb9dfb
add parser
Oct 6, 2023
c61f2ee
add folders
Oct 6, 2023
fe7b318
add matrix
Oct 6, 2023
7db1bf5
fix
Oct 6, 2023
3571d7d
add new path var
Oct 6, 2023
2924687
add Generated Helm manifests
Oct 6, 2023
acfcf68
added create folder
Oct 6, 2023
9e8f34e
run run_helm_template_cmd
Oct 6, 2023
8d09dda
add file output
Oct 6, 2023
87e7807
draft tested
Oct 6, 2023
d44ed8d
Add optional kustomize
Oct 6, 2023
9b738ef
remove shell script
Oct 6, 2023
66e0e82
refactor structure
Oct 9, 2023
d83cecf
fix chart_name
Oct 9, 2023
0292cc5
remove manifests
Oct 9, 2023
4a1f4f8
test values
Oct 9, 2023
cab26be
fix value 2
Oct 9, 2023
3117ffa
Add example-v2 to deploy
Oct 9, 2023
8129024
test create PR
Oct 9, 2023
7602e8e
fix perm
Oct 9, 2023
7723288
Adapt deploy_branch_name
Oct 9, 2023
41b1a28
refactor workflow
Oct 9, 2023
aa893ea
fix needs
Oct 9, 2023
587b974
use artifacts
Oct 9, 2023
378452b
debug
Oct 9, 2023
37d644f
fix path
Oct 9, 2023
d397b7c
add more stages
Oct 9, 2023
2111e4c
add helm release name
Oct 9, 2023
087e2bc
add deps
Oct 9, 2023
0a64337
set commit PR message
Oct 9, 2023
cc7e4e1
fix pr commit
Oct 9, 2023
1d61e4f
change dev value for infra
Oct 9, 2023
608a4a0
set new url for databaseUrl on ldc
Oct 9, 2023
c42a65b
change pr message
Oct 9, 2023
3131c7f
auto merge to dev
Oct 9, 2023
e552a05
set env per workflow
Oct 9, 2023
129f7e8
set env folder
Oct 9, 2023
44080e8
shorten the worklow
Oct 9, 2023
e05721d
change ingress version
Oct 9, 2023
730e8b8
create DATABASE_URL as env variable
Oct 9, 2023
8011810
modify ingress
Oct 9, 2023
9504326
removed target
Oct 9, 2023
5e7fa3c
activate new target
Oct 9, 2023
4a12158
changed files & folder structure
Oct 16, 2023
cdd5106
refactor parse_yaml_files_in_directory
Oct 16, 2023
a1fc156
add helm pull
Oct 16, 2023
2151cf3
add removal incl content
Oct 16, 2023
6cb0209
Add helm chart path
Oct 16, 2023
a76fdfa
run template
Oct 16, 2023
e0f7541
fix path
Oct 16, 2023
8ec3a96
print output
Oct 16, 2023
fc67cf9
fix folder exists check
Oct 16, 2023
9d11aaa
add automerge variable
Oct 16, 2023
3985d89
Qa auto merge
Oct 16, 2023
35cbe8e
Add build push charts to Artifactory
Nov 9, 2023
c5be196
move
Nov 9, 2023
d624beb
Create Bitbucket script for PR
Nov 9, 2023
e880a9a
unset bash tracing
Nov 9, 2023
567fc80
set rest-api-url as arg
Nov 9, 2023
19f93b4
add changelog
Jun 28, 2024
8400c71
add new chart version
Jun 28, 2024
96db367
add version
Jun 28, 2024
c056eea
add proper old release
Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add helm pull
Boris Kossev committed Oct 16, 2023
commit a1fc156cf5dc1157039fc491252db49a59f84c52
87 changes: 49 additions & 38 deletions .github/workflows/utils/generate-manifests.py
Original file line number Diff line number Diff line change
@@ -67,25 +67,18 @@ def run_helm_template_cmd(chart_path, release_name, value_files, output_manifest
except Exception as e:
print(f"An error occurred: {str(e)}")

def run_command_in_folder(command, working_directory):
try:
# Run the command in the specified working directory
result = subprocess.run(command, shell=True, cwd=working_directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

# Check for errors and print output
if result.returncode == 0:
print(f"Command '{command}' executed successfully.")
print("Output:")
print(result.stdout)
else:
print(f"Error running command '{command}':")
print("Standard Output:")
print(result.stdout)
print("Standard Error:")
print(result.stderr)

except Exception as e:
print(f"An error occurred: {str(e)}")
def remove_directory_if_exists(directory_path):
if os.path.exists(directory_path):
try:
os.rmdir(directory_path) # Remove the directory
print(f"Directory '{directory_path}' removed.")
return True
except OSError as e:
print(f"Error removing directory '{directory_path}': {str(e)}")
return False
else:
print(f"Directory '{directory_path}' does not exist.")
return True # The directory doesn't exist, so it's considered "removed"

def output_file_content(file_path):
try:
@@ -117,37 +110,55 @@ def output_file_content(file_path):
# Parse YAML files in the directory
parsed_yaml_data = parse_yaml_files_in_directory(deployment_targets_path)

sys.exit(0) # Success


# Work with the parsed YAML data as a list of dictionaries
for data in parsed_yaml_data:
print(f"Parsed YAML data as a list of dictionaries:")
print(data)

# construct and create folder for environment
gen_manifests_env_path = os.path.join(gen_manifests_path, data["environment"])
# Create folder for deployment environment
gen_manifests_env_path = os.path.join(gen_manifests_path, data["deployment"]["environment"])
create_folder(gen_manifests_env_path)

# Construct Helm release name
helm_release_name = data["chartReleaseName"]
# Collect Helm chart attributed
helm_release_name = data["chart"]["releaseName"]
helm_chart_name = data["chart"]["name"]

# construct and create folder for chartReleaseName and deploymentTarget
gen_manifests_deployment_target = os.path.join(gen_manifests_env_path, helm_release_name + "-" + data["deploymentTargetName"])
# Construct and create manifest path for generated deployment target
gen_manifests_deployment_target = os.path.join(gen_manifests_env_path, helm_release_name + "-" + data["deployment"]["targetName"])
create_folder(gen_manifests_deployment_target)

# construct list of Helm value files
helm_value_files = data["appValueFiles"] + data["infraValueFiles"]

# Construct file path for Helm output
output_manifest_file = os.path.join(gen_manifests_deployment_target, "gen_manifests.yaml")

# Run Helm template
run_helm_template_cmd(helm_chart_path, helm_release_name, helm_value_files, output_manifest_file)
# Construct list of Helm value files
helm_value_files = data["deployment"]["valueFiles"]["application"] + data["deployment"]["valueFiles"]["infrastructure"]

# Run kustomize command in the generated manifests folder
# command_to_run = "kustomize create --autodetect"
# run_command_in_folder(command_to_run, gen_manifests_deployment_target)
# Process helm chart repository url
is_helm_chart_local = False
helm_chart_repository_url = data["chart"]["repository"]
if helm_chart_repository_url.startswith("file://"):
is_helm_chart_local = True
helm_chart_repository_url = helm_chart_repository_url[len("file://"):]
print(f"Helm chart repostiroy url: '{helm_chart_repository_url}'")

# Helm chart pull from repo
if is_helm_chart_local is not True:
helm_chart_repository_name = data["chart"]["name"] + "-repo"
helm_chart_version = data["chart"]["version"]
helm_chart_untardir = os.path.join(".","charts_upstream")

command = ["helm", "repo", "add", helm_chart_repository_name, helm_chart_repository_url]
subprocess.run(command,text=True,check=True)

remove_directory_if_exists(os.path.join(helm_chart_untardir,helm_chart_name))

command = ["helm", "pull", helm_chart_repository_name + "/" + helm_chart_name]
command.extend(["--version", helm_chart_version])
command.extend(["--untar"])
command.extend(["--untardir", helm_chart_untardir])
subprocess.run(command,text=True,check=True)


# Run Helm template
#run_helm_template_cmd(helm_chart_path, helm_release_name, helm_value_files, output_manifest_file)

# Print generated file content
content = output_file_content(output_manifest_file)