From 227b3a70f4865fcd9f54d776c1a7105f84815aa9 Mon Sep 17 00:00:00 2001
From: Boxiang Sun <boxiang.sun@nexedi.com>
Date: Wed, 5 Oct 2022 09:55:05 +0200
Subject: [PATCH] software/peertube: fixup

---
 software/peertube/instance.cfg.in | 34 +++++++++++++++++++++++--------
 software/peertube/software.cfg    | 18 +++++++++++++---
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/software/peertube/instance.cfg.in b/software/peertube/instance.cfg.in
index d63ba935e..58706ff24 100644
--- a/software/peertube/instance.cfg.in
+++ b/software/peertube/instance.cfg.in
@@ -3,7 +3,8 @@ extends =
   ${monitor-template:output}
 
 parts =
-  peertube-instance
+  postgresql
+  postgresql-extension
   nginx-service
   nginx-listen-promise
 
@@ -30,8 +31,8 @@ ssl = $${:etc}/ssl
 [peertube-instance]
 recipe = slapos.cookbook:wrapper
 wrapper-path = $${directory:services}/$${:_buildout_section_name_}
-command-line = cd $${directory:versions} && cp -r ${peertube-download:location} ./
-#  echo "Hello!"
+command-line = echo "Hello!"
+# Change config/production.yaml
 #  ehco $${directory:versions}
 environment =
   PATH=${unzip:location}/bin:${vim:location}/bin:${nodejs:location}/bin:${yarn:location}/bin:${python3:location}/bin:${nginx:location}/sbin:${postgresql:location}/sbin:${gcc-10.2:location}/bin:${redis:location}/bin:{git:location}/bin:{wget:location}/bin:%(PATH)s
@@ -40,7 +41,6 @@ environment =
 
 [postgresql-password]
 recipe = slapos.cookbook:generate.password
-bytes = 24
 
 [postgresql]
 recipe = slapos.cookbook:postgres
@@ -63,6 +63,11 @@ command-line =
     $${postgresql:bin}/psql -c "CREATE EXTENSION pg_trgm;" $${postgresql:dbname}
     $${postgresql:bin}/psql -c "CREATE EXTENSION unaccent;" $${postgresql:dbname}
 
+[service-postgresql]
+recipe  = slapos.cookbook:postgres
+bin     = {{ postgresql_location }}/bin
+services= ${directory:service}
+
 #################################
 # Nginx service
 #################################
@@ -75,10 +80,11 @@ virtual-depends =
 
 [nginx-listen-promise]
 <= monitor-promise-base
-promise = check_socket_listening
+promise = check_url_available
 name = nginx_listen.py
-config-host = $${nginx-configuration:ip}
+config-host = [$${nginx-configuration:ip}]
 config-port = $${nginx-configuration:port}
+config-url = https://$${:config-host}/$${:config-port}
 
 [nginx-configuration]
 recipe = slapos.recipe.template
@@ -86,12 +92,24 @@ url = ${template-nginx-configuration:output}
 output = $${directory:etc}/nginx.cfg
 access_log = $${directory:log}/nginx-access.log
 error_log = $${directory:log}/nginx-error.log
-ip = {{ partition_ipv6 }}
+ip = $${instance-parameter:ipv6-random}
 port = 9443
 ssl_key = $${directory:ssl}/nginx.key
 ssl_csr = $${directory:ssl}/nginx.csr
 ssl_crt = $${directory:ssl}/nginx.crt
 
+#################################
+# SlapOS service
+#################################
+[instance-parameter]
+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}
+configuration._ = {}
+
 [publish-connection-parameter]
 recipe = slapos.cookbook:publish
-url = $${peertube-instance:url}
+# url = $${peertube-instance:url}
diff --git a/software/peertube/software.cfg b/software/peertube/software.cfg
index 06422469d..4e2a514e2 100644
--- a/software/peertube/software.cfg
+++ b/software/peertube/software.cfg
@@ -50,19 +50,31 @@ parts =
   git
   wget
 # peetube sections
-  peertube-download
+  peertube
+  peertube-build
   instance-profile
 # postgresql-setup
 
 [nodejs]
 <= nodejs-16.13.2
 
-[peertube-download]
+[peertube]
 recipe = slapos.recipe.build:download-unpacked
 url = https://github.com/Chocobozzz/PeerTube/releases/download/v4.2.2/peertube-v4.2.2.zip
-# destination = ${directory:versions}
 # md5sum =
 
+[peertube-build]
+recipe = slapos.recipe.cmmi
+path = ${peertube:location}
+environment =
+  PATH=${unzip:location}/bin:${vim:location}/bin:${nodejs:location}/bin:${yarn:location}/bin:${python3:location}/bin:${nginx:location}/sbin:${postgresql:location}/sbin:${gcc-10.2:location}/bin:${redis:location}/bin:{git:location}/bin:{wget:location}/bin:%(PATH)s
+  CPPFLAGS=-I${openssl:location}/include
+  LDFLAGS=-L${curl:location}/lib -Wl,-rpath -Wl,${openssl:location}/lib -Wl,-rpath -Wl
+pre-configure =
+  ${yarn:location}/bin/yarn install --production --pure-lockfile
+configure-command = true
+make-binary = cd %(location)s && ${yarn:location}/bin/yarn
+
 [instance-profile]
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/${:filename}
-- 
2.30.9