|
| 1 | +require './ci/common' |
| 2 | + |
| 3 | +def kong_version |
| 4 | + ENV['FLAVOR_VERSION'] || '0.8.1' |
| 5 | +end |
| 6 | + |
| 7 | +def kong_rootdir |
| 8 | + "#{ENV['INTEGRATIONS_DIR']}/kong" |
| 9 | +end |
| 10 | + |
| 11 | +def cassandra_rootdir |
| 12 | + "#{ENV['INTEGRATIONS_DIR']}/cassandra" |
| 13 | +end |
| 14 | + |
| 15 | +namespace :ci do |
| 16 | + namespace :kong do |flavor| |
| 17 | + task before_install: ['ci:common:before_install'] |
| 18 | + |
| 19 | + task install: ['ci:common:install'] do |
| 20 | + unless Dir.exist? File.expand_path(kong_rootdir) |
| 21 | + # Download Kong, Cassandra. curl, openjdk 1.8, wget, make, gcc must be already installed |
| 22 | + ENV['LUA_VERSION'] = 'luajit-2.1' |
| 23 | + ENV['CASSANDRA_VERSION'] = '2.2.4' |
| 24 | + ENV['LUAROCKS_VERSION'] = '2.3.0' |
| 25 | + ENV['OPENSSL_VERSION'] = '1.0.2f' |
| 26 | + ENV['OPENRESTY_VERSION'] = '1.9.7.3' |
| 27 | + ENV['SERF_VERSION'] = '0.7.0' |
| 28 | + ENV['DNSMASQ_VERSION'] = '2.75' |
| 29 | + ENV['LUAJIT_VERSION'] = '2.1' |
| 30 | + ENV['LUAJIT_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/lua" |
| 31 | + ENV['LUAROCKS_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/luarocks" |
| 32 | + ENV['OPENRESTY_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/openresty" |
| 33 | + ENV['SERF_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/serf" |
| 34 | + ENV['DNSMASQ_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/dnsmasq" |
| 35 | + ENV['CASSANDRA_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/cassandra" |
| 36 | + ENV['UUID_DIR'] = "#{ENV['INTEGRATIONS_DIR']}/libuuid" |
| 37 | + ENV['CASSANDRA_HOSTS'] = '127.0.0.1' |
| 38 | + sh %(mkdir -p #{kong_rootdir}) |
| 39 | + sh %(cp $TRAVIS_BUILD_DIR/ci/resources/kong/*.sh #{kong_rootdir}) |
| 40 | + sh %(bash #{kong_rootdir}/setup_uuid.sh) |
| 41 | + sh %(bash #{kong_rootdir}/setup_lua.sh) |
| 42 | + sh %(bash #{kong_rootdir}/setup_openresty.sh) |
| 43 | + sh %(bash #{kong_rootdir}/setup_serf.sh) |
| 44 | + sh %(bash #{kong_rootdir}/setup_dnsmasq.sh) |
| 45 | + ENV['LUA_CPATH'] = "./?.so;#{ENV['LUAROCKS_DIR']}/lib/lua/5.1/?.so;" |
| 46 | + ENV['LUA_PATH'] = "./?.lua;#{ENV['LUAROCKS_DIR']}/share/lua/5.1/?.lua;#{ENV['LUAROCKS_DIR']}/share/lua/5.1/?/init.lua;\ |
| 47 | + #{ENV['LUAROCKS_DIR']}/lib/lua/5.1/?.lua;" |
| 48 | + ENV['PATH'] = "#{ENV['LUAJIT_DIR']}/bin:#{ENV['LUAJIT_DIR']}/include/#{ENV['LUA_VERSION']}:#{ENV['LUAROCKS_DIR']}/bin:#{ENV['PATH']}" |
| 49 | + ENV['PATH'] = "#{ENV['OPENRESTY_DIR']}/nginx/sbin:#{ENV['SERF_DIR']}:#{ENV['DNSMASQ_DIR']}/usr/local/sbin:#{ENV['PATH']}" |
| 50 | + sh %(curl -s -L -o $VOLATILE_DIR/apache-cassandra-2.2.6-bin.tar.gz\ |
| 51 | + http://mirror.metrocast.net/apache/cassandra/2.2.6/apache-cassandra-2.2.6-bin.tar.gz) |
| 52 | + sh %(mkdir -p #{cassandra_rootdir}) |
| 53 | + sh %(tar zxf $VOLATILE_DIR/apache-cassandra-2.2.6-bin.tar.gz\ |
| 54 | + -C #{cassandra_rootdir} --strip-components=1) |
| 55 | + sh %(#{cassandra_rootdir}/bin/cassandra -p $VOLATILE_DIR/cass.pid > /dev/null) |
| 56 | + sh %(mkdir -p $VOLATILE_DIR/cassandra) |
| 57 | + Wait.for 9042, 60 |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + task before_script: ['ci:common:before_script'] do |
| 62 | + sh %(bash #{kong_rootdir}/kong_install.sh) |
| 63 | + Wait.for 8001, 10 |
| 64 | + end |
| 65 | + |
| 66 | + task script: ['ci:common:script'] do |
| 67 | + this_provides = [ |
| 68 | + 'kong' |
| 69 | + ] |
| 70 | + Rake::Task['ci:common:run_tests'].invoke(this_provides) |
| 71 | + end |
| 72 | + |
| 73 | + task before_cache: :cleanup |
| 74 | + |
| 75 | + task cache: ['ci:common:cache'] |
| 76 | + |
| 77 | + task cleanup: ['ci:common:cleanup'] do |
| 78 | + sh %(kill `cat $VOLATILE_DIR/cass.pid`) |
| 79 | + sleep_for 3 |
| 80 | + sh %(kill `cat $INTEGRATIONS_DIR/kong/nginx.pid`) |
| 81 | + sh %(kill `cat $INTEGRATIONS_DIR/kong/dnsmasq.pid`) |
| 82 | + sh %(kill `cat $INTEGRATIONS_DIR/kong/serf.pid`) |
| 83 | + end |
| 84 | + |
| 85 | + task :execute do |
| 86 | + exception = nil |
| 87 | + begin |
| 88 | + %w(before_install install before_script |
| 89 | + script before_cache cache).each do |t| |
| 90 | + Rake::Task["#{flavor.scope.path}:#{t}"].invoke |
| 91 | + end |
| 92 | + rescue => e |
| 93 | + exception = e |
| 94 | + puts "Failed task: #{e.class} #{e.message}".red |
| 95 | + end |
| 96 | + if ENV['SKIP_CLEANUP'] |
| 97 | + puts 'Skipping cleanup, disposable environments are great'.yellow |
| 98 | + else |
| 99 | + puts 'Cleaning up' |
| 100 | + Rake::Task["#{flavor.scope.path}:cleanup"].invoke |
| 101 | + end |
| 102 | + raise exception if exception |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments