Skip to content

Rake tasks for running tests in Docker #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.ruby-version
Gemfile.lock
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
services:
- docker

language: general
language: ruby

env:
matrix:
Expand All @@ -14,8 +14,8 @@ env:
- RVM_RUBY_VERSION=2.6
- RVM_RUBY_VERSION=ruby-head

before_install:
- sudo docker build -t stackprof-$RVM_RUBY_VERSION --build-arg=RVM_RUBY_VERSION=$RVM_RUBY_VERSION .
after_install:
- bundle exec rake test:docker:$RVM_RUBY_VERSION:build

script:
- sudo docker run --name stackprof-$RVM_RUBY_VERSION stackprof-$RVM_RUBY_VERSION
- bundle exec rake test:docker:$RVM_RUBY_VERSION
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
55 changes: 55 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.2 2.3 2.4 2.5 2.6]

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
build_ruby_docker_image
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