diff --git a/.travis.yml b/.travis.yml index 6d533916..90fd5471 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,14 +12,11 @@ addons: before_install: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start -# Config to run docker tests - doesn't work so far -# - sudo apt-get update -# - sudo apt-get upgrade lxc-docker -# - echo 'DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock --iptables=false"' | sudo tee /etc/default/docker > /dev/null -# - export DOCKER_HOST=tcp://192.168.23.75:2375 -# - sudo service docker restart -# - sleep 5 -# - docker pull openhpi/docker_ruby + - echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2376 -H unix:///var/run/docker.sock --iptables=false"' | sudo tee /etc/default/docker > /dev/null + - sudo service docker restart + - sleep 5 + - docker pull openhpi/co_execenv_python + - docker pull openhpi/co_execenv_java before_script: - cp .rspec.travis .rspec @@ -27,6 +24,7 @@ before_script: - cp config/code_ocean.yml.travis config/code_ocean.yml - cp config/database.yml.travis config/database.yml - cp config/secrets.yml.travis config/secrets.yml + - cp config/docker.yml.erb.travis config/docker.yml.erb - psql --command='CREATE DATABASE travis_ci_test;' --username=postgres - bundle exec rake db:schema:load RAILS_ENV=test @@ -35,8 +33,4 @@ language: ruby rvm: - 2.3.6 -script: bundle exec rspec --color --format documentation --require spec_helper --require rails_helper --tag ~docker && bundle exec codeclimate-test-reporter -# one of the solutions I've found -# - sudo docker run --rm=true -v `pwd`:/ansible-apache:rw weldpua2008/docker-ansible:${OS_TYPE}${OS_VERSION}_v${ANSIBLE_VERSION} /bin/bash -c "/ansible-apache/tests/test-in-docker-image.sh ${OS_TYPE} ${OS_VERSION} ${ANSIBLE_VERSION}" - - +script: bundle exec rspec --color --format documentation --require spec_helper --require rails_helper && bundle exec codeclimate-test-reporter diff --git a/app/models/execution_environment.rb b/app/models/execution_environment.rb index 74177173..9cd23a48 100644 --- a/app/models/execution_environment.rb +++ b/app/models/execution_environment.rb @@ -47,7 +47,7 @@ class ExecutionEnvironment < ActiveRecord::Base private :validate_docker_image? def working_docker_image? - DockerClient.pull(docker_image) unless DockerClient.image_tags.include?(docker_image) + DockerClient.pull(docker_image) unless DockerClient.find_image_by_tag(docker_image).blank? output = DockerClient.new(execution_environment: self).execute_arbitrary_command(VALIDATION_COMMAND) errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present? rescue DockerClient::Error => error diff --git a/config/docker.yml.erb.example b/config/docker.yml.erb.example index 9f55d126..eb1af61e 100644 --- a/config/docker.yml.erb.example +++ b/config/docker.yml.erb.example @@ -34,7 +34,21 @@ production: ws_host: ws://localhost:4243 #url to connect rails server to docker host ws_client_protocol: wss:// #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) +staging: + <<: *default + host: unix:///var/run/docker.sock + pool: + active: true + refill: + async: false + batch_size: 8 + interval: 15 + timeout: 60 + workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> + ws_host: ws://localhost:4243 #url to connect rails server to docker host + ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) + test: <<: *default - host: tcp://192.168.59.104:2376 + host: tcp://127.0.0.1:2376 workspace_root: <%= File.join('/', 'shared', Rails.env) %> diff --git a/config/docker.yml.erb b/config/docker.yml.erb.travis similarity index 94% rename from config/docker.yml.erb rename to config/docker.yml.erb.travis index c1871de7..eb1af61e 100644 --- a/config/docker.yml.erb +++ b/config/docker.yml.erb.travis @@ -32,7 +32,7 @@ production: timeout: 60 workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> ws_host: ws://localhost:4243 #url to connect rails server to docker host - ws_client_protocol: 'wss:' #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) + ws_client_protocol: wss:// #set the websocket protocol to be used by the client to connect to the rails server (ws on development, wss on production) staging: <<: *default @@ -50,5 +50,5 @@ staging: test: <<: *default - host: tcp://192.168.59.104:2376 + host: tcp://127.0.0.1:2376 workspace_root: <%= File.join('/', 'shared', Rails.env) %> diff --git a/public/uploads/files/4/chai.ogg b/public/uploads/files/4/chai.ogg deleted file mode 100644 index 86190d0c..00000000 Binary files a/public/uploads/files/4/chai.ogg and /dev/null differ diff --git a/public/uploads/files/5/devstories.mp4 b/public/uploads/files/5/devstories.mp4 deleted file mode 100644 index 9e7d328d..00000000 Binary files a/public/uploads/files/5/devstories.mp4 and /dev/null differ diff --git a/public/uploads/files/6/devstories.webm b/public/uploads/files/6/devstories.webm deleted file mode 100644 index 84fff0ed..00000000 Binary files a/public/uploads/files/6/devstories.webm and /dev/null differ diff --git a/public/uploads/files/7/poster.png b/public/uploads/files/7/poster.png deleted file mode 100644 index d950cef4..00000000 Binary files a/public/uploads/files/7/poster.png and /dev/null differ diff --git a/spec/concerns/lti_spec.rb b/spec/concerns/lti_spec.rb index a7b1dfcc..4fb8dc5f 100644 --- a/spec/concerns/lti_spec.rb +++ b/spec/concerns/lti_spec.rb @@ -98,7 +98,7 @@ describe Lti do let(:consumer) { FactoryBot.create(:consumer) } let(:score) { 0.5 } let(:submission) { FactoryBot.create(:submission) } - let!(:lti_parameter) { FactoryBot.create(:lti_parameter)} + let!(:lti_parameter) { FactoryBot.create(:lti_parameter, consumers_id: consumer.id, external_users_id: submission.user_id, exercises_id: submission.exercise_id)} context 'with an invalid score' do it 'raises an exception' do @@ -114,7 +114,6 @@ describe Lti do context 'when grading is not supported' do it 'returns a corresponding status' do - skip('ralf: this does not work, since send_score pulls data from the database, which then returns an empty array. On this is called .first, which returns nil and lets the test fail. Before Toms changes, this was taken from the session, which could be mocked') expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false) expect(controller.send(:send_score, submission.exercise_id, score, submission.user_id)[:status]).to eq('unsupported') end @@ -133,12 +132,10 @@ describe Lti do end it 'sends the score' do - skip('ralf: this does not work, since send_score pulls data from the database, which then returns an empty array. On this is called .first, which returns nil and lets the test fail. Before Toms changes, this was taken from the session, which could be mocked') controller.send(:send_score, submission.exercise_id, score, submission.user_id) end it 'returns code, message, and status' do - skip('ralf: this does not work, since send_score pulls data from the database, which then returns an empty array. On this is called .first, which returns nil and lets the test fail. Before Toms changes, this was taken from the session, which could be mocked') result = controller.send(:send_score, submission.exercise_id, score, submission.user_id) expect(result[:code]).to eq(response.response_code) expect(result[:message]).to eq(response.body) diff --git a/spec/factories/user_exercise_feedback.rb b/spec/factories/user_exercise_feedback.rb index 42c5d803..3c43158f 100644 --- a/spec/factories/user_exercise_feedback.rb +++ b/spec/factories/user_exercise_feedback.rb @@ -2,6 +2,7 @@ FactoryBot.define do factory :user_exercise_feedback, class: UserExerciseFeedback do created_by_external_user feedback_text 'Most suitable exercise ever' + association :exercise, factory: :math end end diff --git a/spec/lib/docker_client_spec.rb b/spec/lib/docker_client_spec.rb index 5901c130..5d1118bd 100644 --- a/spec/lib/docker_client_spec.rb +++ b/spec/lib/docker_client_spec.rb @@ -2,12 +2,22 @@ require 'rails_helper' require 'seeds_helper' describe DockerClient, docker: true do + WORKSPACE_PATH = '/tmp/code_ocean_test' + let(:command) { 'whoami' } let(:docker_client) { described_class.new(execution_environment: FactoryBot.build(:java), user: FactoryBot.build(:admin)) } let(:execution_environment) { FactoryBot.build(:java) } let(:image) { double } let(:submission) { FactoryBot.create(:submission) } - let(:workspace_path) { '/tmp' } + let(:workspace_path) { WORKSPACE_PATH } + + before(:all) do + FileUtils.mkdir_p(WORKSPACE_PATH) + end + + after(:all) do + FileUtils.rm_rf(WORKSPACE_PATH) + end describe '.check_availability!' do context 'when a socket error occurs' do @@ -129,7 +139,7 @@ describe DockerClient, docker: true do after(:each) { docker_client.send(:create_workspace_files, container, submission) } it 'creates submission-specific directories' do - expect(Dir).to receive(:mkdir).at_least(:once) + expect(Dir).to receive(:mkdir).at_least(:once).and_call_original end it 'copies binary files' do diff --git a/test/factories/error_template_attributes.rb b/test/factories/error_template_attributes.rb index 84e65757..2e867ec5 100644 --- a/test/factories/error_template_attributes.rb +++ b/test/factories/error_template_attributes.rb @@ -1,6 +1,5 @@ FactoryBot.define do factory :error_template_attribute do - error_template nil key "MyString" regex "MyString" end