From efaa3058c0b60b2d6fab9e07f4ec3adb1ef7a0cb Mon Sep 17 00:00:00 2001 From: kaiyou Date: Sat, 10 Mar 2018 14:05:49 +0100 Subject: [PATCH] Very first version of the configuration wizard --- config/flavors/compose/docker-compose.yml | 0 config/flavors/compose/mailu.env | 0 config/flavors/compose/setup.html | 36 +++++++++++++++++++++++ config/requirements.txt | 3 ++ config/server.py | 35 ++++++++++++++++++++++ config/templates/base.html | 4 +++ config/templates/index.html | 22 ++++++++++++++ config/templates/macros.html | 22 ++++++++++++++ config/templates/setup.html | 23 +++++++++++++++ config/templates/steps/expose.html | 25 ++++++++++++++++ config/templates/steps/flavor.html | 16 ++++++++++ 11 files changed, 186 insertions(+) create mode 100644 config/flavors/compose/docker-compose.yml create mode 100644 config/flavors/compose/mailu.env create mode 100644 config/flavors/compose/setup.html create mode 100644 config/requirements.txt create mode 100644 config/server.py create mode 100644 config/templates/base.html create mode 100644 config/templates/index.html create mode 100644 config/templates/macros.html create mode 100644 config/templates/setup.html create mode 100644 config/templates/steps/expose.html create mode 100644 config/templates/steps/flavor.html diff --git a/config/flavors/compose/docker-compose.yml b/config/flavors/compose/docker-compose.yml new file mode 100644 index 00000000..e69de29b diff --git a/config/flavors/compose/mailu.env b/config/flavors/compose/mailu.env new file mode 100644 index 00000000..e69de29b diff --git a/config/flavors/compose/setup.html b/config/flavors/compose/setup.html new file mode 100644 index 00000000..b136250e --- /dev/null +++ b/config/flavors/compose/setup.html @@ -0,0 +1,36 @@ +{% import "macros.html" as macros %} + +{% call macros.panel("info", "Step 1 - Download your configuration files") %} +

Docker Compose expects a project file, named docker-compose.yml +in a project directory. First create your project directory.

+ +
mkdir /path/to/project
+
+ +

Then download the project file. A side configuration file makes it easier +to read and check the configuration variables generated by the wizard.

+ +
cd /path/to/project
+wget https://...
+wget https://...
+
+{% endcall %} + + +{% call macros.panel("info", "Step 2 - Review the configuration") %} +

We did not insert any malicious code on purpose in the configurations we +distribute, but your download could have been intercepted, or our wizard +website could have been compromised, so make sure you check the configuration +files before going any further.

+ +

When you are done checking them, check them one last time.

+{% endcall %} + +{% call macros.panel("info", "Step 3 - Start the Compose project") %} +

To start your compose project, simply run the Docker Compose up +command.

+ +
cd /path/to/project
+docker-compose up -d
+
+{% endcall %} diff --git a/config/requirements.txt b/config/requirements.txt new file mode 100644 index 00000000..88ea3d75 --- /dev/null +++ b/config/requirements.txt @@ -0,0 +1,3 @@ +flask +flask-bootstrap +redis diff --git a/config/server.py b/config/server.py new file mode 100644 index 00000000..a0e3564f --- /dev/null +++ b/config/server.py @@ -0,0 +1,35 @@ +import flask +import flask_bootstrap +import redis +import os +import jinja2 + +app = flask.Flask(__name__) +flask_bootstrap.Bootstrap(app) +db = redis.StrictRedis(host='localhost', port=6379, db=0) + +app.jinja_loader = jinja2.ChoiceLoader([ + app.jinja_loader, + jinja2.FileSystemLoader("flavors"), +]) + + +def render_flavor(flavor, template, **context): + path = os.path.join(flavor, template) + return flask.render_template(path, **context) + + +@app.route("/") +def index(): + return flask.render_template('index.html') + + +@app.route("/setup", methods=["POST"]) +def setup(): + flavor = flask.request.form.get("flavor", "compose") + rendered = render_flavor(flavor, "setup.html") + return flask.render_template("setup.html", contents=rendered) + + +if __name__ == "__main__": + app.run(debug=True) diff --git a/config/templates/base.html b/config/templates/base.html new file mode 100644 index 00000000..bc52b3b6 --- /dev/null +++ b/config/templates/base.html @@ -0,0 +1,4 @@ +{% extends "bootstrap/base.html" %} +{% import "macros.html" as macros %} + +{% block title %}Mailu configuration{% endblock %} diff --git a/config/templates/index.html b/config/templates/index.html new file mode 100644 index 00000000..ff3a8800 --- /dev/null +++ b/config/templates/index.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block content %} +
+

Mailu configuration - {{ branch }}

+ + {% call macros.panel("warning", "Before starting, read the docs!") %} + Mailu is not perfectly documented, but still has a lot of documentation + available at mailu.io. Make sure you read + the appropriate documentation for your setup and have all the requirements + ready when using this wizard. + {% endcall %} + +
+ {% include "steps/flavor.html" %} + {% include "steps/expose.html" %} + + +
+ +
+{% endblock %} diff --git a/config/templates/macros.html b/config/templates/macros.html new file mode 100644 index 00000000..579800d2 --- /dev/null +++ b/config/templates/macros.html @@ -0,0 +1,22 @@ +{% macro panel(style, title) %} +
+
+

{{ title }}

+
+
+ {{ caller() }} +
+
+{% endmacro %} + +{% macro radio(name, value, emph, text) %} +
+ +
+{% endmacro %} diff --git a/config/templates/setup.html b/config/templates/setup.html new file mode 100644 index 00000000..fa1be8aa --- /dev/null +++ b/config/templates/setup.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block content %} +
+

Mailu configuration - {{ branch }}

+ + {% call macros.panel("success", "Your configuration was generated") %} +

The following steps will guide you towards downloading and using your + configuration files. Keep in mind that you should review every downloaded + file before running anything based on it.

+

If you encounter issues while setting Mailu up, please review the + documentation first, then check if an issue is open for that specific + problem. If not, you may either use Github to open an issue and detail what + your problem or bug looks like, or join us on Matrix and discuss it + with contributors.

+ {% endcall %} + + {% autoescape false %} + {{ contents }} + {% endautoescape %} + +
+{% endblock %} diff --git a/config/templates/steps/expose.html b/config/templates/steps/expose.html new file mode 100644 index 00000000..c712de63 --- /dev/null +++ b/config/templates/steps/expose.html @@ -0,0 +1,25 @@ +{% call macros.panel("info", "Step 2 - expose Mailu to the world") %} +

A mail server must be exposed to the world to receive emails, send emails, +and let users access their mailboxes. Mailu has some flexibility in the way +you expose it to the world.

+ +

Among Mailu services, the front server is the one accepting connections, +be it directly from the outside world, through a reverse proxy or in any +complex configuration that you might want to setup. It needs to listen on some +IP addresses in order to expose its public services. You must at least setup +an IPv4 or an IPv6 address if you wish to access Mailu.

+ +

Warning You must use specific addresses, please +avoid generic all-interfaces addresses like 0.0.0.0 or ::.

+ +
+ + +
+ +
+ + +
+ +{% endcall %} diff --git a/config/templates/steps/flavor.html b/config/templates/steps/flavor.html new file mode 100644 index 00000000..66da0757 --- /dev/null +++ b/config/templates/steps/flavor.html @@ -0,0 +1,16 @@ +{% call macros.panel("info", "Step 1 - pick a flavor") %} +

Mailu comes in multiple "flavors". It was originally +designed to run on top of Docker Compose but now offers multiple options +including Docker Stack, Rancher, Kubernetes.

+

Please note that "official" support, that is provided by the most active +developpers, will mostly cover Compose and Stack, while other flavors are +maintained by specific contributors.

+ +
+ {{ macros.radio("flavor", "compose", "Compose", "simply using Docker Compose manager") }} + {{ macros.radio("flavor", "stack", "Stack", "using stack deployments in a Swarm cluster") }} + {{ macros.radio("flavor", "rancher", "Rancher", "on top of the Rancher container manager") }} + {{ macros.radio("flavor", "kubernetes", "Kubernetes", "on top of the Kubernetes container manager") }} +
+ +{% endcall %}