From 946f2ac9589110ffc8bbe266f63031d4b0cafd02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 14 Aug 2020 03:59:21 +0200
Subject: [PATCH] software/theia: tasks to control embedded slapos

Introduce an easy way to run slapos commands in a more integrated way.
---
 software/theia/buildout.hash.cfg |  2 +-
 software/theia/instance.cfg.in   | 69 +++++++++++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/software/theia/buildout.hash.cfg b/software/theia/buildout.hash.cfg
index 318c78bbd..24a747ccf 100644
--- a/software/theia/buildout.hash.cfg
+++ b/software/theia/buildout.hash.cfg
@@ -15,7 +15,7 @@
 
 [instance]
 filename = instance.cfg.in
-md5sum = d8ad39bc93c492026a93c28b33a5dc3a
+md5sum = d6f7d1607641bee3543cebc04db73472
 
 [yarn.lock]
 filename = yarn.lock
diff --git a/software/theia/instance.cfg.in b/software/theia/instance.cfg.in
index f747d0d42..8609a63b5 100644
--- a/software/theia/instance.cfg.in
+++ b/software/theia/instance.cfg.in
@@ -3,6 +3,7 @@ parts =
   monitor-base
   promises
   frontend-reload
+  tasks.json
   publish-connection-parameter
 
 extends = ${monitor-template:rendered}
@@ -114,6 +115,69 @@ install =
 location = $${directory:frontend-static}/$${:filename}
 filename = $${:_buildout_section_name_}
 
+[tasks.json]
+recipe = slapos.recipe.template:jinja2
+rendered = $${directory:dot-theia}/tasks.json
+template =
+  inline:
+  {
+    // See https://go.microsoft.com/fwlink/?LinkId=733558
+    // for the documentation about the tasks.json format
+    "version": "2.0.0",
+    "tasks": [
+      {
+        "label": "slapos node software",
+        "detail": "Build all software supplied to the node",
+        "type": "shell",
+        "command": "${buildout:bin-directory}/slapos",
+        "args": [
+          "node",
+          "software",
+          // debug mode can be enabled by commenting out this line:
+          // "--buildout-debug",
+          "--all"
+        ],
+        "options": {
+          "env": {
+            "SLAPOS_CONFIGURATION": "$${slapos-standalone-activate:slapos-configuration}",
+            "GIT_EXEC_PATH": ""
+          }
+        },
+        "group": {
+          "kind": "build",
+          "isDefault": true
+        },
+        "problemMatcher": []
+      },
+      {
+        "label": "slapos node instance",
+        "detail": "Create all instances requested on the node",
+        "type": "shell",
+        "command": "${buildout:bin-directory}/slapos",
+        "args": [
+          "node",
+          "instance",
+          // debug mode can be enabled by commenting out this line:
+          // "--buildout-debug",
+          "--all"
+        ],
+        "options": {
+          "env": {
+            "SLAPOS_CONFIGURATION": "$${slapos-standalone-activate:slapos-configuration}",
+            "GIT_EXEC_PATH": ""
+          }
+        },
+        "problemMatcher": [],
+        "group": {
+          "kind": "build",
+          "isDefault": true
+        }
+      }
+    ]
+  }
+
+
+
 [user]
 recipe = slapos.cookbook:userinfo
 
@@ -163,13 +227,13 @@ template =
       $${slap-connection:partition-id} \
       --key='$${slap-connection:key-file}' \
       --cert='$${slap-connection:cert-file}'
-  export SLAPOS_CONFIGURATION=$${directory:slapos}/etc/slapos.cfg
+  export SLAPOS_CONFIGURATION=$${:slapos-configuration}
   export SLAPOS_CLIENT_CONFIGURATION=$SLAPOS_CONFIGURATION
 
 ipv4 = $${instance-parameter:ipv4-random}
 ipv6 = $${instance-parameter:ipv6-random}
 port = 4000
-
+slapos-configuration = $${directory:slapos}/etc/slapos.cfg
 
 [promises]
 recipe =
@@ -233,6 +297,7 @@ var = $${buildout:directory}/var
 srv = $${buildout:directory}/srv
 bin = $${buildout:directory}/bin
 tmp = $${buildout:directory}/tmp
+dot-theia = $${buildout:directory}/.theia/
 pidfiles = $${:var}/run
 
 services = $${:etc}/service
-- 
2.30.9