Skip to content

Commit b3c5a3d

Browse files
p-datadogpTonyCTHsu
authored
Add hanami app to integration CI configurations (#3639)
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>
1 parent 595b30d commit b3c5a3d

File tree

9 files changed

+56
-10
lines changed

9 files changed

+56
-10
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ workflows:
531531
<<: *filters_all_branches_and_tags
532532
- orb/build_and_test_integration:
533533
name: build_and_test_integration-2.6
534-
integration_apps: 'rack rails-five rails-six sinatra2-classic sinatra2-modular'
534+
integration_apps: 'rack rails-five rails-six sinatra2-classic sinatra2-modular hanami'
535535
ruby_version: '2.6'
536536
<<: *filters_all_branches_and_tags
537537
- orb/build_and_test_integration:
538538
name: build_and_test_integration-2.7
539-
integration_apps: 'rack rails-five rails-six rails-seven sinatra2-classic sinatra2-modular'
539+
integration_apps: 'rack rails-five rails-six rails-seven sinatra2-classic sinatra2-modular hanami'
540540
ruby_version: '2.7'
541541
<<: *filters_all_branches_and_tags
542542
- orb/build_and_test_integration:

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Integration tests that run in docker should not receive the gemfile lock
2+
# files that aren't checked into git, because these lock files are dependent
3+
# on the system set of installed software which is different between the
4+
# host and the docker container.
5+
#
6+
# Gemfile lock files that *are* checked into git should be in docker
7+
# containers also.
8+
Gemfile.lock

integration/apps/hanami/Gemfile

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ gem 'rake'
66
gem 'hanami', '~> 1.3'
77
gem 'hanami-model', '~> 1.3'
88
gem 'dry-container', '~> 0.8.0'
9+
gem 'dry-configurable', '~> 0.12.0'
910

1011
gem 'sqlite3'
1112
gem 'puma'
1213
gem 'unicorn'
1314
gem 'webrick'
1415
gem 'pry-byebug'
1516

16-
gem 'datadog', Datadog::DemoEnv.gem_spec('datadog')[0].merge(require: 'datadog/auto_instrument')
17+
gem_spec = Datadog::DemoEnv.gem_spec('datadog')
18+
req = {require: 'datadog/auto_instrument'}
19+
opts = if gem_spec.last.is_a?(Hash)
20+
gem_spec.pop.merge(req)
21+
else
22+
req
23+
end
24+
gem_spec << opts
25+
gem 'datadog', *gem_spec
1726
gem 'google-protobuf', '~> 3.0'
1827

1928
group :development do

integration/apps/hanami/apps/acme/controllers/books/show.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ class Show
55
include Acme::Action
66

77
def call(params)
8+
=begin Uncomment for testing failures
89
# binding.pry
910
if rand > 0.5
1011
raise "Oooops...."
1112
end
13+
=end
1214
end
1315
end
1416
end

integration/apps/hanami/config/environment.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'bundler/setup'
22
require 'hanami/setup'
33
require 'hanami/model'
4-
require_relative '../lib/hanami'
54
require_relative '../apps/acme/application'
65

76
Hanami.configure do

integration/apps/hanami/config/puma.rb

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
preload_app!
1414

15-
rackup DefaultRackup
16-
1715
port ENV.fetch("PORT") { 80 }
1816

1917
environment ENV.fetch("HANAMI_ENV") { "development" }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'datadog/demo_env'
2+
3+
# config/unicorn.rb
4+
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
5+
timeout 15
6+
preload_app true
7+
8+
Datadog::DemoEnv.print_env('Unicorn master environment')
9+
10+
before_fork do |server, worker|
11+
Signal.trap 'TERM' do
12+
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
13+
Process.kill 'QUIT', Process.pid
14+
end
15+
end
16+
17+
after_fork do |server, worker|
18+
Signal.trap 'TERM' do
19+
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
20+
end
21+
22+
Datadog::DemoEnv.print_env('Unicorn worker environment')
23+
end

integration/apps/hanami/lib/hanami.rb

-2
This file was deleted.

integration/script/build-images

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ INTEGRATION_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1
55
INTEGRATION_DIR=${INTEGRATION_SCRIPT_DIR%/script}
66
cd $INTEGRATION_DIR
77

8+
APP_RUBY_VERSION=
9+
810
# Parse options
9-
while getopts ":v:" opt; do
11+
while getopts ":hv:" opt; do
1012
case $opt in
13+
h)
14+
echo "Usage: ./script/build-images [-v RUBY_VERSION]"
15+
echo
16+
echo "If no Ruby version is specified, images are built for each of the"
17+
echo "supported versions (currently 2.1 through 3.3)."
18+
exit 0
19+
;;
1120
v)
1221
APP_RUBY_VERSION=$OPTARG
1322
;;
@@ -27,7 +36,7 @@ echo "== Building base images... =="
2736
# docker build -t datadog/dd-apm-demo:wrk -f $INTEGRATION_DIR/images/wrk/Dockerfile $INTEGRATION_DIR/images
2837
docker build -t datadog/dd-apm-demo:agent -f $INTEGRATION_DIR/images/agent/Dockerfile $INTEGRATION_DIR/images/agent
2938

30-
if [[ ! -z $APP_RUBY_VERSION ]]; then
39+
if test -n "$APP_RUBY_VERSION"; then
3140
docker build -t datadog/dd-apm-demo:rb-$APP_RUBY_VERSION -f $INTEGRATION_DIR/images/ruby/$APP_RUBY_VERSION/Dockerfile $INTEGRATION_DIR/images
3241
else
3342
docker build -t datadog/dd-apm-demo:rb-2.1 -f $INTEGRATION_DIR/images/ruby/2.1/Dockerfile $INTEGRATION_DIR/images

0 commit comments

Comments
 (0)