feat: configurable VM base domain and customer Gitea and Woodpecker URI generators
SUMMARY The hostnames are partially generated by the Dashboard and enough.community. The stuff between angle brackets(`<>`) are substituted and filled-in by the Dashboard and the stuff between parenthesis(`{}`) are substituted and filled-in by enough. URI FORMAT Gitea URI <vm-name>.{{ domain }} Woodpecker URI <vm-name>-ci.{{ domain }} Where domain is agreed to be equal to HOSTEA_DOMAIN fixes: https://gitea.hostea.org/Hostea/dashboard/issues/11wip-hostea-domain
parent
e4c418b45b
commit
fc5a23e60a
|
@ -76,7 +76,8 @@ HOSTEA = {
|
|||
"REMOTE": env.get_value("HOSTEA_INFRA_HOSTEA_REPO_REMOTE"),
|
||||
# SSH key that can push to the Git repository remote mentioned above
|
||||
"SSH_KEY": env.get_value("HOSTEA_INFRA_HOSTEA_REPO_SSH_KEY"),
|
||||
}
|
||||
},
|
||||
"HOSTEA_DOMAIN": "hostea.org", # domain at which Hostea VMs will be spun up
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ HOSTEA = {
|
|||
"REMOTE": "git@localhost:Hostea/enough.git",
|
||||
# SSH key that can push to the Git repository remote mentioned above
|
||||
"SSH_KEY": "/srv/hostea/deploy",
|
||||
}
|
||||
},
|
||||
"HOSTEA_DOMAIN": "",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,8 @@ HOSTEA = {
|
|||
"REMOTE": "git@localhost:Hostea/enough.git",
|
||||
# SSH key that can push to the Git repository remote mentioned above
|
||||
"SSH_KEY": "/srv/hostea/deploy",
|
||||
}
|
||||
},
|
||||
"HOSTEA_DOMAIN": "vm.hostea.org", # domain at which Hostea VMs will be spun up
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -84,13 +84,40 @@ class Infra:
|
|||
"""
|
||||
return self._host_vars_dir(subdomain=subdomain).joinpath("provision.yml")
|
||||
|
||||
@staticmethod
|
||||
def get_gitea_uri(instance: Instance) -> str:
|
||||
"""
|
||||
Get an instance's Gitea URI
|
||||
"""
|
||||
base = settings.HOSTEA["INFRA"]["HOSTEA_DOMAIN"]
|
||||
return f"https://{instance.name}{base}"
|
||||
|
||||
@staticmethod
|
||||
def _gen_woodpecker_hostname(instance: Instance) -> str:
|
||||
"""
|
||||
Get Woodpecker hostname of an instance
|
||||
"""
|
||||
return (f"{instance.name}-ci",)
|
||||
|
||||
@staticmethod
|
||||
def get_woodpecker_hostname(instance: Instance) -> str:
|
||||
"""
|
||||
Get an instance's Gitea URI
|
||||
"""
|
||||
base = settings.HOSTEA["INFRA"]["HOSTEA_DOMAIn"]
|
||||
return f"https://{self._gen_woodpecker_hostname(instance=instance)}{base}"
|
||||
|
||||
def get_flavor(self, instance: Instance):
|
||||
"""
|
||||
Get VM flavour/size/configuration from the fleet repository
|
||||
"""
|
||||
subdomain = instance.name
|
||||
provision = self._provision_path(subdomain)
|
||||
with open(provision, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f)
|
||||
if "openstack_flavor" in config:
|
||||
return config["openstack_flavor"].split("{{ ")[1].split(" }}")[0]
|
||||
return None
|
||||
|
||||
def _gitea_path(self, subdomain: str) -> Path:
|
||||
"""
|
||||
|
@ -154,15 +181,19 @@ class Infra:
|
|||
def _pull(self):
|
||||
self.repo.git.pull(env=self.env, rebase="true")
|
||||
|
||||
def translate_size(self, instance: Instance) -> str:
|
||||
@staticmethod
|
||||
def translate_size(instance: Instance) -> str:
|
||||
"""
|
||||
Translate openstack(I think OVH-specific) sizes to enough.community
|
||||
normalized sizes
|
||||
"""
|
||||
if instance.configuration_id.name == "s1-2":
|
||||
return "openstack_flavor_small"
|
||||
elif instance.configuration_id.name == "s1-4":
|
||||
if instance.configuration_id.name == "s1-4":
|
||||
return "openstack_flavor_medium"
|
||||
elif instance.configuration_id.name == "s1-8":
|
||||
if instance.configuration_id.name == "s1-8":
|
||||
return "openstack_flavor_large"
|
||||
else:
|
||||
return instance.configuration_id.name
|
||||
return instance.configuration_id.name
|
||||
|
||||
def add_vm(self, instance: Instance) -> (str, Commit):
|
||||
"""
|
||||
|
@ -187,7 +218,7 @@ class Infra:
|
|||
|
||||
ctx = {
|
||||
"woodpecker_agent_secret": woodpecker_agent_secret,
|
||||
"woodpecker_hostname": f"{subdomain}-ci",
|
||||
"woodpecker_hostname": self._gen_woodpecker_hostname(instance=instance),
|
||||
"woodpecker_admins": f"{instance.owned_by.username}",
|
||||
"gitea_email": instance.owned_by.email,
|
||||
"gitea_password": gitea_password,
|
||||
|
@ -203,14 +234,8 @@ class Infra:
|
|||
)
|
||||
)
|
||||
|
||||
# provision_template = "./templates/infrastructure/yml/provision.yml"
|
||||
size = self.translate_size(instance=instance)
|
||||
provision = self._provision_path(subdomain)
|
||||
# TODO: instance config names are different the flavours expected:
|
||||
# ```
|
||||
# openstack_flavor: ‘{{ openstack_flavor_medium }}’ * openstack_flavor: ‘{{ openstack_flavor_large }}’
|
||||
# ```
|
||||
# check with @dachary about this
|
||||
|
||||
with open(provision, "w+", encoding="utf-8") as f:
|
||||
f.write(
|
||||
|
@ -219,10 +244,7 @@ class Infra:
|
|||
)
|
||||
)
|
||||
|
||||
assert provision.exists()
|
||||
# backup = self.repo_path.joinpath(f"inventory/{instance.name}-backup.yml")
|
||||
backup = self._backup_path(subdomain)
|
||||
# backup_template = "./templates/infrastructure/yml/provision.yml"
|
||||
with open(backup, "w+", encoding="utf-8") as f:
|
||||
f.write(
|
||||
render_to_string(
|
||||
|
@ -238,8 +260,6 @@ class Infra:
|
|||
)
|
||||
)
|
||||
|
||||
# hostscript = self.repo_path.join("inventory/hosts-scripts/{instance.name}-host.sh")
|
||||
|
||||
hostscript = self._hostscript_path(subdomain)
|
||||
with open(hostscript, "w+", encoding="utf-8") as f:
|
||||
f.write("\n")
|
||||
|
|
|
@ -26,7 +26,7 @@ from accounts.decorators import confirm_access
|
|||
from dash.models import Instance
|
||||
from billing.utils import payment_fullfilled
|
||||
|
||||
from .utils import create_vm_if_not_exists
|
||||
from .utils import create_vm_if_not_exists, Infra
|
||||
|
||||
|
||||
def default_ctx(title: str, username: str):
|
||||
|
@ -71,6 +71,7 @@ docs or contact support!\n
|
|||
|
||||
ctx = {
|
||||
"gitea_password": gitea_password,
|
||||
"gitea_uri": Infra.get_gitea_uri(instance=instance),
|
||||
}
|
||||
return render(request, "infrastructure/html/create.html", ctx)
|
||||
return HttpResponse()
|
||||
|
|
Loading…
Reference in New Issue