Spec out a second approach
This commit is contained in:
parent
982cdafea3
commit
e2eee7f3bb
45
second.py
45
second.py
@ -1,27 +1,58 @@
|
|||||||
"""Less flashy version. Mord hard-coding."""
|
"""Less flashy version. Mord hard-coding."""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from shlex import split
|
||||||
|
from subprocess import run
|
||||||
|
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
from wtforms import PasswordField, StringField
|
||||||
|
from wtforms.validators import DataRequired
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Note(decentral1se): load from env vars at some point
|
|
||||||
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
|
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
|
||||||
|
|
||||||
yaml = YAML()
|
yaml = YAML()
|
||||||
|
|
||||||
# Note(decentral1se): paths needs to change dependening
|
APPS = {"gitea": "https://git.autonomic.zone/compose-stacks/gitea"}
|
||||||
# on deployment mode ./data in dev, /data in production
|
|
||||||
DATA_DIR = Path("./data")
|
DATA_DIR = Path("./data")
|
||||||
|
|
||||||
STATIC_DIR = Path(app.root_path).absolute() / "static"
|
|
||||||
|
class GiteaConfigForm(FlaskForm):
|
||||||
|
app_name = StringField("Application name", default="Gitea")
|
||||||
|
db_host = StringField("Database host", default="mariadb:3306")
|
||||||
|
db_name = StringField("Database name", default="gitea")
|
||||||
|
db_passwd = PasswordField("Database password", validators=[DataRequired()])
|
||||||
|
db_root_passwd = PasswordField(
|
||||||
|
"Root database password", validators=[DataRequired()]
|
||||||
|
)
|
||||||
|
db_type = StringField("Database type", default="mysql")
|
||||||
|
db_user = StringField("Database user", default="mysql")
|
||||||
|
domain = StringField("Domain name", validators=[DataRequired()])
|
||||||
|
ssh_port = StringField("SSH port", default="2222")
|
||||||
|
stack_name = StringField("Stack name", default="gitea")
|
||||||
|
internal_token = PasswordField("Internal token", validators=[DataRequired()])
|
||||||
|
jwt_secret = PasswordField("JWT secret", validators=[DataRequired()])
|
||||||
|
|
||||||
|
|
||||||
|
def clone_app_template(app_name):
|
||||||
|
"""Git clone an app template repository."""
|
||||||
|
clone_path = DATA_DIR / app_name
|
||||||
|
clone_url = apps[app_name]
|
||||||
|
run(split(f"git clone {clone_url} {clone_path}"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def index():
|
||||||
pass
|
return render_template("second/index.html", apps=[app for app in APPS])
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/<app_name>")
|
||||||
|
def app_config(app_name):
|
||||||
|
if app_name == "gitea":
|
||||||
|
form = GiteaConfigForm()
|
||||||
|
return render_template("second/install.html", app_name=app_name, form=form)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
16
templates/second/index.html
Normal file
16
templates/second/index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Magic App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>List of apps that can be installed:</p>
|
||||||
|
<ul>
|
||||||
|
{% for app in apps %}
|
||||||
|
<li><a href="/{{ app }}">{{ app }}</a></li>
|
||||||
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
</body>
|
||||||
|
</html>
|
20
templates/second/install.html
Normal file
20
templates/second/install.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Install {{ app_name }}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Install {{ app_name }}</p>
|
||||||
|
<form method="POST" action="/deploy">
|
||||||
|
{% for field in form %}
|
||||||
|
<div>
|
||||||
|
{{ field.label() }}
|
||||||
|
{{ field() }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<input type="submit" value="Deploy" />
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user