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

parts =
  helloweb-python
  helloweb-ruby
  helloweb-go


# repository with examples
[helloweb-repository]
recipe  = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
repository = https://lab.nexedi.com/nexedi/helloweb.git
revision = 0487fa7bc88e83ce8b97d784ab11354aa8fac603
location = ${buildout:parts-directory}/helloweb


# -*- python -*-
[helloweb-egg]
recipe  = zc.recipe.egg:develop
egg     = helloweb
setup   = ${helloweb-repository:location}/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.4.8.zip
ruby-location = ${ruby2.1:location}
ruby-executable = ${:ruby-location}/bin/ruby
gems    = bundler==1.10.6

# 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    = ${helloweb-repository:location}/ruby/

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


[helloweb-ruby]
recipe  = slapos.cookbook:wrapper
wrapper-path = ${buildout:bin-directory}/${:_buildout_section_name_}
environment  =
    BUNDLE_GEMFILE = ${helloweb-ruby-bundle:path}/Gemfile
command-line =
    ${bundler:bundle} exec sh -c 'helloweb.rb "$@"' ${:_buildout_section_name_}


# -*- go -*-
[helloweb-go]
recipe  = slapos.recipe.cmmi
path    = ${helloweb-repository:location}/go/

go      = ${golang15:location}/bin/go
configure-command = :
make-binary =
make-targets= cd ${:path} &&
     ${:go} build
        -o ${buildout:bin-directory}/${:_buildout_section_name_}
        helloweb.go
