Skip to content

Commit

Permalink
Add hanami app to integration CI configurations (#3639)
Browse files Browse the repository at this point in the history
What does this PR do?

Adds hanami to CI configurations, as requested in #2546.

Several things needed to be fixed for the tests to pass:

Fix hanami integration app dependencies #2546
There was an empty hanami.rb which looks to have been intended to mock Hanami framework (?). The app requires the actual hanami framework to function and this empty file was loaded instead of hanami itself. I removed the file.
Hanami integration app was missing unicorn configuration, which the test suite was expecting. I copied it from sinatra.
The controller in the test app was written to fail 50% of the time, presumably to provide an environment to test failure. I commented out the failure generation so that CI would pass every time.
I also made the image build script work when ruby version isn't given and to provide a help message so that someone new to this area of the code could actually get it running locally.

Motivation:

Review of #2546.

Test plan
The tests are running on Ruby 2.6 and 2.7 only. Hanami 1 (1.3.5, more exactly) that is currently being used in these tests is not compatible with Ruby 3.


Co-authored-by: Oleg Pudeyev <code@olegp.name>
Co-authored-by: Tony Hsu <tonyc.t.hsu@gmail.com>
  • Loading branch information
3 people authored Jun 6, 2024
1 parent 595b30d commit b3c5a3d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ workflows:
<<: *filters_all_branches_and_tags
- orb/build_and_test_integration:
name: build_and_test_integration-2.6
integration_apps: 'rack rails-five rails-six sinatra2-classic sinatra2-modular'
integration_apps: 'rack rails-five rails-six sinatra2-classic sinatra2-modular hanami'
ruby_version: '2.6'
<<: *filters_all_branches_and_tags
- orb/build_and_test_integration:
name: build_and_test_integration-2.7
integration_apps: 'rack rails-five rails-six rails-seven sinatra2-classic sinatra2-modular'
integration_apps: 'rack rails-five rails-six rails-seven sinatra2-classic sinatra2-modular hanami'
ruby_version: '2.7'
<<: *filters_all_branches_and_tags
- orb/build_and_test_integration:
Expand Down
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Integration tests that run in docker should not receive the gemfile lock
# files that aren't checked into git, because these lock files are dependent
# on the system set of installed software which is different between the
# host and the docker container.
#
# Gemfile lock files that *are* checked into git should be in docker
# containers also.
Gemfile.lock
11 changes: 10 additions & 1 deletion integration/apps/hanami/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ gem 'rake'
gem 'hanami', '~> 1.3'
gem 'hanami-model', '~> 1.3'
gem 'dry-container', '~> 0.8.0'
gem 'dry-configurable', '~> 0.12.0'

gem 'sqlite3'
gem 'puma'
gem 'unicorn'
gem 'webrick'
gem 'pry-byebug'

gem 'datadog', Datadog::DemoEnv.gem_spec('datadog')[0].merge(require: 'datadog/auto_instrument')
gem_spec = Datadog::DemoEnv.gem_spec('datadog')
req = {require: 'datadog/auto_instrument'}
opts = if gem_spec.last.is_a?(Hash)
gem_spec.pop.merge(req)
else
req
end
gem_spec << opts
gem 'datadog', *gem_spec
gem 'google-protobuf', '~> 3.0'

group :development do
Expand Down
2 changes: 2 additions & 0 deletions integration/apps/hanami/apps/acme/controllers/books/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ class Show
include Acme::Action

def call(params)
=begin Uncomment for testing failures
# binding.pry
if rand > 0.5
raise "Oooops...."
end
=end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion integration/apps/hanami/config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'bundler/setup'
require 'hanami/setup'
require 'hanami/model'
require_relative '../lib/hanami'
require_relative '../apps/acme/application'

Hanami.configure do
Expand Down
2 changes: 0 additions & 2 deletions integration/apps/hanami/config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

preload_app!

rackup DefaultRackup

port ENV.fetch("PORT") { 80 }

environment ENV.fetch("HANAMI_ENV") { "development" }
Expand Down
23 changes: 23 additions & 0 deletions integration/apps/hanami/config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'datadog/demo_env'

# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

Datadog::DemoEnv.print_env('Unicorn master environment')

before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
end

after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end

Datadog::DemoEnv.print_env('Unicorn worker environment')
end
2 changes: 0 additions & 2 deletions integration/apps/hanami/lib/hanami.rb

This file was deleted.

13 changes: 11 additions & 2 deletions integration/script/build-images
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ INTEGRATION_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1
INTEGRATION_DIR=${INTEGRATION_SCRIPT_DIR%/script}
cd $INTEGRATION_DIR

APP_RUBY_VERSION=

# Parse options
while getopts ":v:" opt; do
while getopts ":hv:" opt; do
case $opt in
h)
echo "Usage: ./script/build-images [-v RUBY_VERSION]"
echo
echo "If no Ruby version is specified, images are built for each of the"
echo "supported versions (currently 2.1 through 3.3)."
exit 0
;;
v)
APP_RUBY_VERSION=$OPTARG
;;
Expand All @@ -27,7 +36,7 @@ echo "== Building base images... =="
# docker build -t datadog/dd-apm-demo:wrk -f $INTEGRATION_DIR/images/wrk/Dockerfile $INTEGRATION_DIR/images
docker build -t datadog/dd-apm-demo:agent -f $INTEGRATION_DIR/images/agent/Dockerfile $INTEGRATION_DIR/images/agent

if [[ ! -z $APP_RUBY_VERSION ]]; then
if test -n "$APP_RUBY_VERSION"; then
docker build -t datadog/dd-apm-demo:rb-$APP_RUBY_VERSION -f $INTEGRATION_DIR/images/ruby/$APP_RUBY_VERSION/Dockerfile $INTEGRATION_DIR/images
else
docker build -t datadog/dd-apm-demo:rb-2.1 -f $INTEGRATION_DIR/images/ruby/2.1/Dockerfile $INTEGRATION_DIR/images
Expand Down

0 comments on commit b3c5a3d

Please sign in to comment.