summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2016-12-16 13:24:03 +0100
committerAdam Niedzielski <adamsunday@gmail.com>2016-12-16 13:24:03 +0100
commitc945a0a7141ddf80e58e821178195cc48b8143f0 (patch)
tree9dcc3cdf890800b6c4a3ad006c04b0c1c2e6530a /app/models
parent45bd2263698892b9de6eb7956e3085a61054f49f (diff)
downloadgitlab-ce-c945a0a7141ddf80e58e821178195cc48b8143f0.tar.gz
Pass variables from deployment project services to CI runnerexpose-deployment-variables
This commit introduces the concept of deployment variables - variables that are collected from deployment services and passed to CI runner during a deployment build. Deployment services specify the variables by overriding "predefined_variables" method. This commit also configures variables for KubernetesService
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb3
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/project_services/deployment_service.rb4
-rw-r--r--app/models/project_services/kubernetes_service.rb10
4 files changed, 22 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index fdbf28a1d68..591aba6bdc9 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -155,7 +155,7 @@ module Ci
end
def has_environment?
- self.environment.present?
+ environment.present?
end
def starts_environment?
@@ -221,6 +221,7 @@ module Ci
variables += pipeline.predefined_variables
variables += runner.predefined_variables if runner
variables += project.container_registry_variables
+ variables += project.deployment_variables if has_environment?
variables += yaml_variables
variables += user_variables
variables += project.secret_variables
diff --git a/app/models/project.rb b/app/models/project.rb
index 2c726cfc5df..5f8058dac60 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1229,6 +1229,12 @@ class Project < ActiveRecord::Base
end
end
+ def deployment_variables
+ return [] unless deployment_service
+
+ deployment_service.predefined_variables
+ end
+
def append_or_update_attribute(name, value)
old_values = public_send(name.to_s)
diff --git a/app/models/project_services/deployment_service.rb b/app/models/project_services/deployment_service.rb
index 55e98c31251..da6be9dd7b7 100644
--- a/app/models/project_services/deployment_service.rb
+++ b/app/models/project_services/deployment_service.rb
@@ -8,4 +8,8 @@ class DeploymentService < Service
def supported_events
[]
end
+
+ def predefined_variables
+ []
+ end
end
diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb
index 80ae1191108..f5fbf8b353b 100644
--- a/app/models/project_services/kubernetes_service.rb
+++ b/app/models/project_services/kubernetes_service.rb
@@ -83,6 +83,16 @@ class KubernetesService < DeploymentService
{ success: false, result: err }
end
+ def predefined_variables
+ variables = [
+ { key: 'KUBE_URL', value: api_url, public: true },
+ { key: 'KUBE_TOKEN', value: token, public: false },
+ { key: 'KUBE_NAMESPACE', value: namespace, public: true }
+ ]
+ variables << { key: 'KUBE_CA_PEM', value: ca_pem, public: true } if ca_pem.present?
+ variables
+ end
+
private
def build_kubeclient(api_path = '/api', api_version = 'v1')