More fishing around in the dark

This commit is contained in:
Luke Murphy 2020-07-01 21:19:09 +02:00
parent 38cc463a1d
commit ae06f928bf
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 38 additions and 3 deletions

View File

@ -1,10 +1,13 @@
"""Less flashy version. More hard-coding.""" """Less flashy version. More hard-coding."""
from json import dumps, loads
from os import environ
from os.path import exists
from pathlib import Path from pathlib import Path
from shlex import split from shlex import split
from subprocess import run from subprocess import run
from flask import Flask, render_template from flask import Flask, render_template, request
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from ruamel.yaml import YAML from ruamel.yaml import YAML
from wtforms import PasswordField, StringField from wtforms import PasswordField, StringField
@ -43,17 +46,49 @@ def clone_app_template(app_name):
run(split(f"git clone {clone_url} {clone_path}")) run(split(f"git clone {clone_url} {clone_path}"))
def dump_db(db):
"""Dump the database."""
with open(DATA_DIR / "db.json", "w") as handle:
return handle.write(dumps(db))
def load_db():
"""Load the database."""
db_path = DATA_DIR / "db.json"
if exists(db_path):
with open(db_path, "r") as handle:
return loads(handle.read())
return {}
@app.route("/") @app.route("/")
def index(): def index():
return render_template("second/index.html", apps=[app for app in APPS]) return render_template("second/index.html", apps=[app for app in APPS])
@app.route("/config/<app_name>") @app.route("/config/<app_name>")
def app_config(app_name): def config(app_name):
if app_name == "gitea": if app_name == "gitea":
# Note(decentral1se): load db.json and pre-populate the form?
form = GiteaConfigForm() form = GiteaConfigForm()
return render_template("second/config.html", app_name=app_name, form=form) return render_template("second/config.html", app_name=app_name, form=form)
@app.route("/deploy/<app_name>", methods=["POST"])
def deploy(app_name):
environment = environ.copy()
for key in request.form.keys():
environment[key.upper()] = request.form[key]
# Note(decentral1se): how to handle the following?
# configs -> ${STACK_NAME}_app_ini_${APP_INI_VERSION}
# secrets -> ${STACK_NAME}_db_passwd_${DB_PASSWD_VERSION}
# and dump it all to the db.json when we're done here too
compose_yml = DATA_DIR / app_name / "compose.yml"
command = f"docker stack deploy -c {compose_yml} {app_name}"
run(split(command), env=environment)
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0") app.run(debug=True, host="0.0.0.0")

View File

@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<p>Install {{ app_name }}</p> <p>Install {{ app_name }}</p>
<form method="POST" action="/deploy"> <form method="POST" action="/deploy/{{ app_name }}">
{% for field in form %} {% for field in form %}
<div> <div>
{{ field.label() }} {{ field.label() }}