instance.cfg.in 16.9 KB
Newer Older
1
[buildout]
2 3 4 5
extends =
  ${monitor-template:rendered}

theia-environment-parts =
6
  tasks.json
7
  slapos-repository
8
  runner-link
9
  settings.json
10
  request-script
11

12 13 14 15 16 17 18 19 20
theia-parts =
  frontend-reload
  promises

parts =
  monitor-base
  $${:theia-parts}
  $${:theia-environment-parts}
  publish-connection-parameter
21

22
eggs-directory = ${buildout:eggs-directory}
23
develop-eggs-directory = ${buildout:develop-eggs-directory}
24 25 26
offline = true


27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
[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.autorun = running
configuration.embedded-sr =
configuration.embedded-sr-type =


[publish-connection-parameter]
<= monitor-publish
recipe = slapos.cookbook:publish
url = $${apache-frontend:connection-secure_access}
username = $${frontend-instance-password:username}
password = $${frontend-instance-password:passwd}
45
backend-url = $${frontend-instance:url}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138


[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
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
runner = $${:srv}/runner
project = $${:srv}/project
frontend-static = $${:srv}/frontend-static
frontend-static-public = $${:frontend-static}/public
frontend-static-css = $${:frontend-static}/css

bash-completions = $${buildout:directory}/.local/share/bash-completion/completions/
fish-completions = $${buildout:directory}/.config/fish/completions/


# Promises
# --------

[promises]
recipe =
instance-promises =
  $${theia-listen-promise:name}
  $${frontend-listen-promise:name}
  $${apache-frontend-url-available-promise:name}
  $${slapos-standalone-listen-promise:name}
  $${slapos-autorun-promise:name}

[theia-listen-promise]
<= monitor-promise-base
module = check_port_listening
name = $${:_buildout_section_name_}.py
config-hostname = $${theia-instance:ip}
config-port = $${theia-instance:port}

[frontend-listen-promise]
<= monitor-promise-base
module = check_port_listening
name = $${:_buildout_section_name_}.py
config-hostname = $${frontend-instance:ip}
config-port = $${frontend-instance:port}

[apache-frontend-url-available-promise]
<= monitor-promise-base
module = check_url_available
name = $${:_buildout_section_name_}.py
config-url = $${apache-frontend:connection-secure_access}
config-check-secure = 1

[slapos-standalone-listen-promise]
<= monitor-promise-base
module = check_port_listening
# XXX promise plugins can not contain "slapos" in their names
name = standalone-listen-promise.py
config-hostname = $${slapos-standalone-instance:hostname}
config-port = $${slapos-standalone-instance:port}

[slapos-autorun-promise]
<= monitor-promise-base
module = check_service_state
# XXX promise plugins can not contain "slapos" in their names
name = autorun-state-promise.py
config-service = $${slapos-autorun:service-name}
config-expect = $${slapos-autorun:autorun}


# Remote Apache Frontend
# ----------------------

[apache-frontend]
<= slap-connection
recipe = slapos.cookbook:requestoptional
name = Theia Frontend
# XXX We have hardcoded SR URL here.
software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
slave = true
config-url = $${frontend-instance:url}
config-https-only = true
config-type = websocket
config-websocket-path-list = /services /file-upload
return = domain secure_access


# Local Caddy Frontend
# --------------------

139 140
[frontend-instance-password]
recipe = slapos.cookbook:generate.password
141
username = admin
142 143
bytes = 12

144 145 146 147 148 149
[frontend-instance-port]
recipe = slapos.cookbook:free_port
minimum = 3000
maximum = 3100
ip = $${instance-parameter:ipv6-random}

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
[frontend-instance-certificate]
recipe = plone.recipe.command
command =
  if [ ! -e $${:key-file} ]
  then
    ${openssl-output:openssl} req -x509 -nodes -days 3650 \
      -subj "/C=AA/ST=X/L=X/O=Dis/CN=$${:common-name}" \
      -newkey rsa:1024 -keyout $${:key-file} \
      -out $${:cert-file}
  fi
update-command = $${:command}
key-file = $${directory:etc}/$${:_buildout_section_name_}.key
cert-file = $${directory:etc}/$${:_buildout_section_name_}.crt
common-name = $${frontend-instance-config:ip}
location =
  $${:key-file}
  $${:cert-file}

168 169 170
[frontend-instance-config]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}
171 172
template =
  inline:
173
  :$${:port} {
174
    bind $${:ip}
175
    tls $${frontend-instance-certificate:cert-file} $${frontend-instance-certificate:key-file}
176 177 178 179 180 181 182 183
    log stdout
    errors stderr
    gzip
    # because caddy does not support upgrade http2 to websocket
    # https://tools.ietf.org/html/rfc8441
    tls {
      alpn http/1.1
    }
184 185
    root $${directory:frontend-static}
    browse
186
    proxy / $${theia-instance:base-url} {
187
      except $${frontend-instance-fonts:folder-name} $${frontend-instance-slapos.css:folder-name} public $${favicon.ico:filename} $${frontend-instance-logo:filename}
188 189 190 191
    }
    proxy /services $${theia-instance:base-url} {
      websocket
    }
192 193 194
    proxy /file-upload $${theia-instance:base-url} {
      websocket
    }
195 196 197 198 199
    basicauth $${frontend-instance-password:username} $${frontend-instance-password:passwd} {
      realm "Theia"
      /
    }
  }
200
ip = $${frontend-instance-port:ip}
201
hostname = [$${:ip}]
202
port = $${frontend-instance-port:port}
203 204 205 206 207 208 209 210 211 212 213

[frontend-instance]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:services}/$${:_buildout_section_name_}
command-line =
  ${caddy:output} -conf $${frontend-instance-config:rendered} -pidfile $${:pidfile}

ip = $${frontend-instance-config:ip}
hostname = $${frontend-instance-config:hostname}
port = $${frontend-instance-config:port}
pidfile = $${directory:pidfiles}/$${:_buildout_section_name_}.pid
214
url = https://$${:hostname}:$${:port}/
215

216 217 218 219 220 221 222
[frontend-instance-fonts]
; XXX caddy 1 does not seem to serve different folders at different locations
; so we link fonts in static folder
recipe = plone.recipe.command
location = $${directory:frontend-static}/$${:folder-name}
folder-name = fonts
command =
223 224 225
  mkdir -p $${:location}
  ln -sf ${source-code-pro-fonts:location} $${:location}/source-code-pro
  ln -sf ${jetbrains-mono-fonts:location} $${:location}/jetbrains-mono
226 227
stop-on-error = true

228 229 230
[frontend-instance-logo]
recipe = plone.recipe.command
filename = logo.png
231
full-path = $${directory:frontend-static}/$${:filename}
232
command =
233
  cp -f ${logo.png:output} $${:full-path}
234 235
stop-on-error = true

236 237 238 239 240
[frontend-instance-slapos.css]
recipe = slapos.recipe.template:jinja2
template = ${slapos.css.in:output}
rendered = $${directory:frontend-static}/$${:folder-name}/slapos.css
folder-name = css
241 242
context =
  key logo_image frontend-instance-logo:filename
243

244 245 246 247 248 249 250 251 252 253 254 255
[frontend-reload]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:services}/$${:_buildout_section_name_}
command-line =
  ${bash:location}/bin/bash -c
  "kill -s USR1 $$(${coreutils:location}/bin/cat $${frontend-instance:pidfile}) \
    && ${coreutils:location}/bin/sleep infinity"
hash-files =
  $${frontend-instance-config:rendered}
  $${frontend-instance:wrapper-path}
wait-for-files = $${frontend-instance:pidfile}

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
[favicon.ico]
# generate a pseudo random favicon, different for each instance name.
recipe = slapos.recipe.build
install =
  import hashlib, shutil
  buildout_offline = self.buildout['buildout']['offline']
  self.buildout['buildout']['offline'] = 'false'
  try:
    gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(
      '''$${slap-configuration:root-instance-title}'''
    ).hexdigest() + "?s=256&d=retro"
    shutil.copy(self.download(gravatar_url), '''$${:location}''')
  except Exception:
    # Because installation should work offline, if we can't download a favicon,
    # just ignore this step.
    self.logger.exception("Error while downloading favicon, using empty one")
    open('''$${:location}''', 'w').close()
  finally:
    self.buildout['buildout']['offline'] = buildout_offline

location = $${directory:frontend-static}/$${:filename}
filename = $${:_buildout_section_name_}

279

280 281 282 283 284
# Common Environment
# ------------------

[common-environment]
recipe = slapos.recipe.template:jinja2
285
rendered = $${directory:bin}/$${:_buildout_section_name_}
286 287 288 289 290 291 292 293 294 295 296
mode = 0777
template =
  inline:
  #!/bin/sh
  . ${gowork:env.sh}
  # reset PS1 from gowork
  export PS1='$ '
  export HOME=$${buildout:directory}
  export PATH=${python-language-server:location}/bin:${java-jdk:location}/bin:${cli-utilities:PATH}:$HOME/.cargo/bin:$PATH


297 298 299 300 301 302 303 304
# Theia Backend
# -------------

[theia-service-port]
recipe = slapos.cookbook:free_port
minimum = 3500
maximum = 3600
ip = $${instance-parameter:ipv4-random}
305

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
[theia-service]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/$${:_buildout_section_name_}
mode = 0700
template =
  inline:#!/bin/sh
  {% raw %}
  export THEIA_WEBVIEW_EXTERNAL_ENDPOINT='{{hostname}}'
  {% endraw %}
  export THEIA_OPEN_EDITOR_TOKEN=$(${openssl:location}/bin/openssl rand -hex 32)
  export THEIA_URL=$${:base-url}
  export THEIA_SHELL=$${theia-shell:rendered}
  export TMP=$${directory:tmp}
  export TEMP=$TMP
  export LC_ALL=C.UTF-8
321
  export TERMINFO=${ncurses:location}/lib/terminfo/
322
  export EDITOR="${python-language-server:location}/bin/python -m theia_open --wait"
323 324
  export THEIA_DEFAULT_PLUGINS="local-dir:${theia-plugins:location}"
  . $${common-environment:rendered}
325
  exec ${theia-wrapper:rendered} "$@"
326 327
ip =  $${theia-service-port:ip}
port = $${theia-service-port:port}
328
base-url = http://$${:ip}:$${:port}/
329 330 331 332

[theia-instance]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:services}/$${:_buildout_section_name_}
333
command-line = $${theia-service:rendered}  --hostname=$${:hostname} --port=$${:port} $${directory:project}
334 335 336
hash-existing-files =
  ${yarn.lock:output}
  ${theia-wrapper:rendered}
337
ip =  $${instance-parameter:ipv4-random}
338
hostname = $${:ip}
339 340
port = $${theia-service:port}
base-url = $${theia-service:base-url}
341

342
[theia-shell]
343 344 345
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/$${:_buildout_section_name_}
mode = 0700
346 347
template =
  inline:#!{{ bash }}
348
  SHELL=$BASH
349
  # when running interactively, activate slapos configuration and reset GIT_EXEC_PATH to workaround https://github.com/eclipse-theia/theia/issues/7555
350 351 352 353
  if [ $# = 0 ]; then
    . {{ activate }}
    unset GIT_EXEC_PATH
    set -- --rcfile {{ bashrc }}
354
  # otherwise, assume this shell is running task and add an artificial delay to workaround https://github.com/eclipse-theia/theia/issues/2961
355 356 357 358 359 360 361 362
  else
    sleep 1
  fi
  exec "$SHELL" "$@"
context =
  raw bash ${bash:location}/bin/bash
  key activate slapos-standalone-activate:rendered
  key bashrc theia-bashrc:rendered
363

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
[theia-bashrc]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}
template =
  inline:
  # enable bash completion
  . ${bash-completion:location}/etc/profile.d/bash_completion.sh
  # source user's .bashrc
  [ -f ~/.bashrc ] && . ~/.bashrc
depends =
  $${shell-setup-completion:recipe}

[shell-setup-completion]
recipe = plone.recipe.command
stop-on-error = true
command =
  ${buildout:bin-directory}/slapos complete > $${directory:bash-completions}/slapos
  ${buildout:bin-directory}/slapos complete --shell fish > $${directory:fish-completions}/slapos.fish

383

384 385 386 387 388 389 390 391 392
# SlapOS Standalone
# -----------------

[slapos-standalone-port]
recipe = slapos.cookbook:free_port
minimum = 4000
maximum = 4100
ip = $${instance-parameter:ipv4-random}

393 394 395
[slapos-standalone-config]
ipv4 = $${instance-parameter:ipv4-random}
ipv6 = $${instance-parameter:ipv6-random}
396
port = $${slapos-standalone-port:port}
397
slapos-configuration = $${directory:runner}/etc/slapos.cfg
398
computer-id = slaprunner
399

400 401 402 403
[slapos-standalone-activate]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/$${:_buildout_section_name_}
template =
404
  inline:
405
  export PATH=${buildout:bin-directory}:$PATH
406 407 408 409 410 411 412 413 414 415
  export SLAPOS_CONFIGURATION=$${slapos-standalone-config:slapos-configuration}
  export SLAPOS_CLIENT_CONFIGURATION=$SLAPOS_CONFIGURATION
  echo 'Standalone SlapOS for computer `$${slapos-standalone-config:computer-id}` activated'

[slapos-standalone]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/$${:_buildout_section_name_}
mode = 0700
template =
  inline:#!/bin/sh
416
  . $${common-environment:rendered}
417
  #XXX find out where the extra nodejs in theia's PATH comes from
418 419
  export PATH=${nodejs:location}/bin/:$PATH
  . $${slapos-standalone-activate:rendered}
420
  exec ${slapos-standalone:script-path} \
421
      $${directory:runner} \
422 423 424 425
      $${slapos-standalone-config:ipv4} \
      $${slapos-standalone-config:ipv6} \
      $${slapos-standalone-config:port} \
      $${slapos-standalone-config:computer-id} \
426 427
      --sr='$${instance-parameter:configuration.embedded-sr}' \
      --srtype='$${instance-parameter:configuration.embedded-sr-type}' \
428 429 430 431 432
      $${slap-connection:server-url} \
      $${slap-connection:computer-id} \
      $${slap-connection:partition-id} \
      --key='$${slap-connection:key-file}' \
      --cert='$${slap-connection:cert-file}'
433

434 435 436 437 438 439 440 441
[slapos-standalone-instance]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:services}/$${:_buildout_section_name_}
command-line = $${slapos-standalone:rendered}
hash-files =
  $${slapos-standalone:rendered}
hostname = $${slapos-standalone-config:ipv4}
port = $${slapos-standalone-config:port}
442

443

444 445
# Slapos Standalone Autoprocessing
# --------------------------------
446 447 448 449 450 451 452 453 454 455 456 457

[slapos-autorun]
recipe = plone.recipe.command
command =
  case $${:autorun} in
    ( running ) ${buildout:bin-directory}/supervisorctl -c $${:supervisor-conf} start $${:service-name};;
    ( stopped ) ${buildout:bin-directory}/supervisorctl -c $${:supervisor-conf} stop $${:service-name};;
  esac
update-command = $${:command}
service-name = slapos-node-auto
supervisor-conf = $${directory:runner}/etc/supervisord.conf
autorun = $${instance-parameter:configuration.autorun}
458

459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

# Theia Local Environment Setup
# -----------------------------

[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-config: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-config:slapos-configuration}",
            "GIT_EXEC_PATH": ""
          }
        },
        "problemMatcher": [],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

524 525 526 527 528 529 530 531
[slapos-repository]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/nexedi/slapos.git
location = $${directory:project}/slapos
branch = 1.0
develop = true
git-executable = ${git:location}/bin/git

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
[settings.json]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:dot-theia}$${:_buildout_section_name_}
once = $${:rendered}
template =
  inline:
  {
    "files.watcherExclude": {
      "**/.eggs/**": true,
      "**/.env/**": true,
      "**/.git/**": true,
      "**/node_modules/**": true,
      "$${directory:runner}/**":true,
      "$${directory:project}/runner/**":true
    }
  }

549 550 551 552
[runner-link]
recipe = slapos.cookbook:symbolic.link
target-directory = $${directory:project}
link-binary = $${directory:runner}
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

[request-script]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:project}/$${:_buildout_section_name_}.sh
mode = 0700
template =
  inline:#!/bin/sh
  software_name=html5as-base #replace the software name
  software_release_uri=~/srv/project/slapos/software/$software_name/software.cfg
  # slapos supply is used to add the software to the software list to be supplied to a node.
  slapos supply $software_release_uri slaprunner
  # slapos request the allocation of an instance to the master. 
  # slapos request also gets status and parameters of the instance if it has any 
  # (slapos request is meant to be run multiple time until you get the status).
  slapos request $software_name'_1' $software_release_uri