Refactor duplication and use stack name
This commit is contained in:
parent
6c19775b1c
commit
409dfe5955
39
second.py
39
second.py
@ -72,30 +72,21 @@ def get_hash(value: str) -> str:
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def get_secret_names(app_name, form_data, env):
|
||||
"""Generate versioned names for secrets that swarm will accept"""
|
||||
for secret in APPS_SPEC[app_name]["secrets"]:
|
||||
if secret in form_data:
|
||||
hashed = get_hash(form_data[secret])
|
||||
env_key = f"{secret.upper()}_SECRET_VERSION"
|
||||
env[env_key] = f"{secret}_{hashed}"
|
||||
def get_swarm_versions(app_name, form_data, env):
|
||||
"""Version secrets and configs for swarm."""
|
||||
values = [APPS_SPEC[app_name]["secrets"], APPS_SPEC[app_name]["configs"]]
|
||||
for value in values:
|
||||
if value in form_data:
|
||||
hashed = get_hash(form_data[value])
|
||||
env_key = f"{value.upper()}_VERSION"
|
||||
env[env_key] = f"{value}_{hashed}"
|
||||
return env
|
||||
|
||||
|
||||
def get_config_names(app_name, form_data, env):
|
||||
"""Generate versioned names for configs that swarm will accept"""
|
||||
for config in APPS_SPEC[app_name]["configs"]:
|
||||
if config in form_data:
|
||||
hashed = get_hash(form_data[config])
|
||||
env_key = f"{config.upper()}_CONFIG_VERSION"
|
||||
env[env_key] = f"{secret}_{hashed}"
|
||||
return env
|
||||
|
||||
|
||||
def stack_deploy(app_name, env):
|
||||
def stack_deploy(stack_name, app_name, env):
|
||||
"""Depoy an application to the swarm."""
|
||||
compose_yml = DATA_DIR / app_name / "compose.yml"
|
||||
command = f"docker stack deploy -c {compose_yml} {app_name}"
|
||||
command = f"docker stack deploy -c {compose_yml} {stack_name}"
|
||||
run(split(command), env=env)
|
||||
|
||||
|
||||
@ -112,6 +103,7 @@ class GiteaInstallForm(FlaskForm):
|
||||
|
||||
app_name = StringField("Application name", default="Git with a cup of tea")
|
||||
domain = StringField("Domain name", validators=[DataRequired()],)
|
||||
stack_name = StringField("Stack name", default="magic-app-gitea")
|
||||
|
||||
db_host = StringField("Database host", default="mariadb:3306")
|
||||
db_name = StringField("Database name", default="gitea")
|
||||
@ -159,14 +151,11 @@ def deploy(app_name):
|
||||
return render_template("second/install.html", app_name=app_name, form=form)
|
||||
|
||||
env = get_loaded_env(app_name, form.data)
|
||||
env = get_secret_names(app_name, form.data, env)
|
||||
env = get_config_names(app_name, form.data, env)
|
||||
env = get_swarm_versions(app_name, form.data, env)
|
||||
|
||||
app.logger.info(f"env -> {env}")
|
||||
dump_db({fork.data["stack_name"]: form.data})
|
||||
|
||||
dump_db({app_name: form.data})
|
||||
|
||||
stack_deploy(app_name, env)
|
||||
stack_deploy(app_name, form.data["stack_name"], env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user