diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-19 11:22:51 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-19 11:22:51 +0000 |
commit | c20e4267e89c1fa84b3eeb9f63e17677388c25e3 (patch) | |
tree | bc1eac011692f0ade7fa9d802f63be9d29fa449a /app | |
parent | 6a9d87b523b2db9561d70fce1c19584c90b289a8 (diff) | |
parent | 4939911e96297aa6ed9fb60f635d7d16a360876f (diff) | |
download | gitlab-ce-c20e4267e89c1fa84b3eeb9f63e17677388c25e3.tar.gz |
Merge branch 'review-apps' into 'master'
Add support for dynamic environments
Implements proposal described in https://gitlab.com/gitlab-org/gitlab-ce/issues/21971.
Specifically:
- it adds a `.gitlab-ci.yml` configuration,
- it allows environment name to have slashes,
- it allows environment names to use CI predefined variables,
- it allows to specify URL from `.gitlab-ci.yml`,
- it allows the URL to use CI predefined variables,
- it introduces `environment_type` to allow to easily group environments in the future
See merge request !6323
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 13 | ||||
-rw-r--r-- | app/models/environment.rb | 12 | ||||
-rw-r--r-- | app/services/create_deployment_service.rb | 38 |
3 files changed, 55 insertions, 8 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index fb16bc06d71..d5724af4cce 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -79,11 +79,14 @@ module Ci after_transition any => [:success] do |build| if build.environment.present? - service = CreateDeploymentService.new(build.project, build.user, - environment: build.environment, - sha: build.sha, - ref: build.ref, - tag: build.tag) + service = CreateDeploymentService.new( + build.project, build.user, + environment: build.environment, + sha: build.sha, + ref: build.ref, + tag: build.tag, + options: build.options[:environment], + variables: build.variables) service.execute(build) end end diff --git a/app/models/environment.rb b/app/models/environment.rb index 75e6f869786..33c9abf382a 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -4,6 +4,7 @@ class Environment < ActiveRecord::Base has_many :deployments before_validation :nullify_external_url + before_save :set_environment_type validates :name, presence: true, @@ -26,6 +27,17 @@ class Environment < ActiveRecord::Base self.external_url = nil if self.external_url.blank? end + def set_environment_type + names = name.split('/') + + self.environment_type = + if names.many? + names.first + else + nil + end + end + def includes_commit?(commit) return false unless last_deployment diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb index efeb9df9527..e6667132e27 100644 --- a/app/services/create_deployment_service.rb +++ b/app/services/create_deployment_service.rb @@ -2,9 +2,7 @@ require_relative 'base_service' class CreateDeploymentService < BaseService def execute(deployable = nil) - environment = project.environments.find_or_create_by( - name: params[:environment] - ) + environment = find_or_create_environment project.deployments.create( environment: environment, @@ -15,4 +13,38 @@ class CreateDeploymentService < BaseService deployable: deployable ) end + + private + + def find_or_create_environment + project.environments.find_or_create_by(name: expanded_name) do |environment| + environment.external_url = expanded_url + end + end + + def expanded_name + ExpandVariables.expand(name, variables) + end + + def expanded_url + return unless url + + @expanded_url ||= ExpandVariables.expand(url, variables) + end + + def name + params[:environment] + end + + def url + options[:url] + end + + def options + params[:options] || {} + end + + def variables + params[:variables] || [] + end end |