diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..7edb52d6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.ruby-version +Gemfile.lock diff --git a/.travis.yml b/.travis.yml index b5c8b501..7785d464 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required services: - docker -language: general +language: ruby env: matrix: @@ -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 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" diff --git a/Rakefile b/Rakefile index 2a2b16ec..5bd16e9e 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.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