From 8975261ddb090e4f3fe99bd166b0e4cf819488d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Fern=C3=A1ndez?= Date: Fri, 2 Aug 2019 12:12:36 -0400 Subject: [PATCH 1/4] test(potassium-test-helpers): add helper to cleanup db docker containers --- spec/support/potassium_test_helpers.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/support/potassium_test_helpers.rb b/spec/support/potassium_test_helpers.rb index 3a937922..13aeb346 100644 --- a/spec/support/potassium_test_helpers.rb +++ b/spec/support/potassium_test_helpers.rb @@ -47,6 +47,10 @@ def on_project(&block) end end + def docker_cleanup + run_command(`docker-compose -f #{project_path}/docker-compose.yml down --volumes`) + end + private def tmp_path From 673bbc0e1dab1c17a340ff66aa1174b7891ee9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Fern=C3=A1ndez?= Date: Fri, 2 Aug 2019 12:13:03 -0400 Subject: [PATCH 2/4] test(spec-helper): cleanup docker env after each test --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d0cf156..4ebc5d42 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,10 @@ create_tmp_directory end + config.after(:each) do + docker_cleanup + end + config.before(:each) do FakeGithub.clear! FakeHeroku.clear! From 3bddddc20596bec13939c05c4943e7430ba91e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Fern=C3=A1ndez?= Date: Fri, 2 Aug 2019 12:13:50 -0400 Subject: [PATCH 3/4] refactor(database-container): remove unnecessary after block --- spec/features/database_container_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/features/database_container_spec.rb b/spec/features/database_container_spec.rb index 157888b2..1d2e9bc8 100644 --- a/spec/features/database_container_spec.rb +++ b/spec/features/database_container_spec.rb @@ -11,10 +11,6 @@ create_dummy_project("database" => database) end - after do - `docker-compose -f #{project_path}/docker-compose.yml down` - end - [:postgresql, :mysql].each do |db_type| context "when database is #{db_type}" do let!(:database) { db_type } From 07de3d21760f97c61ae585e056f42cd79b473600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Fern=C3=A1ndez?= Date: Fri, 2 Aug 2019 12:14:25 -0400 Subject: [PATCH 4/4] chore(cibuild): remove one-off containers after execution --- lib/potassium/assets/bin/cibuild.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/potassium/assets/bin/cibuild.erb b/lib/potassium/assets/bin/cibuild.erb index 351f8e3d..db09f633 100644 --- a/lib/potassium/assets/bin/cibuild.erb +++ b/lib/potassium/assets/bin/cibuild.erb @@ -15,7 +15,7 @@ build(){ # Wait services to be ready wait_services(){ function test_service { - docker-compose $DOCKER_COMPOSE_ARGS run test sh -c "nc -z $1 $2" + docker-compose $DOCKER_COMPOSE_ARGS run --rm test sh -c "nc -z $1 $2" } count=0 @@ -41,16 +41,16 @@ wait_services(){ # Prepare dependencies dependencies(){ - docker-compose $DOCKER_COMPOSE_ARGS run test bundle install + docker-compose $DOCKER_COMPOSE_ARGS run --rm test bundle install } assets() { - docker-compose $DOCKER_COMPOSE_ARGS run test /bin/bash -c "bin/setup && bundle exec rake assets:precompile" + docker-compose $DOCKER_COMPOSE_ARGS run --rm test /bin/bash -c "bin/setup && bundle exec rake assets:precompile" } # Prepare database database(){ - docker-compose $DOCKER_COMPOSE_ARGS run test bundle exec rake db:create db:schema:load + docker-compose $DOCKER_COMPOSE_ARGS run --rm test bundle exec rake db:create db:schema:load } # Run the specs @@ -59,7 +59,7 @@ tests(){ RSPEC_JUNIT_ARGS="-r rspec_junit_formatter --format RspecJunitFormatter -o $HOME/.rspec_reports/junit.xml" RSPEC_FORMAT_ARGS="--format progress --no-color" } - docker-compose $DOCKER_COMPOSE_ARGS run test bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS + docker-compose $DOCKER_COMPOSE_ARGS run --rm test bundle exec rspec spec $RSPEC_FORMAT_ARGS $RSPEC_JUNIT_ARGS } # Run the complete ci build