8
setup/.env
Normal file
8
setup/.env
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Hostname passed to Traefik
|
||||||
|
ADDRESS=setup.mailu.io
|
||||||
|
|
||||||
|
# Current release
|
||||||
|
RELEASE=master
|
||||||
|
|
||||||
|
# Comma separated list of versions the user can choose.
|
||||||
|
VERSIONS=master
|
||||||
@@ -4,20 +4,15 @@ RUN mkdir -p /app
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
RUN apk add --no-cache git curl \
|
RUN apk add --no-cache curl \
|
||||||
&& pip install -r requirements.txt
|
&& pip install -r requirements.txt
|
||||||
|
|
||||||
COPY server.py ./server.py
|
COPY server.py ./server.py
|
||||||
COPY setup.py ./setup.py
|
|
||||||
COPY main.py ./main.py
|
COPY main.py ./main.py
|
||||||
COPY flavors /data/master/flavors
|
COPY flavors /data/flavors
|
||||||
COPY templates /data/master/templates
|
COPY templates /data/templates
|
||||||
COPY static ./static
|
COPY static ./static
|
||||||
|
|
||||||
#RUN python setup.py https://github.com/mailu/mailu /data
|
|
||||||
|
|
||||||
EXPOSE 80/tcp
|
EXPOSE 80/tcp
|
||||||
|
|
||||||
CMD gunicorn -w 4 -b :80 --access-logfile - --error-logfile - --preload main:app
|
CMD gunicorn -w 4 -b :80 --access-logfile - --error-logfile - --preload main:app
|
||||||
|
|
||||||
HEALTHCHECK CMD curl -f -L http://localhost/ || exit 1
|
|
||||||
|
|||||||
@@ -6,9 +6,37 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
image: redis:alpine
|
image: redis:alpine
|
||||||
|
|
||||||
setup:
|
setup_master:
|
||||||
image: ${DOCKER_ORG:-mailu}/${DOCKER_PREFIX}setup:${MAILU_VERSION:-master}
|
image: mailu/setup:master
|
||||||
ports:
|
networks:
|
||||||
- "8000:80"
|
- web
|
||||||
build: .
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
this_version: "master"
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.port=80
|
||||||
|
- traefik.main.frontend.rule=Host:${ADDRESS};PathPrefix:/master/
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
|
|
||||||
|
setup_release:
|
||||||
|
image: mailu/setup:${RELEASE}
|
||||||
|
networks:
|
||||||
|
- web
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
this_version: ${RELEASE}
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.port=80
|
||||||
|
- traefik.root.frontend.redirect.regex=.*
|
||||||
|
- traefik.root.frontend.redirect.replacement=/${RELEASE}/
|
||||||
|
- traefik.root.frontend.rule=Host:${ADDRESS};PathPrefix:/
|
||||||
|
- traefik.main.frontend.rule=Host:${ADDRESS};PathPrefix:/${RELEASE}/
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
|
|
||||||
|
networks:
|
||||||
|
web:
|
||||||
|
external: true
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ services:
|
|||||||
|
|
||||||
{% if resolver_enabled %}
|
{% if resolver_enabled %}
|
||||||
resolver:
|
resolver:
|
||||||
image: mailu/unbound:{{ version }}
|
image: ${DOCKER_ORG:-mailu}/unbound:${MAILU_VERSION:-{{ version }}}
|
||||||
env_file: {{ env }}
|
env_file: {{ env }}
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
@@ -56,7 +56,6 @@ services:
|
|||||||
imap:
|
imap:
|
||||||
image: ${DOCKER_ORG:-mailu}/dovecot:${MAILU_VERSION:-{{ version }}}
|
image: ${DOCKER_ORG:-mailu}/dovecot:${MAILU_VERSION:-{{ version }}}
|
||||||
env_file: {{ env }}
|
env_file: {{ env }}
|
||||||
environment:
|
|
||||||
volumes:
|
volumes:
|
||||||
- "{{ root }}/mail:/mail"
|
- "{{ root }}/mail:/mail"
|
||||||
- "{{ root }}/overrides:/overrides"
|
- "{{ root }}/overrides:/overrides"
|
||||||
@@ -130,7 +129,7 @@ services:
|
|||||||
|
|
||||||
{% if webmail_type != 'none' %}
|
{% if webmail_type != 'none' %}
|
||||||
webmail:
|
webmail:
|
||||||
image: ${DOCKER_ORG:-mailu}/roundcube:${MAILU_VERSION:-{{ version }}}
|
image: ${DOCKER_ORG:-mailu}/{{ webmail_type }}:${MAILU_VERSION:-{{ version }}}
|
||||||
env_file: {{ env }}
|
env_file: {{ env }}
|
||||||
volumes:
|
volumes:
|
||||||
- "{{ root }}/webmail:/data"
|
- "{{ root }}/webmail:/data"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
flask
|
flask
|
||||||
flask-bootstrap
|
flask-bootstrap
|
||||||
redis
|
redis
|
||||||
gitpython
|
|
||||||
gunicorn
|
gunicorn
|
||||||
|
|||||||
@@ -33,70 +33,60 @@ def secret(length=16):
|
|||||||
|
|
||||||
def build_app(path):
|
def build_app(path):
|
||||||
|
|
||||||
#Hardcoded master as the only version for test purposes
|
|
||||||
versions = [
|
|
||||||
# version for version in os.listdir(path)
|
|
||||||
# if os.path.isdir(os.path.join(path, version))
|
|
||||||
"master"
|
|
||||||
]
|
|
||||||
|
|
||||||
app.jinja_env.trim_blocks = True
|
app.jinja_env.trim_blocks = True
|
||||||
app.jinja_env.lstrip_blocks = True
|
app.jinja_env.lstrip_blocks = True
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def app_context():
|
def app_context():
|
||||||
return dict(versions=versions)
|
return dict(versions=os.getenv("VERSIONS","master").split(','))
|
||||||
|
|
||||||
@app.route("/")
|
version = os.getenv("this_version")
|
||||||
def index():
|
|
||||||
return flask.redirect(flask.url_for('{}.wizard'.format(versions[-1])))
|
|
||||||
|
|
||||||
for version in versions:
|
bp = flask.Blueprint(version, __name__)
|
||||||
bp = flask.Blueprint(version, __name__)
|
bp.jinja_loader = jinja2.ChoiceLoader([
|
||||||
bp.jinja_loader = jinja2.ChoiceLoader([
|
jinja2.FileSystemLoader(os.path.join(path, "templates")),
|
||||||
jinja2.FileSystemLoader(os.path.join(path, version, "templates")),
|
jinja2.FileSystemLoader(os.path.join(path, "flavors"))
|
||||||
jinja2.FileSystemLoader(os.path.join(path, version, "flavors"))
|
])
|
||||||
])
|
|
||||||
|
|
||||||
@bp.context_processor
|
@bp.context_processor
|
||||||
def bp_context(version=version):
|
def bp_context(version=version):
|
||||||
return dict(version=version)
|
return dict(version=version)
|
||||||
|
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
def wizard():
|
def wizard():
|
||||||
return flask.render_template('wizard.html')
|
return flask.render_template('wizard.html')
|
||||||
|
|
||||||
@bp.route("/submit_flavor", methods=["POST"])
|
@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(path + "/" + version + "/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"])
|
@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())
|
||||||
data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])
|
data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])
|
||||||
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"])
|
@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"])
|
@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")
|
||||||
return flask.Response(
|
return flask.Response(
|
||||||
render_flavor(flavor, filepath, data),
|
render_flavor(flavor, filepath, data),
|
||||||
mimetype="application/text"
|
mimetype="application/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
app.register_blueprint(bp, url_prefix="/{}".format(version))
|
app.register_blueprint(bp, url_prefix="/{}".format(version))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import git
|
|
||||||
import tempfile
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
VERSION_BRANCH = re.compile("(master|\d+\.\d+)")
|
|
||||||
|
|
||||||
|
|
||||||
def main(upstream, dest, dev=True):
|
|
||||||
shutil.rmtree(dest, ignore_errors=True)
|
|
||||||
os.makedirs(dest, exist_ok=True)
|
|
||||||
with tempfile.TemporaryDirectory() as clone_path:
|
|
||||||
repo = git.Repo.clone_from(upstream, clone_path)
|
|
||||||
for branch in repo.refs:
|
|
||||||
if not branch.name.startswith("origin/"):
|
|
||||||
continue
|
|
||||||
name = branch.name[len("origin/"):]
|
|
||||||
if not VERSION_BRANCH.match(name):
|
|
||||||
continue
|
|
||||||
branch.checkout()
|
|
||||||
config_path = os.path.join(clone_path, "setup")
|
|
||||||
if os.path.exists(config_path):
|
|
||||||
shutil.copytree(config_path, os.path.join(dest, name))
|
|
||||||
print("Imported branch {}".format(name))
|
|
||||||
if dev:
|
|
||||||
shutil.copytree(".", os.path.join(dest, "dev"))
|
|
||||||
print("Imported dev")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument("--dev", action="store_true", help="Copy the local dir in /dev")
|
|
||||||
parser.add_argument("upstream", help="Path to Mailu git repository")
|
|
||||||
parser.add_argument("dest", help="Destination directory for data files")
|
|
||||||
args = parser.parse_args()
|
|
||||||
main(**vars(args))
|
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
<p>
|
<p>
|
||||||
Version
|
Version
|
||||||
<select onchange="window.location.href=this.value;" class="btn btn-primary dropdown-toggle">
|
<select onchange="window.location.href=this.value;" class="btn btn-primary dropdown-toggle">
|
||||||
{% for available in versions %}
|
{% for module in versions %}
|
||||||
<option value="{{ url_for('{}.wizard'.format(available)) }}" {% if available == version %}selected{% endif %}>{{ available }}</option>
|
<option value="/{{ module }}" {% if module == version %}selected{% endif %}>{{ module }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user