debian-mirror-gitlab/app/models/clusters/applications/runner.rb

84 lines
1.9 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
module Clusters
module Applications
class Runner < ActiveRecord::Base
2019-02-15 15:39:39 +05:30
VERSION = '0.1.43'.freeze
2018-03-27 19:54:05 +05:30
self.table_name = 'clusters_applications_runners'
include ::Clusters::Concerns::ApplicationCore
include ::Clusters::Concerns::ApplicationStatus
2018-11-18 11:00:15 +05:30
include ::Clusters::Concerns::ApplicationVersion
2018-03-27 19:54:05 +05:30
include ::Clusters::Concerns::ApplicationData
belongs_to :runner, class_name: 'Ci::Runner', foreign_key: :runner_id
delegate :project, to: :cluster
default_value_for :version, VERSION
def chart
"#{name}/gitlab-runner"
end
def repository
'https://charts.gitlab.io'
end
def values
content_values.to_yaml
end
def install_command
Gitlab::Kubernetes::Helm::InstallCommand.new(
2018-11-18 11:00:15 +05:30
name: name,
version: VERSION,
2018-11-20 20:47:30 +05:30
rbac: cluster.platform_kubernetes_rbac?,
2018-03-27 19:54:05 +05:30
chart: chart,
2018-11-18 11:00:15 +05:30
files: files,
2018-03-27 19:54:05 +05:30
repository: repository
)
end
private
def ensure_runner
runner || create_and_assign_runner
end
def create_and_assign_runner
transaction do
2018-11-08 19:23:39 +05:30
Ci::Runner.create!(runner_create_params).tap do |runner|
2018-03-27 19:54:05 +05:30
update!(runner_id: runner.id)
end
end
end
2018-10-15 14:42:47 +05:30
def runner_create_params
{
name: 'kubernetes-cluster',
runner_type: :project_type,
2018-11-08 19:23:39 +05:30
tag_list: %w(kubernetes cluster),
projects: [project]
2018-10-15 14:42:47 +05:30
}
end
2018-03-27 19:54:05 +05:30
def gitlab_url
Gitlab::Routing.url_helpers.root_url(only_path: false)
end
def specification
{
"gitlabUrl" => gitlab_url,
"runnerToken" => ensure_runner.token,
"runners" => { "privileged" => privileged }
}
end
def content_values
YAML.load_file(chart_values_file).deep_merge!(specification)
end
end
end
end