Skip to content

Commit

Permalink
Implement integration tests running inside Docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeykot committed Aug 23, 2018
1 parent 756bfda commit 62f8231
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -1,7 +1,10 @@
tmp/*
!tmp/.keep
log/*
!log/.keep
.git
Dockerfile
Dockerfile.test
Jenkinsfile
.codeclimate.yml
.travis.yml
Expand Down
60 changes: 60 additions & 0 deletions Dockerfile.test
@@ -0,0 +1,60 @@
FROM registry.scc.suse.de/suse/sles15:ga

RUN useradd --no-log-init --create-home scc

ARG REGCODE
RUN SUSEConnect -r $REGCODE
RUN zypper --non-interactive ar http://download.opensuse.org/repositories/openSUSE:/Tools/SLE_15/openSUSE:Tools.repo
RUN zypper --non-interactive --gpg-auto-import-keys ref
RUN zypper --non-interactive up
RUN zypper --non-interactive in -t pattern devel_osc_build
RUN zypper --non-interactive install --no-recommend wget curl timezone \
gcc-c++ libffi-devel git-core zlib-devel libxml2-devel libxslt-devel libmariadb-devel \
mariadb-client ruby2.5-rubygem-bundler make build sudo ruby-devel


ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

ARG OBS_USER
ARG OBS_PASSWORD
RUN printf "[general]\n\
build-root = /oscbuild/%(repo)s-%(arch)s\n\
packagecachedir = /oscbuild/packagecache\n\
[https://api.suse.de]\n\
user=$OBS_USER\n\
pass=$OBS_PASSWORD\n\
sslcertck = 0\n\
trusted_prj=SLE_12 SUSE:SLE-12:GA\n\
[https://api.opensuse.org]\n\
user=$OBS_USER\n\
pass=$OBS_PASSWORD\n\
sslcertck = 0\n\
trusted_prj=SLE_12 SUSE:SLE-12:GA\n\
" >> ~/.oscrc

RUN mkdir /tmp/rmt-server
WORKDIR /tmp/rmt-server
ADD . /tmp/rmt-server
RUN chown -R scc /tmp/rmt-server
ARG MYSQL_HOST
ARG MYSQL_USER
ARG MYSQL_PASSWORD
ARG MYSQL_DATABASE
ARG SCC_USERNAME
ARG SCC_PASSWORD
RUN printf "database:\n\
host: $MYSQL_HOST\n\
username: $MYSQL_USER\n\
password: $MYSQL_PASSWORD\n\
database: $MYSQL_DATABASE\n\
scc:\n\
username: $SCC_USERNAME\n\
password: $SCC_PASSWORD\n\
" >> /etc/rmt.conf

RUN bundle

CMD dockerize -wait tcp://$MYSQL_HOST:3306 -timeout 60s true
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -59,6 +59,7 @@ group :development do
end

group :test do
gem 'rspec-command'
gem 'rspec-rails', '~> 3.5'
gem 'factory_girl_rails', '4.8.0'
gem 'ffaker'
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Expand Up @@ -122,7 +122,7 @@ GEM
faraday (~> 0.8)
fast_gettext (1.6.0)
ffaker (2.8.1)
ffi (1.9.21)
ffi (1.9.25)
formatador (0.2.5)
fuubar (2.3.1)
rspec-core (~> 3.0)
Expand Down Expand Up @@ -169,6 +169,7 @@ GEM
method_source (0.9.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
mixlib-shellout (2.4.0)
multipart-post (2.0.0)
mustache (1.0.5)
mysql2 (0.4.10)
Expand Down Expand Up @@ -223,6 +224,10 @@ GEM
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-command (1.0.3)
mixlib-shellout (~> 2.0)
rspec (~> 3.2)
rspec-its (~> 1.2)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
Expand Down Expand Up @@ -337,6 +342,7 @@ DEPENDENCIES
railties (~> 5.1.3)
responders
ronn
rspec-command
rspec-its
rspec-rails (~> 3.5)
ruby_parser
Expand All @@ -356,4 +362,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.16.1
1.16.2
44 changes: 44 additions & 0 deletions docker-compose-test.yml
@@ -0,0 +1,44 @@
version: '2'
volumes:
db_storage:
driver: local
networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1350

services:
db:
image: mariadb:10.2
restart: always
volumes:
- db_storage:/var/lib/mysql
extends:
service: base
file: docker-compose-base.yml

rmt_test:
privileged: true
build:
context: .
dockerfile: Dockerfile.test
args:
REGCODE: ${REGCODE}
OBS_USER: ${OBS_USER}
OBS_PASSWORD: ${OBS_PASSWORD}
SCC_USERNAME: ${SCC_USERNAME}
SCC_PASSWORD: ${SCC_PASSWORD}
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
environment:
- MYSQL_HOST=db
- SECRET_KEY_BASE=8ea53ad3bc6c03923e376c8bdd85059c1885524947a7efe53d5e9c9d4e39861106ffd6a2ece82b803072ed701e6c960bade91644979e679416c5f255007237ae
depends_on:
- db
extends:
service: base
file: docker-compose-base.yml
command: /bin/bash -c 'bundle.ruby2.5 exec rails db:migrate'
17 changes: 17 additions & 0 deletions features/lockfile_spec.rb
@@ -0,0 +1,17 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'rmt-cli' do
before(:example) { system '/usr/bin/rmt-cli sync > /dev/null &' }
# kill running process to let further specs pass
after(:example) { system 'kill -9 $(cat /tmp/rmt.lock)' }

describe 'lockfile' do
command '/usr/bin/rmt-cli sync', allow_error: true

its(:stderr) { is_expected.to eq("Process is locked by the application with \
pid #{File.read('/tmp/rmt.lock')}. Close this application or wait for it \
to finish before trying again\n") }

its(:exitstatus) { is_expected.to eq 1 }
end
end
6 changes: 6 additions & 0 deletions features/mirror_spec.rb
@@ -0,0 +1,6 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'mirror' do
command '/usr/bin/rmt-cli mirror'
its(:exitstatus) { is_expected.to eq 0 }
end
8 changes: 8 additions & 0 deletions features/repos_spec.rb
@@ -0,0 +1,8 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

[3114, 3115, 3116, 2705, 2707].each do |repo_id|
describe 'enable repos' do
command "/usr/bin/rmt-cli repos enable #{repo_id}"
its(:stdout) { is_expected.to eq("Repository successfully enabled.\n") }
end
end
5 changes: 5 additions & 0 deletions features/support/command_rspec_helper.rb
@@ -0,0 +1,5 @@
require 'rspec_command'

RSpec.configure do |config|
config.include RSpecCommand
end
13 changes: 13 additions & 0 deletions features/sync_spec.rb
@@ -0,0 +1,13 @@
require File.expand_path('../support/command_rspec_helper', __FILE__)

describe 'rmt-cli' do
describe 'sync' do
command '/usr/bin/rmt-cli sync'
its(:exitstatus) { is_expected.to eq 0 }
its(:stdout) { is_expected.to include("INFO -- : Cleaning up the database\n") }
its(:stdout) { is_expected.to include("INFO -- : Downloading data from SCC\n") }
its(:stdout) { is_expected.to include("INFO -- : Updating products\n") }
its(:stdout) { is_expected.to include("INFO -- : Updating repositories\n") }
its(:stdout) { is_expected.to include("INFO -- : Updating subscriptions\n") }
end
end
14 changes: 14 additions & 0 deletions integration.sh
@@ -0,0 +1,14 @@
#!/bin/sh -xe
make dist
mkdir ~/obs
cd ~/obs
osc co systemsmanagement:SCC:RMT rmt-server
cd /tmp/rmt-server/package
cp * ~/obs/systemsmanagement:SCC:RMT/rmt-server
cd ~/obs/systemsmanagement:SCC:RMT/rmt-server && osc build SLE_15 x86_64 --no-verify --trust-all-projects && cd .. &&
zypper --non-interactive --no-gpg-checks in /oscbuild/SLE_15-x86_64/home/abuild/rpmbuild/RPMS/x86_64/*
cd /tmp/rmt-server/
cp /etc/rmt.conf config/rmt.yml
RAILS_ENV=production /usr/share/rmt/bin/rails db:create db:migrate
/usr/bin/rmt-cli sync
NO_COVERAGE=true rspec features/
34 changes: 34 additions & 0 deletions integration/Jenkinsfile
@@ -0,0 +1,34 @@
pipeline {
agent {
label 'scc-happy-customer'
}

stages {
stage('checkout') {
steps {
script {
currentBuild.displayName = "#${BUILD_NUMBER}: ${branch}"
}

git url: 'git@github.com:SUSE/rmt.git', branch: "${branch}"
}
}
stage('docker-compose build') {
steps {
sh 'docker-compose -f docker-compose-test.yml build'
}
}

stage('rmt integration tests') {
steps {
sh 'docker-compose -f docker-compose-test.yml run rmt_test ./integration.sh'
}
}
}
post {
always {
sh 'docker-compose down'
sh 'docker system prune -f'
}
}
}
18 changes: 18 additions & 0 deletions lib/tasks/package.rake
@@ -0,0 +1,18 @@
namespace :package do
package_dir = 'package/'
package_name = 'rmt-server'
obs_project = 'systemsmanagement:SCC:RMT'
local_spec_file = "#{package_name}.spec"
root_path = File.join(File.dirname(__FILE__), '../..')

desc 'Checkout from OBS'
task :checkout do
Dir.chdir "#{root_path}/#{package_dir}" do
unless Dir['.osc'].any?
sh 'mkdir .tmp; mv * .tmp/'
sh "osc co #{obs_project} #{package_name} -o ."
puts 'Checkout successful.' if $CHILD_STATUS.exitstatus.zero?
end
end
end
end

0 comments on commit 62f8231

Please sign in to comment.