summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-11-06 10:52:55 +0900
committerShinya Maeda <shinya@gitlab.com>2018-11-06 10:54:27 +0900
commit5f47ebaa6c8e675637459649e541c3a48f174cb5 (patch)
tree90b5223f742a6bb24b99bc50385d453a34882076
parentb3020aaffd1d04319c1d9a06b73a3dd7d93514de (diff)
downloadgitlab-ce-5f47ebaa6c8e675637459649e541c3a48f174cb5.tar.gz
Create deployments only if action: start
-rw-r--r--app/models/concerns/deployable.rb2
-rw-r--r--app/workers/build_success_worker.rb7
-rw-r--r--spec/models/concerns/deployable_spec.rb8
-rw-r--r--spec/workers/build_success_worker_spec.rb13
4 files changed, 29 insertions, 1 deletions
diff --git a/app/models/concerns/deployable.rb b/app/models/concerns/deployable.rb
index ba3abf28ab0..f4f1989f0a9 100644
--- a/app/models/concerns/deployable.rb
+++ b/app/models/concerns/deployable.rb
@@ -7,7 +7,7 @@ module Deployable
after_create :create_deployment
def create_deployment
- return unless has_environment? && !has_deployment?
+ return unless starts_environment? && !has_deployment?
environment = project.environments.find_or_create_by(
name: expanded_environment_name
diff --git a/app/workers/build_success_worker.rb b/app/workers/build_success_worker.rb
index f3530317090..4670cef1a58 100644
--- a/app/workers/build_success_worker.rb
+++ b/app/workers/build_success_worker.rb
@@ -10,6 +10,7 @@ class BuildSuccessWorker
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
create_deployment(build) if build.has_environment?
+ stop_environment(build) if build.stops_environment?
end
end
# rubocop: enable CodeReuse/ActiveRecord
@@ -26,4 +27,10 @@ class BuildSuccessWorker
deployment.succeed
end
end
+
+ ##
+ # TODO: This should be processed in DeploymentSuccessWorker once we started storing `action` value in `deployments` records
+ def stop_environment(build)
+ build.persisted_environment.stop
+ end
end
diff --git a/spec/models/concerns/deployable_spec.rb b/spec/models/concerns/deployable_spec.rb
index e30e9689717..ac79c75a55e 100644
--- a/spec/models/concerns/deployable_spec.rb
+++ b/spec/models/concerns/deployable_spec.rb
@@ -24,6 +24,14 @@ describe Deployable do
end
end
+ context 'when the deployable object will stop an environment' do
+ let!(:job) { create(:ci_build, :stop_review_app) }
+
+ it 'does not create a deployment record' do
+ expect(deployment).to be_nil
+ end
+ end
+
context 'when the deployable object has already had a deployment' do
let!(:job) { create(:ci_build, :start_review_app, deployment: race_deployment) }
let!(:race_deployment) { create(:deployment, :success) }
diff --git a/spec/workers/build_success_worker_spec.rb b/spec/workers/build_success_worker_spec.rb
index 8e9b178728e..5eb9709ded9 100644
--- a/spec/workers/build_success_worker_spec.rb
+++ b/spec/workers/build_success_worker_spec.rb
@@ -47,6 +47,19 @@ describe BuildSuccessWorker do
expect(build.reload).not_to be_has_deployment
end
end
+
+ context 'when the build will stop an environment' do
+ let!(:build) { create(:ci_build, :stop_review_app, environment: environment.name, project: environment.project) }
+ let(:environment) { create(:environment, state: :available) }
+
+ it 'stops the environment' do
+ expect(environment).to be_available
+
+ subject
+
+ expect(environment.reload).to be_stopped
+ end
+ end
end
context 'when build does not exist' do