From 8c6e0c56fb02712f6890e88d3e8446fc29eb619e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Wed, 19 Dec 2018 15:02:00 +0200 Subject: [PATCH 1/5] Fix redis connection errors --- setup/docker-compose.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup/docker-compose.yml b/setup/docker-compose.yml index 7c31d2cd..6d14153a 100644 --- a/setup/docker-compose.yml +++ b/setup/docker-compose.yml @@ -5,17 +5,21 @@ version: '3.6' services: redis: image: redis:alpine + networks: + - default setup_master: image: mailu/setup:master networks: - web + - default env_file: .env environment: this_version: "master" labels: - traefik.enable=true - traefik.port=80 + - traefik.docker.network=web - traefik.main.frontend.rule=Host:${ADDRESS};PathPrefix:/master/ depends_on: - redis @@ -24,12 +28,14 @@ services: image: mailu/setup:${RELEASE} networks: - web + - default env_file: .env environment: this_version: ${RELEASE} labels: - traefik.enable=true - traefik.port=80 + - traefik.docker.network=web - traefik.root.frontend.redirect.regex=.* - traefik.root.frontend.redirect.replacement=/${RELEASE}/ - traefik.root.frontend.rule=Host:${ADDRESS};PathPrefix:/ @@ -40,3 +46,5 @@ services: networks: web: external: true + default: + external: false From 1b64c80612109d4f97b5336e257df93c8e846cf6 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Wed, 19 Dec 2018 17:15:45 +0200 Subject: [PATCH 2/5] Managing different blueprint prefixes --- setup/server.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/setup/server.py b/setup/server.py index 456cb539..2b27cb3b 100644 --- a/setup/server.py +++ b/setup/server.py @@ -42,27 +42,37 @@ def build_app(path): version = os.getenv("this_version") - bp = flask.Blueprint(version, __name__) - bp.jinja_loader = jinja2.ChoiceLoader([ + prefix_bp = flask.Blueprint(version, __name__) + prefix_bp.jinja_loader = jinja2.ChoiceLoader([ jinja2.FileSystemLoader(os.path.join(path, "templates")), 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): return dict(version=version) - @bp.route("/") + @prefix_bp.route("/") + @root_bp.route("/") def wizard(): 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(): data = flask.request.form.copy() steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"]))) 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(): data = flask.request.form.copy() data['uid'] = str(uuid.uuid4()) @@ -70,14 +80,16 @@ def build_app(path): db.set(data['uid'], json.dumps(data)) return flask.redirect(flask.url_for('.setup', uid=data['uid'])) - @bp.route("/setup/", methods=["GET"]) + @prefix_bp.route("/setup/", methods=["GET"]) + @root_bp.route("/setup/", methods=["GET"]) def setup(uid): data = json.loads(db.get(uid)) flavor = data.get("flavor", "compose") rendered = render_flavor(flavor, "setup.html", data) return flask.render_template("setup.html", contents=rendered) - @bp.route("/file//", methods=["GET"]) + @prefix_bp.route("/file//", methods=["GET"]) + @root_bp.route("/file//", methods=["GET"]) def file(uid, filepath): data = json.loads(db.get(uid)) flavor = data.get("flavor", "compose") @@ -86,7 +98,8 @@ def build_app(path): 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__": From 598ad4fc7ad296eef65d038aa01db8f2ef09ba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Sun, 30 Dec 2018 20:52:34 +0200 Subject: [PATCH 3/5] Prefix static path with version for Traefik --- setup/server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/server.py b/setup/server.py index 2b27cb3b..3c950b0a 100644 --- a/setup/server.py +++ b/setup/server.py @@ -10,7 +10,9 @@ import random 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) db = redis.StrictRedis(host='redis', port=6379, db=0) @@ -40,8 +42,6 @@ def build_app(path): def app_context(): 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([ jinja2.FileSystemLoader(os.path.join(path, "templates")), From c1bfde4e150922745373f848cba7ae58694136f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Mon, 31 Dec 2018 00:19:21 +0200 Subject: [PATCH 4/5] Use wget for file dowloads. Curl doesn't like the Traefik redirects --- setup/flavors/compose/setup.html | 4 ++-- setup/flavors/stack/setup.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/setup/flavors/compose/setup.html b/setup/flavors/compose/setup.html index 3d87a263..5d27cd2a 100644 --- a/setup/flavors/compose/setup.html +++ b/setup/flavors/compose/setup.html @@ -11,8 +11,8 @@ in a project directory. First create your project directory.

to read and check the configuration variables generated by the wizard.

cd {{ root }}
-curl {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }} > docker-compose.yml
-curl {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }} > mailu.env
+wget {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }}
+wget {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }}
 
{% endcall %} diff --git a/setup/flavors/stack/setup.html b/setup/flavors/stack/setup.html index d68a6422..d214e3c5 100644 --- a/setup/flavors/stack/setup.html +++ b/setup/flavors/stack/setup.html @@ -11,8 +11,8 @@ in a project directory. First create your project directory.

to read and check the configuration variables generated by the wizard.

cd {{ root }}
-curl {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }} > docker-compose.yml
-curl {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }} > mailu.env
+wget {{ url_for('.file', uid=uid, filepath='docker-compose.yml', _external=True) }}
+wget {{ url_for('.file', uid=uid, filepath='mailu.env', _external=True) }}
 
{% endcall %} From 738d98e5abd040355f851fd829f455235ec30a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Wed, 2 Jan 2019 20:11:12 +0200 Subject: [PATCH 5/5] Fix code formatting --- setup/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/server.py b/setup/server.py index 3c950b0a..4474cd6c 100644 --- a/setup/server.py +++ b/setup/server.py @@ -12,7 +12,7 @@ import ipaddress version = os.getenv("this_version") static_url_path = "/" + version + "/static" -app = flask.Flask(__name__,static_url_path=static_url_path) +app = flask.Flask(__name__, static_url_path=static_url_path) flask_bootstrap.Bootstrap(app) db = redis.StrictRedis(host='redis', port=6379, db=0)