Commit 66742874 authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Use jinja2 to generate caddy-wrapper

As infromation passed to caddy-wrapper comes also from the network it
has to be templated using jinja2 in order to dump variables correctly.
parent 1730555b
...@@ -19,7 +19,7 @@ md5sum = f686f765e55d1dce2e55a400f0714b3e ...@@ -19,7 +19,7 @@ md5sum = f686f765e55d1dce2e55a400f0714b3e
[template-apache-frontend] [template-apache-frontend]
filename = instance-apache-frontend.cfg filename = instance-apache-frontend.cfg
md5sum = 0f9d764e1c4c5e345cdb90390c9d90b6 md5sum = 6a2a0ada0bf281a725712b9c29a12b34
[template-apache-replicate] [template-apache-replicate]
filename = instance-apache-replicate.cfg.in filename = instance-apache-replicate.cfg.in
...@@ -73,6 +73,10 @@ md5sum = c2314c3a9c3412a38d14b312d3df83c1 ...@@ -73,6 +73,10 @@ md5sum = c2314c3a9c3412a38d14b312d3df83c1
filename = templates/wrapper.in filename = templates/wrapper.in
md5sum = 8cde04bfd0c0e9bd56744b988275cfd8 md5sum = 8cde04bfd0c0e9bd56744b988275cfd8
[template-caddy-wrapper]
filename = templates/caddy-wrapper.in
md5sum = 30921eb4be1dc867f9f6749688e6098a
[template-trafficserver-records-config] [template-trafficserver-records-config]
filename = templates/trafficserver/records.config.jinja2 filename = templates/trafficserver/records.config.jinja2
md5sum = 84baef0a49c9a65e8f2d2ffdb8c1d39c md5sum = 84baef0a49c9a65e8f2d2ffdb8c1d39c
......
...@@ -100,6 +100,12 @@ filename = template-log-access.conf.in ...@@ -100,6 +100,12 @@ filename = template-log-access.conf.in
<=download-template <=download-template
filename = empty.in filename = empty.in
[template-caddy-wrapper]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/caddy-wrapper.in
output = ${buildout:directory}/template-caddy-wrapper.cfg
mode = 0644
[template-wrapper] [template-wrapper]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/templates/wrapper.in url = ${:_profile_base_location_}/templates/wrapper.in
......
...@@ -250,24 +250,26 @@ extra-context = ...@@ -250,24 +250,26 @@ extra-context =
section frontend_configuration frontend-configuration section frontend_configuration frontend-configuration
[caddy-wrapper] [caddy-wrapper]
recipe = slapos.cookbook:wrapper < = jinja2-template-base
command-line = ${caddy:output} template = ${template-caddy-wrapper:output}
-conf $${dynamic-apache-frontend-template:rendered} rendered = $${directory:bin}/caddy-wrapper
-root $${caddy-directory:document-root} mode = 0700
-host $${instance-parameter:configuration.domain} extra-context =
-http-port $${instance-parameter:configuration.plain_http_port} raw caddy ${caddy:output}
-https-port $${instance-parameter:configuration.port} key conf dynamic-apache-frontend-template:rendered
-log $${apache-configuration:error-log} key root caddy-directory:document-root
-http2=$${instance-parameter:configuration.enable-http2-by-default} key host instance-parameter:configuration.domain
-grace $${instance-parameter:configuration.mpm-graceful-shutdown-timeout}s key http_port instance-parameter:configuration.plain_http_port
-pidfile $${apache-configuration:pid-file} key https_port instance-parameter:configuration.port
-disable-http-challenge key content apache-configuration:frontend-graceful-command
-disable-tls-sni-challenge key log apache-configuration:error-log
wrapper-path = $${directory:bin}/caddy-wrapper key http2 instance-parameter:configuration.enable-http2-by-default
key grace instance-parameter:configuration.mpm-graceful-shutdown-timeout
key pidfile apache-configuration:pid-file
[apache-frontend] [apache-frontend]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
command-line = $${caddy-wrapper:wrapper-path} command-line = $${caddy-wrapper:rendered}
wrapper-path = $${directory:service}/frontend_caddy wrapper-path = $${directory:service}/frontend_caddy
wait-for-files = wait-for-files =
$${ca-frontend:cert-file} $${ca-frontend:cert-file}
...@@ -297,7 +299,7 @@ error-log = $${directory:log}/frontend-apache-error.log ...@@ -297,7 +299,7 @@ error-log = $${directory:log}/frontend-apache-error.log
pid-file = $${directory:run}/httpd.pid pid-file = $${directory:run}/httpd.pid
protected-path = / protected-path = /
access-control-string = none access-control-string = none
frontend-configuration-verification = $${caddy-wrapper:wrapper-path} -validate > /dev/null frontend-configuration-verification = $${caddy-wrapper:rendered} -validate > /dev/null
frontend-graceful-command = $${:frontend-configuration-verification}; if [ $? -eq 0 ]; then kill -USR1 $(cat $${:pid-file}); fi frontend-graceful-command = $${:frontend-configuration-verification}; if [ $? -eq 0 ]; then kill -USR1 $(cat $${:pid-file}); fi
# Comunication with ats # Comunication with ats
...@@ -308,7 +310,7 @@ ssl-cache-through-port = 26012 ...@@ -308,7 +310,7 @@ ssl-cache-through-port = 26012
# Create wrapper for "apachectl conftest" in bin # Create wrapper for "apachectl conftest" in bin
[configtest] [configtest]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
command-line = $${caddy-wrapper:wrapper-path} -validate command-line = $${caddy-wrapper:rendered} -validate
wrapper-path = $${directory:bin}/caddy-configtest wrapper-path = $${directory:bin}/caddy-configtest
[certificate-authority] [certificate-authority]
...@@ -697,19 +699,21 @@ curl_path = ${curl:location}/bin/curl ...@@ -697,19 +699,21 @@ curl_path = ${curl:location}/bin/curl
# Nginx # Nginx
# #
[nginx-frontend] [nginx-frontend]
recipe = slapos.cookbook:wrapper < = jinja2-template-base
command-line = ${caddy:output} template = ${template-caddy-wrapper:output}
-conf $${nginx-configuration:output} rendered = $${directory:service}/frontend_nginx
-host $${instance-parameter:configuration.domain} mode = 0700
-root $${caddy-directory:document-root} extra-context =
-http-port $${nginx-configuration:plain_port} raw caddy ${caddy:output}
-https-port $${nginx-configuration:port} key conf nginx-configuration:output
-log $${nginx-configuration:error_log} key root caddy-directory:document-root
-http2=$${instance-parameter:configuration.enable-http2-by-default} key host instance-parameter:configuration.domain
-pidfile $${nginx-configuration:pid-file} key http_port nginx-configuration:plain_port
-disable-http-challenge key https_port nginx-configuration:port
-disable-tls-sni-challenge key log nginx-configuration:error_log
wrapper-path = $${directory:service}/frontend_nginx key http2 instance-parameter:configuration.enable-http2-by-default
key grace instance-parameter:configuration.mpm-graceful-shutdown-timeout
key pidfile nginx-configuration:pid-file
[nginx-configuration] [nginx-configuration]
recipe = slapos.recipe.template recipe = slapos.recipe.template
...@@ -727,7 +731,7 @@ worker_connections = 1024 ...@@ -727,7 +731,7 @@ worker_connections = 1024
slave-configuration-directory = $${caddy-directory:nginx-slave-configuration} slave-configuration-directory = $${caddy-directory:nginx-slave-configuration}
pid-file = $${directory:run}/nginx.pid pid-file = $${directory:run}/nginx.pid
nginx-graceful-command = $${:nginx-configuration-verification}; if [ $? -eq 0 ]; then kill -HUP $(cat $${:pid-file}); fi nginx-graceful-command = $${:nginx-configuration-verification}; if [ $? -eq 0 ]; then kill -HUP $(cat $${:pid-file}); fi
nginx-configuration-verification = $${nginx-frontend:wrapper-path} -validate nginx-configuration-verification = $${nginx-frontend:rendered} -validate
ssl_certificate = $${ca-frontend:cert-file} ssl_certificate = $${ca-frontend:cert-file}
ssl_key = $${ca-frontend:key-file} ssl_key = $${ca-frontend:key-file}
......
#!${dash-output:dash}
exec {{ caddy }} \
-conf {{ conf }} \
-root {{ root }} \
-host {{ host }} \
-http-port {{ http_port }} \
-https-port {{ https_port }} \
-log {{ log }} \
-http2={{ http2 }} \
-grace {{ grace }}s \
-pidfile {{ pidfile }} \
-disable-http-challenge \
-disable-tls-sni-challenge \
"$@"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment