# helloweb - programs to say hello to the Web in various languages
[buildout]
extends =
  ../git/buildout.cfg
  ../ruby/buildout.cfg
  ../golang/buildout.cfg
  gowork.cfg

parts =
  helloweb-python
  helloweb-ruby
  helloweb-go


# helloweb.git repository with examples.
#
# We clone it via golang infrastructure into a Go workspace.
# Via gowork helloweb/go is not only cloned, but also built and installed into gowork/bin.
#
# Another option would be to use slapos.recipe.build:gitclone and handle
# cloning+building manually. However to be able to use third-party Go packages
# we need gowork support, and other languages can use helloweb repository from
# under gowork as well.
[gowork]
install =
    lab.nexedi.com/nexedi/helloweb/go/...

golang  = ${golang1.12:location}


# -*- go -*-
[helloweb-go]
# we already have gowork/bin/helloweb with helloweb Go build.
# Add bin/helloweb-go that runs go version of helloweb without any environment preset needed.
recipe  = collective.recipe.template
output  = ${buildout:bin-directory}/${:_buildout_section_name_}
mode    = 0755
input   = inline:
    #!/bin/sh
    . ${gowork:env.sh}
    exec helloweb "$@"


# -*- python -*-
[helloweb-egg]
recipe  = zc.recipe.egg:develop
egg     = helloweb
setup   = ${gowork:src}/lab.nexedi.com/nexedi/helloweb/python/

[helloweb-python]
recipe  = zc.recipe.egg:scripts
eggs    = ${helloweb-egg:egg}
scripts = helloweb=helloweb-python


# -*- ruby -*-

# if ruby program is represented as already-released gem, we can install it
# with `gem install ...` (via rubygemsrecipe).
#
# Alternatively if we need to
# install the program from source-checkout, the Ruby way is to use bundler,
# install program dependencies via it, and run the program itself via it.
#
# Since for helloweb.rb we have source checkout - we go the second - bundler way.

# bundler, that we'll use to install gems and run binaries (via `bundle exec ...`)
[bundler]
# rubygemsrecipe with fixed url and this way pinned rubygems version
recipe  = rubygemsrecipe
url     = https://rubygems.org/rubygems/rubygems-2.5.2.zip
ruby-location = ${ruby2.1:location}
ruby-executable = ${:ruby-location}/bin/ruby
gems    = bundler==1.11.2

# bin installed here
bundle  = ${buildout:bin-directory}/bundle

# install together with path to ruby enabled
# ( reason: rubygemsrecipe hardcodes PATH inside generated bin/* and it is
#   impossible to adjust it later )
#
# bundle exec <smth>                ; <smth> starts with `#!/usr/bin/env ruby` as rubygems
environment =
  PATH    = ${:ruby-location}/bin:%(PATH)s


[helloweb-ruby-bundle]
recipe  = slapos.recipe.cmmi
path    = ${gowork:src}/lab.nexedi.com/nexedi/helloweb/ruby/

configure-command = :
make-binary =
make-targets= cd ${:path} && ${bundler:bundle} install


[helloweb-ruby]
# NOTE slapos.cookbook:wrapper also works, but currently _only_ in instance
recipe  = collective.recipe.template
output  = ${buildout:bin-directory}/${:_buildout_section_name_}
mode    = 0755
input   = inline:
    #!/bin/sh
    export BUNDLE_GEMFILE=${helloweb-ruby-bundle:path}/Gemfile
    exec ${bundler:bundle} exec sh -c 'helloweb.rb "$@"' ${:_buildout_section_name_} "$@"