Skip to content

Commit b4d6ee9

Browse files
committed
staging
1 parent 5ad937d commit b4d6ee9

File tree

12 files changed

+134
-29
lines changed

12 files changed

+134
-29
lines changed

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Current File",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal",
13+
"justMyCode": true
14+
}
15+
]
16+
}

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
language: py
1515
k8s:
1616
deploymentPath: api/manifests
17-
namespace: bigbang
17+
namespace: apps
1818
host: aks
1919
hooks:
2020
postdeploy:

src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.azure

src/api/manifests/helm-release.yaml.tmpl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,5 @@ spec:
2222
- kind: Secret
2323
name: common-bb
2424
valuesKey: values.yaml
25-
values:
26-
nameOverride: ${SERVICE_NAME}-istio-svc
27-
fullnameOverride: ${SERVICE_NAME}-istio-svc
28-
replicas: 1
29-
istio:
30-
gateways:
31-
- 'istio-system/public'
32-
hosts:
33-
- '${SERVICE_NAME}-istio-svc.bigbang.dev'
34-
image:
35-
repository: ${SERVICE_API_IMAGE_NAME}
36-
pullSecret: private-registry
37-
service:
38-
port: 5000
25+
- kind: ConfigMap
26+
name: common
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
apiVersion: kustomize.config.k8s.io/v1beta1
2-
kind: Kustomization
31
resources:
42
- namespace.yaml
53
- repository.yaml
6-
- helm-release.yaml
4+
- helm-release.yaml
5+
6+
configMapGenerator:
7+
- name: common
8+
behavior: create
9+
files:
10+
- values.yaml

src/api/manifests/repository.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ spec:
1111
url: https://github.com/csemissionplatformops/big-bang-istio-service.git
1212
ref:
1313
branch: main
14-
tag: 0.0.10
14+
tag: 0.0.12

src/api/manifests/values.yaml.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
nameOverride: ${SERVICE_NAME}-istio-svc
2+
fullnameOverride: ${SERVICE_NAME}-istio-svc
3+
replicas: 1
4+
5+
istio:
6+
gateways:
7+
- 'istio-system/public'
8+
hosts:
9+
- '${SERVICE_NAME}-istio-svc.bigbang.dev'
10+
11+
image:
12+
repository: ${SERVICE_API_IMAGE_NAME}
13+
pullSecret: private-registry
14+
15+
service:
16+
port: 5000

src/azure.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
2+
3+
name: src

src/hooks/postdeploy.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from wrappers.renderer import RenderEngine
88

99
TEMPLATE_FILE = "azure.yaml"
10+
CWD = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
1011

1112
def set_env_from_azd():
1213
"""
@@ -21,28 +22,28 @@ def set_env_from_azd():
2122
os.environ[key] = value
2223

2324
def get_services_to_deploy(yaml_template) -> dict:
24-
template_file = os.path.join(os.getcwd(), yaml_template)
25+
template_file = os.path.join(CWD, yaml_template)
2526

2627
with open(template_file, "r", encoding="utf-8") as stream:
2728
try:
2829
# Converts yaml document to python object
2930
yaml_dict = yaml.safe_load(stream)
3031

3132
if "services" not in yaml_dict:
32-
raise ValueError("No services found in yaml file.")
33+
raise ValueError(f"No services found in yaml file {template_file}.")
3334

3435
return yaml_dict["services"]
3536
except yaml.YAMLError as ex:
3637
print("Error loading yaml file: ", ex)
3738

3839
def pre_req_assertions(deployment_template):
39-
azure_dir = os.path.join(os.getcwd(), ".azure")
40-
template_file = os.path.join(os.getcwd(), deployment_template)
40+
azure_dir = os.path.join(CWD, ".azure")
41+
template_file = os.path.join(CWD, deployment_template)
4142

4243
# verify that the .azure folder exists
4344
if not os.path.exists(azure_dir):
4445
raise ValueError(
45-
"The .azure folder does not exist. Please run 'azd init' \
46+
f"The .azure folder in {azure_dir} does not exist. Please run 'azd init' \
4647
to setup your environment."
4748
)
4849

@@ -108,11 +109,15 @@ def ignore_func(_, files):
108109
and "deploymentPath" in services_to_deploy[service]["k8s"]:
109110
manifest_dir = services_to_deploy[service]["k8s"]["deploymentPath"]
110111

111-
manifest_path = os.path.join(os.getcwd(), project_dir, manifest_dir)
112-
service_render_path = os.path.join(git_clone_dir, "environments", \
113-
environment_name, "src", "manifests", "services", service)
112+
manifest_path = os.path.join(CWD, project_dir, manifest_dir)
113+
gitops_environment_path = os.path.join(git_clone_dir, "environments", \
114+
environment_name, "src", "manifests")
115+
service_render_path = os.path.join(gitops_environment_path, "services", service)
114116
copy_manifest_dir_tree_to_repo(manifest_path, service_render_path)
115-
render_client = RenderEngine(service_render_path)
117+
render_client = RenderEngine(service_render_path, \
118+
os.path.join(gitops_environment_path, \
119+
"kustomization.yaml"), \
120+
service)
116121
render_client.render()
117122
git_client.push_changes(git_clone_dir, f"Deployed service: {service}")
118123
print(f"Service {service} deployed successfully.")

src/hooks/wrappers/renderer.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22
import subprocess
3+
import yaml
34

45
class RenderEngine:
5-
def __init__(self, path):
6+
def __init__(self, path, kustomization_path, service_name):
67
self.path = path
8+
self.service_name = service_name
9+
self.kustomization_path = kustomization_path
710
self.remove_template_file = True
811

912
def __retrieve_files_to_render(self):
@@ -23,6 +26,38 @@ def render(self):
2326
if self.remove_template_file:
2427
os.remove(file)
2528

29+
self.__add_service_to_kustomization_resources()
30+
31+
def __run_command(self, command):
32+
try:
33+
output = subprocess.check_output(command, stderr=subprocess.STDOUT, \
34+
universal_newlines=True, shell=True)
35+
return output.strip()
36+
except subprocess.CalledProcessError as ex:
37+
print(f"Error: {ex.output}")
38+
return None
39+
40+
def __add_service_to_kustomization_resources(self):
41+
# verify that the kustomization file exists
42+
if not os.path.exists(self.kustomization_path):
43+
raise ValueError(
44+
f"The kustomization file {self.kustomization_path} does not exist."
45+
)
46+
47+
print(f"Adding {self.service_name} to {self.kustomization_path}")
48+
49+
with open(self.kustomization_path, "r", encoding="utf-8") as r_stream:
50+
yaml_dict = yaml.safe_load(r_stream)
51+
# check if the resources key exists
52+
53+
if "resources" not in yaml_dict:
54+
raise ValueError("No resources found in kustomization yaml file.")
55+
56+
yaml_dict["resources"].append(f"./services/{self.service_name}")
57+
# Write the updated yaml to the kustomization file\
58+
with open(self.kustomization_path, "w", encoding="utf-8") as w_stream:
59+
yaml.safe_dump(yaml_dict, w_stream, default_flow_style=False, sort_keys=False)
60+
2661
def __run_command(self, command):
2762
try:
2863
output = subprocess.check_output(command, stderr=subprocess.STDOUT, \

0 commit comments

Comments
 (0)