mirror of
https://github.com/khuedoan/homelab.git
synced 2024-12-23 01:04:32 +07:00
8d00d55eb1
This is a breaking change and requires cluster rebuild (carefully replacing the ApplicationSets may should work but I didn't bother at the current alpha stage): - ApplicationSets are merged into a single root one to use the progressive sync feature when it's ready. - Switched to server side apply to avoid CRDs not ready issues. Also replace the apply script with Ansible, since the Ansible Helm dependency update feature was released.
114 lines
3.0 KiB
Python
Executable File
114 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# WIP
|
|
# TODO clean this up
|
|
|
|
"""
|
|
Basic configure script for new users
|
|
"""
|
|
|
|
import fileinput
|
|
import subprocess
|
|
import sys
|
|
|
|
from rich.prompt import Confirm, Prompt
|
|
|
|
upstream_config = {
|
|
"seed_repo": "https://github.com/khuedoan/homelab",
|
|
"domain": "khuedoan.com",
|
|
"timezone": "Asia/Ho_Chi_Minh",
|
|
"terraform_workspace": "khuedoan",
|
|
"loadbalancer_ip_range": "192.168.1.224/27",
|
|
}
|
|
|
|
|
|
def check_python_version(required_version: str) -> None:
|
|
if sys.version_info < tuple(map(int, required_version.split('.'))):
|
|
raise Exception(f"Must be using Python >= {required_version}")
|
|
|
|
|
|
def find_and_replace(pattern: str, replacement: str, paths: list[str]) -> None:
|
|
files_with_matches = subprocess.run(
|
|
["git", "grep", "--files-with-matches", pattern, "--"] + paths,
|
|
capture_output=True,
|
|
text=True
|
|
).stdout.splitlines()
|
|
|
|
for file_with_maches in files_with_matches:
|
|
with fileinput.FileInput(file_with_maches, inplace=True) as file:
|
|
for line in file:
|
|
print(line.replace(pattern, replacement), end='')
|
|
|
|
|
|
def main() -> None:
|
|
check_python_version(
|
|
required_version='3.10.0'
|
|
)
|
|
|
|
editor = Prompt.ask("Select text editor", default='nvim')
|
|
domain = Prompt.ask("Enter your domain", default=upstream_config['domain'])
|
|
seed_repo = Prompt.ask("Enter seed repo", default=upstream_config['seed_repo'])
|
|
timezone = Prompt.ask("Enter time zone", default=upstream_config['timezone'])
|
|
loadbalancer_ip_range = Prompt.ask("Enter IP range for load balancer", default=upstream_config['loadbalancer_ip_range'])
|
|
|
|
find_and_replace(
|
|
pattern=upstream_config['domain'],
|
|
replacement=domain,
|
|
paths=[
|
|
".ci",
|
|
"apps",
|
|
"platform",
|
|
"system",
|
|
"external"
|
|
]
|
|
)
|
|
|
|
find_and_replace(
|
|
pattern=upstream_config['seed_repo'],
|
|
replacement=seed_repo,
|
|
paths=[
|
|
"system",
|
|
"platform"
|
|
]
|
|
)
|
|
|
|
find_and_replace(
|
|
pattern=upstream_config['timezone'],
|
|
replacement=timezone,
|
|
paths=[
|
|
"apps",
|
|
"system",
|
|
"metal"
|
|
]
|
|
)
|
|
|
|
find_and_replace(
|
|
pattern=upstream_config['loadbalancer_ip_range'],
|
|
replacement=loadbalancer_ip_range,
|
|
paths=[
|
|
"metal/group_vars/all.yml",
|
|
"external/main.tf",
|
|
]
|
|
)
|
|
|
|
if Confirm.ask("Update server list?", default=True):
|
|
subprocess.run(
|
|
[editor, 'metal/inventories/prod.yml']
|
|
)
|
|
|
|
|
|
if Confirm.ask("Do you want to use managed services?"):
|
|
terraform_workspace = Prompt.ask("Enter Terraform Workspace", default=upstream_config['terraform_workspace'])
|
|
|
|
find_and_replace(
|
|
pattern=upstream_config['terraform_workspace'],
|
|
replacement=terraform_workspace,
|
|
paths=[
|
|
"external/versions.tf"
|
|
]
|
|
)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|