From 72be4717f92e8311f4540ac3184824c12fad7841 Mon Sep 17 00:00:00 2001
From: eteri <esokhoyan@gmail.com>
Date: Fri, 20 Oct 2017 08:03:10 +0000
Subject: [PATCH] caddy: improve configuration

---
 software/caddy/Caddyfile.in          |  6 +++-
 software/caddy/instance-caddy.cfg.in |  3 +-
 software/caddy/instance.cfg.in       | 53 +++++++++++++++-------------
 software/caddy/software.cfg          | 28 +++++++--------
 4 files changed, 48 insertions(+), 42 deletions(-)

diff --git a/software/caddy/Caddyfile.in b/software/caddy/Caddyfile.in
index 88522ecba..2789f4895 100644
--- a/software/caddy/Caddyfile.in
+++ b/software/caddy/Caddyfile.in
@@ -1 +1,5 @@
-$${caddy-configuration:ip}:$${caddy-configuration:port}
\ No newline at end of file
+[$${caddy-configuration:ip}]:$${caddy-configuration:port}
+
+log $${caddy-configuration:access_log}
+
+root  $${directory:public-html}
\ No newline at end of file
diff --git a/software/caddy/instance-caddy.cfg.in b/software/caddy/instance-caddy.cfg.in
index ba10bd827..1b8c16fe3 100644
--- a/software/caddy/instance-caddy.cfg.in
+++ b/software/caddy/instance-caddy.cfg.in
@@ -15,6 +15,7 @@ etc = $${buildout:directory}/etc
 bin = $${buildout:directory}/bin
 srv = $${buildout:directory}/srv
 var = $${buildout:directory}/var
+public-html =  $${buildout:directory}/public-html
 run = $${:var}/run
 log = $${:var}/log
 #www = $${:srv}/www
@@ -26,7 +27,7 @@ log = $${:var}/log
 [caddy-service]
 recipe = slapos.recipe.template
 url = ${template-caddy-service:output}
-output = $${directory:services}/caddy
+output = $${directory:srv}/caddy
 mode = 0700
 virtual-depends =
   $${caddy-configuration:ip}
diff --git a/software/caddy/instance.cfg.in b/software/caddy/instance.cfg.in
index 3f7a68539..36d0d0832 100644
--- a/software/caddy/instance.cfg.in
+++ b/software/caddy/instance.cfg.in
@@ -5,44 +5,47 @@
 #############################
 [buildout]
 parts =
-  directory
+  switch-softwaretype
+  
 #  publish-connection-parameter
 
 # Define egg directories to be the one from Software Release
 # (/opt/slapgrid/...)
 # Always the same.
-eggs-directory = {{ buildout['eggs-directory'] }}
-develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
+eggs-directory = ${buildout:eggs-directory}
+develop-eggs-directory = ${buildout:develop-eggs-directory}
 offline = true
 
+[switch-softwaretype]
+recipe = slapos.cookbook:softwaretype
+default = $${:caddy}
+caddy = $${dynamic-template-caddy:rendered}
+
+[dynamic-template-caddy]
+recipe = slapos.recipe.template:jinja2
+template = ${template-caddy:output}
+rendered = $${buildout:parts-directory}/${:_buildout_section_name_}/${:filename}
+filename = instance-caddy.cfg
+
+[slap-connection]
+computer-id = {slap_connection:computer_id}
+partition-id = $${slap_connection:partition_id}
+server-url = $${slap_connection:server_url}
+software-release-url = $${slap_connection:software_release_url}
+key-file = $${slap_connection:key_file}
+cert-file = $${slap_connection:cert_file}
 
 [instance-parameter]
 # Fetch arbitrary parameters defined by the user in SlapOS Master for his instance.
 # We use the slapconfiguration recipe with a few parameters (partition id,
 # computer id, certificate, etc).
 # It will then authenticate to SlapOS Master and fetch the instance parameters.
-# The parameters are accessible from ${instance-parameter:configuration.name-of-parameter}
+# The parameters are accessible from {instance-parameter:configuration.name-of-parameter}
 # Always the same. Just copy/paste.
 # See docstring of slapos.cookbook:slapconfiguration for more information.
 recipe = slapos.cookbook:slapconfiguration
-computer = ${slap_connection:computer_id}
-partition = ${slap_connection:partition_id}
-url = ${slap_connection:server_url}
-key = ${slap_connection:key_file}
-cert = ${slap_connection:cert_file}
-
-# Create all needed directories, depending on your needs
-[directory]
-recipe = slapos.cookbook:mkdirectory
-home = ${buildout:directory}
-etc = ${:home}/etc
-var = ${:home}/var
-# Executables put here will be started but not monitored (for startup scripts)
-script = ${:etc}/run/
-# Executables put here will be started and monitored (for daemons)
-service = ${:etc}/service
-# Executables put here will be launched after buildout has completed to see
-# if instance is running
-promise = ${:etc}/promise/
-# Path of the log directory used by our service (see [helloweb])
-log = ${:var}/log
\ No newline at end of file
+computer = $${slap_connection:computer_id}
+partition = $${slap_connection:partition_id}
+url = $${slap_connection:server_url}
+key = $${slap_connection:key_file}
+cert = $${slap_connection:cert_file}
diff --git a/software/caddy/software.cfg b/software/caddy/software.cfg
index 723eca286..fc5bf79c0 100644
--- a/software/caddy/software.cfg
+++ b/software/caddy/software.cfg
@@ -13,15 +13,12 @@ parts =
   caddy
 
 [instance-profile]
-recipe = slapos.recipe.template:jinja2
-template = ${:_profile_base_location_}/instance.cfg.in
-rendered = ${buildout:directory}/instance.cfg
-# MD5 checksum can be skipped for development (easier to develop), but must be filled for production
-md5sum = ec3f3d81153f7b198ccf30c5a5bf532a
+recipe = slapos.recipe.template
+url = ${:_profile_base_location_}/instance.cfg.in
+md5sum = ae83c35995ce14432ded78ca30cab61b
+output =${buildout:directory}/instance.cfg
+filename = instance.cfg
 mode = 0644
-extensions = jinja2.ext.do
-context =
-  section buildout  buildout
 
 [gopath]
 directory = ${buildout:directory}/go.work
@@ -35,19 +32,20 @@ md5sum = 61da5aea191595962ab020b4197b5390
 output = ${buildout:directory}/template-caddy-service.sh.in
 mode = 0644
 
+[template-Caddyfile]
+recipe = slapos.recipe.template
+url = ${:_profile_base_location_}/Caddyfile.in
+md5sum = c3ad1c9ea830dab84fa18bd58b5dc2ed
+output = ${buildout:directory}/Caddyfile.in
+mode = 0644
+
 [template-caddy]
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/instance-caddy.cfg.in
-md5sum = 06ae4dccd5c8557ddb51be8adbb1d6c0
+md5sum = 3c9c4ef2963a57e5a68188f00a5938b9
 output = ${buildout:directory}/instance-caddy.cfg.in
 mode = 0644
 
-[template-Caddyfile]
-recipe = slapos.recipe.template
-url = ${:_profile_base_location_}/Caddyfile.in
-md5sum = 0bc8e72f2748e22446f850f157321a8c
-output = ${buildout:directory}/Caddyfile.in
-mode = 0644
 
 [caddy]
 recipe  = slapos.recipe.cmmi
-- 
2.30.9