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

107 lines
2.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
module Clusters
module Applications
class Jupyter < ActiveRecord::Base
2018-11-18 11:00:15 +05:30
VERSION = 'v0.6'.freeze
2018-11-08 19:23:39 +05:30
self.table_name = 'clusters_applications_jupyter'
include ::Clusters::Concerns::ApplicationCore
include ::Clusters::Concerns::ApplicationStatus
2018-11-18 11:00:15 +05:30
include ::Clusters::Concerns::ApplicationVersion
2018-11-08 19:23:39 +05:30
include ::Clusters::Concerns::ApplicationData
belongs_to :oauth_application, class_name: 'Doorkeeper::Application'
default_value_for :version, VERSION
def set_initial_status
return unless not_installable?
2018-12-13 13:39:08 +05:30
if cluster&.application_ingress_available? && cluster.application_ingress.external_ip
2018-11-08 19:23:39 +05:30
self.status = 'installable'
end
end
def chart
"#{name}/jupyterhub"
end
def repository
'https://jupyterhub.github.io/helm-chart/'
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-11-08 19:23:39 +05:30
chart: chart,
2018-11-18 11:00:15 +05:30
files: files,
2018-11-08 19:23:39 +05:30
repository: repository
)
end
def callback_url
"http://#{hostname}/hub/oauth_callback"
end
private
def specification
{
"ingress" => {
2019-02-15 15:39:39 +05:30
"hosts" => [hostname],
"tls" => [{
"hosts" => [hostname],
"secretName" => "jupyter-cert"
}]
2018-11-08 19:23:39 +05:30
},
"hub" => {
"extraEnv" => {
"GITLAB_HOST" => gitlab_url
},
"cookieSecret" => cookie_secret
},
"proxy" => {
"secretToken" => secret_token
},
"auth" => {
"gitlab" => {
"clientId" => oauth_application.uid,
"clientSecret" => oauth_application.secret,
"callbackUrl" => callback_url
}
2018-12-05 23:21:45 +05:30
},
"singleuser" => {
"extraEnv" => {
"GITLAB_CLUSTER_ID" => cluster.id
}
2018-11-08 19:23:39 +05:30
}
}
end
def gitlab_url
Gitlab.config.gitlab.url
end
def content_values
YAML.load_file(chart_values_file).deep_merge!(specification)
end
def secret_token
@secret_token ||= SecureRandom.hex(32)
end
def cookie_secret
@cookie_secret ||= SecureRandom.hex(32)
end
end
end
end