Permalink
Browse files

First commit:

  * Add config files and template for Caddyfile
  * Add Makefile for Docker
  • Loading branch information...
CristianCantoro committed May 8, 2017
1 parent acc69ba commit 3c3b761fc03d124d42d42380c05fe29f9cd9cc55
Showing with 89 additions and 0 deletions.
  1. +19 −0 Makefile
  2. +1 −0 caddy/.gitignore
  3. 0 caddy/.gitkeep
  4. +5 −0 config/config.json
  5. +44 −0 config/configgen.py
  6. +20 −0 config/template.Caddyfile
@@ -0,0 +1,19 @@
all: mirror
mirror:
docker run --rm -d \
--name wikimirror \
-v "$(PWD)"/caddy/Caddyfile:/etc/Caddyfile \
-v "$(HOME)"/.caddy:/root/.caddy \
-p 80:80 -p 443:443 \
abiosoft/caddy
stop:
docker stop wikimirror
test:
docker run \
-v "$(PWD)"/caddy/Caddyfile:/etc/Caddyfile \
-v "$(HOME)"/.caddy:/root/.caddy \
-p 80:80 -p 443:443 \
abiosoft/caddy
@@ -0,0 +1 @@
Caddyfile
No changes.
@@ -0,0 +1,5 @@
{
"en": "Main_page",
"it": "Pagina_principale",
"tr": "Anasayfa"
}
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import json
import argparse
from string import Template
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("domain",
metavar='<domain>',
help="The domain name of the mirror")
parser.add_argument("-c", "--config",
default='config.json',
help="The configuration file [default: config.json]")
parser.add_argument("-t", "--template",
default='template.Caddyfile',
help="The configuration file template [default: template.Caddyfile]")
parser.add_argument("--tls",
help="The e-mail address for TLS certificates.")
parser.add_argument("-o", "--output",
default='../caddy/Caddyfile',
help="The name of the resulting Caddy config file [default: ../caddy/Caddyfile]")
args = parser.parse_args()
with open(args.config) as conf_file:
config = json.load(conf_file)
with open(args.template) as template_file:
template = Template(template_file.read())
with open(args.output, 'w') as outfile:
tls_string = ''
if args.tls is not None:
tls_string = 'tls {}'.format(args.tls)
for lang, main in config.items():
rendered = template.substitute(domain=args.domain,
tls=tls_string,
lang=lang,
main_page=main)
outfile.write(rendered)
@@ -0,0 +1,20 @@
${lang}.${domain} {
${tls}
redir {
if {uri} is /
/wiki/${main_page}
}
proxy / https://${lang}.wikipedia.org
}
${lang}.m.${domain} {
${tls}
redir {
if {uri} is /
/wiki/${main_page}
}
proxy / https://${lang}.m.wikipedia.org
}

0 comments on commit 3c3b761

Please sign in to comment.