This repository has been archived on 2020-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
magic-app/second.py

60 lines
1.9 KiB
Python
Raw Normal View History

2020-07-01 18:46:29 +00:00
"""Less flashy version. More hard-coding."""
2020-07-01 18:02:19 +00:00
from pathlib import Path
2020-07-01 18:42:47 +00:00
from shlex import split
from subprocess import run
2020-07-01 18:02:19 +00:00
from flask import Flask, render_template
2020-07-01 18:42:47 +00:00
from flask_wtf import FlaskForm
2020-07-01 18:02:19 +00:00
from ruamel.yaml import YAML
2020-07-01 18:42:47 +00:00
from wtforms import PasswordField, StringField
from wtforms.validators import DataRequired
2020-07-01 18:02:19 +00:00
app = Flask(__name__)
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
yaml = YAML()
2020-07-01 18:42:47 +00:00
APPS = {"gitea": "https://git.autonomic.zone/compose-stacks/gitea"}
2020-07-01 18:02:19 +00:00
DATA_DIR = Path("./data")
2020-07-01 18:42:47 +00:00
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}"))
2020-07-01 18:02:19 +00:00
@app.route("/")
2020-07-01 18:42:47 +00:00
def index():
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()
2020-07-01 18:56:16 +00:00
return render_template("second/config.html", app_name=app_name, form=form)
2020-07-01 18:02:19 +00:00
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")