From d8bb6e5137c7a7f6b672de3240f4e24140366457 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 19:32:37 -0500 Subject: [PATCH 01/18] Ignore .ruby-version using .dockerignore If a user has a local `.ruby-version` file in the project directory for `stackprof`, this can cause some extra noise in the docker builds. Adding this file simply tells `docker` to ignore it when doing a `ADD`. --- .dockerignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..eaa6e54c --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.ruby-version From 67c83746bb866a3121160b01d37882cf791e893b Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 19:34:13 -0500 Subject: [PATCH 02/18] Add test:docker:* rake tasks These are helper tasks for docker that are used to facilitate a similar testing environment that would be seen on Travis. This even allows for running tests against all tested versions of Ruby. Specifically, once all of the images have been built for each version, re-running tests against all versions of ruby takes only about 10sec on my machine: $ time rake test:docker ==> Building Docker Image for 2.1... docker build -t stackprof-2.1 --build-arg=RVM_RUBY_VERSION=2.1 . {[:out, :err]=>"/dev/null"} docker run --rm stackprof-2.1 mesg: ttyname failed: Inappropriate ioctl for device install -c tmp/x86_64-linux/stackprof/2.1.10/stackprof.so lib/stackprof/stackprof.so cp tmp/x86_64-linux/stackprof/2.1.10/stackprof.so tmp/x86_64-linux/stage/lib/stackprof/stackprof.so Run options: --seed 21454 # Running: ........................ Finished in 0.263683s, 91.0185 runs/s, 284.4327 assertions/s. 24 runs, 75 assertions, 0 failures, 0 errors, 0 skips ==> Building Docker Image for 2.2... docker build -t stackprof-2.2 --build-arg=RVM_RUBY_VERSION=2.2 . {[:out, :err]=>"/dev/null"} docker run --rm stackprof-2.2 mesg: ttyname failed: Inappropriate ioctl for device install -c tmp/x86_64-linux/stackprof/2.2.10/stackprof.so lib/stackprof/stackprof.so cp tmp/x86_64-linux/stackprof/2.2.10/stackprof.so tmp/x86_64-linux/stage/lib/stackprof/stackprof.so Run options: --seed 47520 # Running: ........................ Finished in 0.270496s, 88.7260 runs/s, 277.2687 assertions/s. When using `docker-machine`, simply create a `docker-machine` VM, sync up the environment to point to the VM running docker, and run the rake tasks normally: $ docker-machine create --driver virtualbox default $ eval $(docker-machine env default) $ rake test:docker:all $ rake test:docker:clean $ rake test:docker:2.4 --- Rakefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Rakefile b/Rakefile index 2a2b16ec..25469b39 100644 --- a/Rakefile +++ b/Rakefile @@ -29,3 +29,58 @@ Rake::TestTask.new 'test' do |t| t.test_files = FileList['test/test_*.rb'] end task :test => :build + +def build_ruby_docker_image ruby_version = "ruby-head" + image = "stackprof-#{ruby_version}" + sh_opts = [] + sh_opts = [{[:out, :err] => File::NULL}, {}] if @mute_build_output + + puts "\033[34m==>\033[0m \033[1mBuilding Docker Image for #{ruby_version}...\033[0m" + sh "docker build -t #{image} --build-arg=RVM_RUBY_VERSION=#{ruby_version} .", *sh_opts +end + +def run_tests_in_docker ruby_version = "ruby-head" + sh "docker run --rm stackprof-#{ruby_version}" +end + +namespace :test do + namespace :docker do + RUBY_VERSIONS = %w[2.1 2.2 2.3 2.4 2.5] + + RUBY_VERSIONS.each do |ruby_version| + task "#{ruby_version}:build" do + build_ruby_docker_image ruby_version + end + + desc "Run tests in docker for Ruby #{ruby_version}" + task ruby_version => "#{ruby_version}:build" do + run_tests_in_docker ruby_version + end + end + + task "ruby-head:build" do + run_tests_in_docker + end + + desc "Run tests in docker for ruby-head" + task "ruby-head" => "ruby-head:build" do + run_tests_in_docker + end + + desc "Run tests in docker for all versions" + task :all => %w[mute_build_output] + RUBY_VERSIONS + %w[ruby-head] + + desc "Clean created docker images" + task :clean do + images = RUBY_VERSIONS.map {|rbv| "stackprof-#{rbv}" } + images << "stackprof-ruby-head" + sh "docker rmi --force #{images.join(' ')}", {[:out,:err] => File::NULL} + end + + task :mute_build_output do + @mute_build_output = true + end + end + + task :docker => "test:docker:all" +end From 370a143e04d7517127d32680d9249d1e87ac334b Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 19:41:06 -0500 Subject: [PATCH 03/18] Run `rake build` as part of build stage Reduces the noise when running `rake test:docker:all`. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 7c107967..70a24031 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,5 @@ ADD . /stackprof/ WORKDIR /stackprof/ RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && gem install bundler:1.16.0" RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && bundle install" +RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && bundle exec rake build" CMD /bin/bash -l -c ". /etc/profile.d/rvm.sh && bundle exec rake" From de1d708a192559461679ccb598f80c99b1138891 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 19:53:56 -0500 Subject: [PATCH 04/18] Use rake tasks on travis Will help keep the list of ruby versions found in the .travis.yml in sync with the ones in the Rakefile, since if a new version of ruby is added to the .travis.yml, but it will break the tasks. This makes `rake test:docker:all` have a better chance of accurately representing a full Travis build across all rubies. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5c8b501..8d270f89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required services: - docker -language: general +language: ruby env: matrix: @@ -15,7 +15,7 @@ env: - RVM_RUBY_VERSION=ruby-head before_install: -- sudo docker build -t stackprof-$RVM_RUBY_VERSION --build-arg=RVM_RUBY_VERSION=$RVM_RUBY_VERSION . +- sudo rake test:docker:$RVM_RUBY_VERSION:build script: -- sudo docker run --name stackprof-$RVM_RUBY_VERSION stackprof-$RVM_RUBY_VERSION +- sudo rake test:docker:$RVM_RUBY_VERSION From 77c9b156255d3be73a553705e61d4396f1d33670 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:08:07 -0500 Subject: [PATCH 05/18] [FIXUP] .travis.yml fix attempt #1 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d270f89..13f1b112 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ env: - RVM_RUBY_VERSION=ruby-head before_install: -- sudo rake test:docker:$RVM_RUBY_VERSION:build +- sudo -E rake test:docker:$RVM_RUBY_VERSION:build script: -- sudo rake test:docker:$RVM_RUBY_VERSION +- sudo -E rake test:docker:$RVM_RUBY_VERSION From a533c5e6c8077b3833c96e4f158b84fd718418e5 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:08:43 -0500 Subject: [PATCH 06/18] [Debug] run rake tasks with --trace --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13f1b112..e5f09c39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ env: - RVM_RUBY_VERSION=ruby-head before_install: -- sudo -E rake test:docker:$RVM_RUBY_VERSION:build +- sudo -E rake --trace test:docker:$RVM_RUBY_VERSION:build script: -- sudo -E rake test:docker:$RVM_RUBY_VERSION +- sudo -E rake --trace test:docker:$RVM_RUBY_VERSION From 45a47db210df5e9d8d20784186745dec44a78abf Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:09:15 -0500 Subject: [PATCH 07/18] [DEBUG] determine what ruby/rake we are using --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e5f09c39..b83aa7de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ env: - RVM_RUBY_VERSION=ruby-head before_install: +- sudo -E which ruby +- sudo -E which rake - sudo -E rake --trace test:docker:$RVM_RUBY_VERSION:build script: From a4848ae3a18f08e93b46629d05ec1222a48a3a00 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:12:32 -0500 Subject: [PATCH 08/18] [DEBUG] Confirm I know what sudo options are availble... --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b83aa7de..46168ae4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - RVM_RUBY_VERSION=ruby-head before_install: +- sudo --help - sudo -E which ruby - sudo -E which rake - sudo -E rake --trace test:docker:$RVM_RUBY_VERSION:build From bf05c17d7ead1d2198818437bf66778e2730089d Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:12:54 -0500 Subject: [PATCH 09/18] [FIXUP] try using -i instead of -E hopefully this will load the .rvm scripts... --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46168ae4..c31963e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ env: before_install: - sudo --help -- sudo -E which ruby -- sudo -E which rake -- sudo -E rake --trace test:docker:$RVM_RUBY_VERSION:build +- sudo -i which ruby +- sudo -i which rake +- sudo -i rake --trace test:docker:$RVM_RUBY_VERSION:build script: -- sudo -E rake --trace test:docker:$RVM_RUBY_VERSION +- sudo -i rake --trace test:docker:$RVM_RUBY_VERSION From b873cec040f66e9f34d695f96ad3d13625f7c193 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:17:05 -0500 Subject: [PATCH 10/18] [FIXUP] Maybe we don't need sudo.. Travis docs seem to suggest we don't... https://docs.travis-ci.com/user/docker/ --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c31963e3..6400dc84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_install: - sudo --help - sudo -i which ruby - sudo -i which rake -- sudo -i rake --trace test:docker:$RVM_RUBY_VERSION:build +- rake --trace test:docker:$RVM_RUBY_VERSION:build script: -- sudo -i rake --trace test:docker:$RVM_RUBY_VERSION +- rake --trace test:docker:$RVM_RUBY_VERSION From ada124c97628027b45bfd9adbf546c9344d8c627 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:19:29 -0500 Subject: [PATCH 11/18] [FIXUP] Duh Nick... you need to bundle... Yeah, we are now using the `Rakefile`, so we need to bundle so `rake/extensiontask` is available... --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6400dc84..43fd4912 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_install: - sudo --help - sudo -i which ruby - sudo -i which rake +- bundle install - rake --trace test:docker:$RVM_RUBY_VERSION:build script: From 39f7fa89704e0c88409087c4005370c107c8113d Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:22:12 -0500 Subject: [PATCH 12/18] [FIXUP] ... or do we? This is the other option I guess... though, probably better that we just use `bundle install` on CI, as it is only 3 seconds to do that. --- Rakefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 25469b39..ef44d824 100644 --- a/Rakefile +++ b/Rakefile @@ -14,11 +14,16 @@ end # Ruby Extension # ========================================================== -require 'rake/extensiontask' -Rake::ExtensionTask.new('stackprof', GEMSPEC) do |ext| - ext.lib_dir = 'lib/stackprof' +begin + require 'rake/extensiontask' + Rake::ExtensionTask.new('stackprof', GEMSPEC) do |ext| + ext.lib_dir = 'lib/stackprof' + end + task :build => :compile +rescue LoadError => e + # rake-compiler not installed. No problem if on CI. + raise e unless ENV["TRAVIS"] end -task :build => :compile # ========================================================== # Testing From cf4eca17df83dd8e35e02ce117d43edbf0f7a4c8 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:31:47 -0500 Subject: [PATCH 13/18] [FIXUP] Oops... forgot ruby-2.6 --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index ef44d824..14767036 100644 --- a/Rakefile +++ b/Rakefile @@ -50,7 +50,7 @@ end namespace :test do namespace :docker do - RUBY_VERSIONS = %w[2.1 2.2 2.3 2.4 2.5] + RUBY_VERSIONS = %w[2.1 2.2 2.3 2.4 2.5 2.6] RUBY_VERSIONS.each do |ruby_version| task "#{ruby_version}:build" do From f5dfa8a9c5daeccdfc9c73399c89839a6c8849e7 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:35:04 -0500 Subject: [PATCH 14/18] [FIXUP] Oops... wrong method for ruby-head:build --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 14767036..13a11059 100644 --- a/Rakefile +++ b/Rakefile @@ -64,7 +64,7 @@ namespace :test do end task "ruby-head:build" do - run_tests_in_docker + build_ruby_docker_image end desc "Run tests in docker for ruby-head" From b639f54a9561fa29a41b39d70c258a7e90cddada Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 21:35:48 -0500 Subject: [PATCH 15/18] [FIXUP] Final form I think this is the route I am going to go with, and will most likely rebase these [FIXUP] and [DEBUG] commits out. It makes use of the `bundle install` that is already done by travis anyway (since we did a `before_install` instead of overwriting the `install`, this was being done when I switched the language back to `ruby`), it makes for a simpler diff to digest. Also... I think the `bundle exec rake ...` might be required... --- .travis.yml | 10 +++------- Rakefile | 13 ++++--------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 43fd4912..7785d464 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,12 +14,8 @@ env: - RVM_RUBY_VERSION=2.6 - RVM_RUBY_VERSION=ruby-head -before_install: -- sudo --help -- sudo -i which ruby -- sudo -i which rake -- bundle install -- rake --trace test:docker:$RVM_RUBY_VERSION:build +after_install: +- bundle exec rake test:docker:$RVM_RUBY_VERSION:build script: -- rake --trace test:docker:$RVM_RUBY_VERSION +- bundle exec rake test:docker:$RVM_RUBY_VERSION diff --git a/Rakefile b/Rakefile index 13a11059..a0f9372a 100644 --- a/Rakefile +++ b/Rakefile @@ -14,16 +14,11 @@ end # Ruby Extension # ========================================================== -begin - require 'rake/extensiontask' - Rake::ExtensionTask.new('stackprof', GEMSPEC) do |ext| - ext.lib_dir = 'lib/stackprof' - end - task :build => :compile -rescue LoadError => e - # rake-compiler not installed. No problem if on CI. - raise e unless ENV["TRAVIS"] +require 'rake/extensiontask' +Rake::ExtensionTask.new('stackprof', GEMSPEC) do |ext| + ext.lib_dir = 'lib/stackprof' end +task :build => :compile # ========================================================== # Testing From 28e774f54d98c8453551e70c46b4e612416c29c2 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 15 Jul 2020 18:51:49 -0500 Subject: [PATCH 16/18] [FIXUP][Rakefile] match method styles In other words: "un-seattle.rb" the method declarations. Force of habit... --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index a0f9372a..ef905c71 100644 --- a/Rakefile +++ b/Rakefile @@ -30,7 +30,7 @@ Rake::TestTask.new 'test' do |t| end task :test => :build -def build_ruby_docker_image ruby_version = "ruby-head" +def build_ruby_docker_image(ruby_version="ruby-head") image = "stackprof-#{ruby_version}" sh_opts = [] sh_opts = [{[:out, :err] => File::NULL}, {}] if @mute_build_output @@ -39,7 +39,7 @@ def build_ruby_docker_image ruby_version = "ruby-head" sh "docker build -t #{image} --build-arg=RVM_RUBY_VERSION=#{ruby_version} .", *sh_opts end -def run_tests_in_docker ruby_version = "ruby-head" +def run_tests_in_docker(ruby_version="ruby-head") sh "docker run --rm stackprof-#{ruby_version}" end From 8f5fc590d5b5a2c941086cae388d5f7cedb0cc9b Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 15 Jul 2020 18:52:42 -0500 Subject: [PATCH 17/18] [FIXUP][Rakefile] Only run versions supported in CI --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index ef905c71..5bd16e9e 100644 --- a/Rakefile +++ b/Rakefile @@ -45,7 +45,7 @@ end namespace :test do namespace :docker do - RUBY_VERSIONS = %w[2.1 2.2 2.3 2.4 2.5 2.6] + RUBY_VERSIONS = %w[2.2 2.3 2.4 2.5 2.6] RUBY_VERSIONS.each do |ruby_version| task "#{ruby_version}:build" do From 268839b826302e09e27199e4c238db7e8b8c2613 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 15 Jul 2020 19:00:15 -0500 Subject: [PATCH 18/18] [FIXUP][.dockerignore] Ignore Gemfile.lock Travis will require a `bundle install` so `rake/extensiontask` is available when running the Rakefile, but we don't want to include this in the `docker` build, so exclude it via the `.dockerignore` --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index eaa6e54c..7edb52d6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ .ruby-version +Gemfile.lock