From 7ac04ba079dec2df220ef08b903065fe9ea116e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 2 Aug 2021 09:39:05 +0200
Subject: [PATCH] software/nginx-push-stream: drop switch-softwaretype

For a simple software with only one software type like this one, using a
recipe like switch-softwaretype is not necessary.
---
 software/nginx-push-stream/buildout.hash.cfg  |  6 +-
 .../nginx-push-stream/instance-nginx.cfg.in   | 78 -----------------
 software/nginx-push-stream/instance.cfg.in    | 85 ++++++++++++++++---
 software/nginx-push-stream/software.cfg       |  7 --
 4 files changed, 74 insertions(+), 102 deletions(-)
 delete mode 100644 software/nginx-push-stream/instance-nginx.cfg.in

diff --git a/software/nginx-push-stream/buildout.hash.cfg b/software/nginx-push-stream/buildout.hash.cfg
index 9d0452528..011bf4393 100644
--- a/software/nginx-push-stream/buildout.hash.cfg
+++ b/software/nginx-push-stream/buildout.hash.cfg
@@ -1,11 +1,7 @@
 [template]
 filename = instance.cfg.in
-md5sum = 509605f8222f92aa62b6cb4a078a78df
+md5sum = f9b6d01e29f2edddd9d6f99591976c33
 
 [template-nginx-configuration]
 filename = template-nginx.cfg.in
 md5sum = 022e4b53e1b2db16c4e518fe76f638fa
-
-[template-nginx]
-filename = instance-nginx.cfg.in
-md5sum = 198bd472438989397bbf350f8361d316
diff --git a/software/nginx-push-stream/instance-nginx.cfg.in b/software/nginx-push-stream/instance-nginx.cfg.in
deleted file mode 100644
index 1c1d5a28a..000000000
--- a/software/nginx-push-stream/instance-nginx.cfg.in
+++ /dev/null
@@ -1,78 +0,0 @@
-[buildout]
-parts =
-  nginx-service
-  promises
-  publish-connection-information
-
-extends = ${monitor-template:rendered}
-
-
-[directory]
-recipe = slapos.cookbook:mkdirectory
-etc = $${buildout:directory}/etc
-bin = $${buildout:directory}/bin
-srv = $${buildout:directory}/srv
-var = $${buildout:directory}/var
-run = $${:var}/run
-log = $${:var}/log
-varnginx = $${:var}/nginx
-services = $${:etc}/service
-cron-entries = $${:etc}/cron.d
-www = $${:srv}/www
-ssl = $${:etc}/ssl
-
-#################################
-# Nginx service
-#################################
-[nginx-service]
-recipe = slapos.cookbook:wrapper
-wrapper-path = $${directory:services}/nginx
-command-line =
-  ${nginx-push-stream-output:nginx} -c $${nginx-configuration:output}
-
-[nginx-configuration]
-recipe = slapos.recipe.template
-url = ${template-nginx-configuration:output}
-output = $${directory:etc}/nginx.cfg
-mode = 0600
-access-log = $${directory:log}/nginx-access.log
-error-log = $${directory:log}/nginx-error.log
-ip = $${slap-configuration:ipv6-random}
-local-ip = $${slap-configuration:ipv4-random}
-port = 9443
-base-url = https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}
-
-# Generate a self-signed TLS certificate.
-[nginx-certificate]
-recipe = plone.recipe.command
-command =
-  if [ ! -e $${:key-file} ]
-  then
-    ${openssl:location}/bin/openssl req -x509 -nodes -days 3650 \
-      -subj "/C=AA/ST=X/L=X/O=Dis/CN=$${nginx-configuration:ip}" \
-      -newkey rsa:1024 -keyout $${:key-file} \
-      -out $${:cert-file}
-  fi
-update-command = $${:command}
-key-file = $${directory:ssl}/${:_buildout_section_name_}.key
-cert-file = $${directory:ssl}/${:_buildout_section_name_}.cert
-common-name = $${nginx-configuration:ip}
-stop-on-error = true
-
-[promises]
-recipe =
-promises =
-  $${nginx-available-promise:recipe}
-
-[nginx-available-promise]
-<= monitor-promise-base
-module = check_url_available
-name = $${:_buildout_section_name_}.py
-config-url = $${nginx-configuration:base-url}/status
-
-[publish-connection-information]
-recipe = slapos.cookbook:publish
-# publisher-url and subscriber-url are URITemplates, with an id
-# parameter which is the ID of the channel.
-publisher-url = $${nginx-configuration:base-url}/pub{?id}
-subscriber-url = $${nginx-configuration:base-url}/sub{/id}
diff --git a/software/nginx-push-stream/instance.cfg.in b/software/nginx-push-stream/instance.cfg.in
index 4fc12e5ca..c4f7c632b 100644
--- a/software/nginx-push-stream/instance.cfg.in
+++ b/software/nginx-push-stream/instance.cfg.in
@@ -1,21 +1,26 @@
 [buildout]
 parts =
-  switch-softwaretype
-
+  nginx-service
+  promises
+  publish-connection-information
+extends = ${monitor-template:rendered}
 eggs-directory = ${buildout:eggs-directory}
 develop-eggs-directory = ${buildout:develop-eggs-directory}
 offline = true
 
-[switch-softwaretype]
-recipe = slapos.cookbook:switch-softwaretype
-default = dynamic-template-nginx:rendered
-RootSoftwareInstance = $${:default}
-
-[dynamic-template-nginx]
-recipe = slapos.recipe.template:jinja2
-template = ${template-nginx:output}
-rendered = $${buildout:parts-directory}/$${:_buildout_section_name_}/$${:filename}
-filename = instance-nginx.cfg
+[directory]
+recipe = slapos.cookbook:mkdirectory
+etc = $${buildout:directory}/etc
+bin = $${buildout:directory}/bin
+srv = $${buildout:directory}/srv
+var = $${buildout:directory}/var
+run = $${:var}/run
+log = $${:var}/log
+varnginx = $${:var}/nginx
+services = $${:etc}/service
+cron-entries = $${:etc}/cron.d
+www = $${:srv}/www
+ssl = $${:etc}/ssl
 
 [slap-configuration]
 recipe = slapos.cookbook:slapconfiguration
@@ -24,3 +29,59 @@ partition = $${slap-connection:partition-id}
 url = $${slap-connection:server-url}
 key = $${slap-connection:key-file}
 cert = $${slap-connection:cert-file}
+
+#################################
+# Nginx service
+#################################
+[nginx-service]
+recipe = slapos.cookbook:wrapper
+wrapper-path = $${directory:services}/nginx
+command-line =
+  ${nginx-push-stream-output:nginx} -c $${nginx-configuration:output}
+
+[nginx-configuration]
+recipe = slapos.recipe.template
+url = ${template-nginx-configuration:output}
+output = $${directory:etc}/nginx.cfg
+mode = 0600
+access-log = $${directory:log}/nginx-access.log
+error-log = $${directory:log}/nginx-error.log
+ip = $${slap-configuration:ipv6-random}
+local-ip = $${slap-configuration:ipv4-random}
+port = 9443
+base-url = https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}
+
+# Generate a self-signed TLS certificate.
+[nginx-certificate]
+recipe = plone.recipe.command
+command =
+  if [ ! -e $${:key-file} ]
+  then
+    ${openssl:location}/bin/openssl req -x509 -nodes -days 3650 \
+      -subj "/C=AA/ST=X/L=X/O=Dis/CN=$${nginx-configuration:ip}" \
+      -newkey rsa:1024 -keyout $${:key-file} \
+      -out $${:cert-file}
+  fi
+update-command = $${:command}
+key-file = $${directory:ssl}/${:_buildout_section_name_}.key
+cert-file = $${directory:ssl}/${:_buildout_section_name_}.cert
+common-name = $${nginx-configuration:ip}
+stop-on-error = true
+
+[promises]
+recipe =
+promises =
+  $${nginx-available-promise:recipe}
+
+[nginx-available-promise]
+<= monitor-promise-base
+module = check_url_available
+name = $${:_buildout_section_name_}.py
+config-url = $${nginx-configuration:base-url}/status
+
+[publish-connection-information]
+recipe = slapos.cookbook:publish
+# publisher-url and subscriber-url are URITemplates, with an id
+# parameter which is the ID of the channel.
+publisher-url = $${nginx-configuration:base-url}/pub{?id}
+subscriber-url = $${nginx-configuration:base-url}/sub{/id}
diff --git a/software/nginx-push-stream/software.cfg b/software/nginx-push-stream/software.cfg
index 65c32eaa6..a6719c743 100644
--- a/software/nginx-push-stream/software.cfg
+++ b/software/nginx-push-stream/software.cfg
@@ -11,7 +11,6 @@ parts =
   nginx-push-stream-module
   nginx-push-stream
   template
-  template-nginx
 
 [python]
 part = python3
@@ -27,9 +26,3 @@ recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/${:filename}
 output = ${buildout:directory}/template-nginx.cfg.in
 mode = 0644
-
-[template-nginx]
-recipe = slapos.recipe.template
-url = ${:_profile_base_location_}//${:filename}
-output = ${buildout:directory}/instance-nginx.cfg.in
-mode = 0644
-- 
2.30.9