diff --git a/.travis.yml b/.travis.yml index 197144ec0..f348d9f3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,19 @@ matrix: - stage: r10k tests rvm: jruby - stage: r10k container tests - language: generic + language: ruby + rvm: 2.5.5 + env: + - DOCKER_COMPOSE_VERSION=1.24.0 script: - - cd docker && make lint && make build && make test + - | + set -ex + sudo rm /usr/local/bin/docker-compose + curl --location https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname --kernel-name`-`uname --machine` > docker-compose + chmod +x docker-compose + sudo mv docker-compose /usr/local/bin + cd docker + make lint + make build + make test + set +x diff --git a/docker/.rspec b/docker/.rspec index 0baedb8de..d44e00231 100644 --- a/docker/.rspec +++ b/docker/.rspec @@ -1,4 +1,4 @@ ---require ./r10k/spec/spec_helper +--require pupperware/spec_helper --format RspecJunitFormatter --out TEST-rspec.xml --format documentation diff --git a/docker/Gemfile b/docker/Gemfile index dd21dbd75..6ab039f45 100644 --- a/docker/Gemfile +++ b/docker/Gemfile @@ -12,3 +12,7 @@ end gem 'rspec' gem 'rspec_junit_formatter' +gem 'pupperware', + :git => 'https://github.com/puppetlabs/pupperware.git', + :ref => 'master', + :glob => 'gem/*.gemspec' diff --git a/docker/Makefile b/docker/Makefile index 636104d4c..fb1c86173 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -6,21 +6,17 @@ build_date := $(shell date -u +%FT%T) hadolint_available := $(shell hadolint --help > /dev/null 2>&1; echo $$?) hadolint_command := hadolint --ignore DL3008 --ignore DL3018 --ignore DL4000 --ignore DL4001 hadolint_container := hadolint/hadolint:latest +pwd := $(shell pwd) +export BUNDLE_PATH = $(pwd)/.bundle/gems +export BUNDLE_BIN = $(pwd)/.bundle/bin +export GEMFILE = $(pwd)/Gemfile -ifeq ($(IS_NIGHTLY),true) - dockerfile := Dockerfile.nightly - version := puppet6-nightly -else - version = $(shell echo $(git_describe) | sed 's/-.*//') - dockerfile := Dockerfile -endif - +version = $(shell echo $(git_describe) | sed 's/-.*//') +dockerfile := Dockerfile prep: -ifneq ($(IS_NIGHTLY),true) @git fetch --unshallow ||: @git fetch origin 'refs/tags/*:refs/tags/*' -endif lint: ifeq ($(hadolint_available),0) @@ -45,8 +41,10 @@ ifeq ($(IS_LATEST),true) endif test: prep - @bundle install --path .bundle/gems - @PUPPET_TEST_DOCKER_IMAGE=$(NAMESPACE)/r10k:$(version) bundle exec rspec r10k/spec + @bundle install --path $$BUNDLE_PATH --gemfile $$GEMFILE + @PUPPET_TEST_DOCKER_IMAGE=$(NAMESPACE)/r10k:$(version) \ + bundle exec --gemfile $$GEMFILE \ + rspec r10k/spec push-image: prep @docker push $(NAMESPACE)/r10k:$(version) diff --git a/docker/r10k/spec/dockerfile_spec.rb b/docker/r10k/spec/dockerfile_spec.rb index 156525ca9..d81ef48ab 100644 --- a/docker/r10k/spec/dockerfile_spec.rb +++ b/docker/r10k/spec/dockerfile_spec.rb @@ -5,10 +5,9 @@ SPEC_DIRECTORY = File.dirname(__FILE__) describe 'r10k container' do - include Helpers - + include Pupperware::SpecHelpers def run_r10k(command) - run_command("docker run --rm \ + run_command("docker run --detach \ --volume #{File.join(SPEC_DIRECTORY, 'fixtures')}:/test \ #{@image} #{command} \ --puppetfile /test/Puppetfile") @@ -33,12 +32,20 @@ def run_r10k(command) it 'should validate the Puppetfile' do result = run_r10k('puppetfile check') - expect(result[:status].exitstatus).to eq(0) + container = result[:stdout].chomp + wait_on_container_exit(container) + expect(get_container_exit_code(container)).to eq(0) + emit_log(container) + teardown_container(container) end it 'should install the Puppetfile' do result = run_r10k('puppetfile install') - expect(result[:status].exitstatus).to eq(0) + container = result[:stdout].chomp + wait_on_container_exit(container) + expect(get_container_exit_code(container)).to eq(0) expect(Dir.exist?(File.join(SPEC_DIRECTORY, 'fixtures', 'modules', 'ntp'))).to eq(true) + emit_log(container) + teardown_container(container) end end diff --git a/docker/r10k/spec/spec_helper.rb b/docker/r10k/spec/spec_helper.rb deleted file mode 100644 index 097cfdb63..000000000 --- a/docker/r10k/spec/spec_helper.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'open3' - -module Helpers - def run_command(command) - stdout_string = '' - status = nil - - Open3.popen3(command) do |stdin, stdout, stderr, wait_thread| - Thread.new do - stdout.each { |l| stdout_string << l; STDOUT.puts l } - end - Thread.new do - stderr.each { |l| STDOUT.puts l } - end - - stdin.close - status = wait_thread.value - end - - { status: status, stdout: stdout_string } - end -end