Merge pull request #769 from usrpro/fix-setup-filegen

Fix setup filegen
master
mergify[bot] 6 years ago committed by GitHub
commit 7509b84100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,17 +5,21 @@ version: '3.6'
services: services:
redis: redis:
image: redis:alpine image: redis:alpine
networks:
- default
setup_master: setup_master:
image: mailu/setup:master image: mailu/setup:master
networks: networks:
- web - web
- default
env_file: .env env_file: .env
environment: environment:
this_version: "master" this_version: "master"
labels: labels:
- traefik.enable=true - traefik.enable=true
- traefik.port=80 - traefik.port=80
- traefik.docker.network=web
- traefik.main.frontend.rule=Host:${ADDRESS};PathPrefix:/master/ - traefik.main.frontend.rule=Host:${ADDRESS};PathPrefix:/master/
depends_on: depends_on:
- redis - redis
@ -24,12 +28,14 @@ services:
image: mailu/setup:${RELEASE} image: mailu/setup:${RELEASE}
networks: networks:
- web - web
- default
env_file: .env env_file: .env
environment: environment:
this_version: ${RELEASE} this_version: ${RELEASE}
labels: labels:
- traefik.enable=true - traefik.enable=true
- traefik.port=80 - traefik.port=80
- traefik.docker.network=web
- traefik.root.frontend.redirect.regex=.* - traefik.root.frontend.redirect.regex=.*
- traefik.root.frontend.redirect.replacement=/${RELEASE}/ - traefik.root.frontend.redirect.replacement=/${RELEASE}/
- traefik.root.frontend.rule=Host:${ADDRESS};PathPrefix:/ - traefik.root.frontend.rule=Host:${ADDRESS};PathPrefix:/
@ -40,3 +46,5 @@ services:
networks: networks:
web: web:
external: true external: true
default:
external: false

@ -11,8 +11,8 @@ in a project directory. First create your project directory.</p>
to read and check the configuration variables generated by the wizard.</p> to read and check the configuration variables generated by the wizard.</p>
<pre><code>cd {{ root }} <pre><code>cd {{ root }}
curl {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }} > docker-compose.yml wget {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }}
curl {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }} > mailu.env wget {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }}
</pre></code> </pre></code>
{% endcall %} {% endcall %}

@ -11,8 +11,8 @@ in a project directory. First create your project directory.</p>
to read and check the configuration variables generated by the wizard.</p> to read and check the configuration variables generated by the wizard.</p>
<pre><code>cd {{ root }} <pre><code>cd {{ root }}
curl {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }} > docker-compose.yml wget {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }}
curl {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }} > mailu.env wget {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }}
</pre></code> </pre></code>
{% endcall %} {% endcall %}

@ -10,7 +10,9 @@ import random
import ipaddress import ipaddress
app = flask.Flask(__name__) version = os.getenv("this_version")
static_url_path = "/" + version + "/static"
app = flask.Flask(__name__, static_url_path=static_url_path)
flask_bootstrap.Bootstrap(app) flask_bootstrap.Bootstrap(app)
db = redis.StrictRedis(host='redis', port=6379, db=0) db = redis.StrictRedis(host='redis', port=6379, db=0)
@ -40,29 +42,37 @@ def build_app(path):
def app_context(): def app_context():
return dict(versions=os.getenv("VERSIONS","master").split(',')) return dict(versions=os.getenv("VERSIONS","master").split(','))
version = os.getenv("this_version") prefix_bp = flask.Blueprint(version, __name__)
prefix_bp.jinja_loader = jinja2.ChoiceLoader([
bp = flask.Blueprint(version, __name__)
bp.jinja_loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader(os.path.join(path, "templates")), jinja2.FileSystemLoader(os.path.join(path, "templates")),
jinja2.FileSystemLoader(os.path.join(path, "flavors")) jinja2.FileSystemLoader(os.path.join(path, "flavors"))
]) ])
@bp.context_processor root_bp = flask.Blueprint("root", __name__)
root_bp.jinja_loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader(os.path.join(path, "templates")),
jinja2.FileSystemLoader(os.path.join(path, "flavors"))
])
@prefix_bp.context_processor
@root_bp.context_processor
def bp_context(version=version): def bp_context(version=version):
return dict(version=version) return dict(version=version)
@bp.route("/") @prefix_bp.route("/")
@root_bp.route("/")
def wizard(): def wizard():
return flask.render_template('wizard.html') return flask.render_template('wizard.html')
@bp.route("/submit_flavor", methods=["POST"]) @prefix_bp.route("/submit_flavor", methods=["POST"])
@root_bp.route("/submit_flavor", methods=["POST"])
def submit_flavor(): def submit_flavor():
data = flask.request.form.copy() data = flask.request.form.copy()
steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"]))) steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"])))
return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps) return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps)
@bp.route("/submit", methods=["POST"]) @prefix_bp.route("/submit", methods=["POST"])
@root_bp.route("/submit", methods=["POST"])
def submit(): def submit():
data = flask.request.form.copy() data = flask.request.form.copy()
data['uid'] = str(uuid.uuid4()) data['uid'] = str(uuid.uuid4())
@ -70,14 +80,16 @@ def build_app(path):
db.set(data['uid'], json.dumps(data)) db.set(data['uid'], json.dumps(data))
return flask.redirect(flask.url_for('.setup', uid=data['uid'])) return flask.redirect(flask.url_for('.setup', uid=data['uid']))
@bp.route("/setup/<uid>", methods=["GET"]) @prefix_bp.route("/setup/<uid>", methods=["GET"])
@root_bp.route("/setup/<uid>", methods=["GET"])
def setup(uid): def setup(uid):
data = json.loads(db.get(uid)) data = json.loads(db.get(uid))
flavor = data.get("flavor", "compose") flavor = data.get("flavor", "compose")
rendered = render_flavor(flavor, "setup.html", data) rendered = render_flavor(flavor, "setup.html", data)
return flask.render_template("setup.html", contents=rendered) return flask.render_template("setup.html", contents=rendered)
@bp.route("/file/<uid>/<filepath>", methods=["GET"]) @prefix_bp.route("/file/<uid>/<filepath>", methods=["GET"])
@root_bp.route("/file/<uid>/<filepath>", methods=["GET"])
def file(uid, filepath): def file(uid, filepath):
data = json.loads(db.get(uid)) data = json.loads(db.get(uid))
flavor = data.get("flavor", "compose") flavor = data.get("flavor", "compose")
@ -86,7 +98,8 @@ def build_app(path):
mimetype="application/text" mimetype="application/text"
) )
app.register_blueprint(bp, url_prefix="/{}".format(version)) app.register_blueprint(prefix_bp, url_prefix="/{}".format(version))
app.register_blueprint(root_bp)
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save