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

127 lines
3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-09-04 21:01:54 +05:30
require 'securerandom'
2018-11-08 19:23:39 +05:30
module Clusters
module Applications
2019-07-07 11:18:12 +05:30
class Jupyter < ApplicationRecord
2020-05-24 23:13:21 +05:30
VERSION = '0.9.0'
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?
2019-07-07 11:18:12 +05:30
return unless cluster&.application_ingress_available?
2018-11-08 19:23:39 +05:30
2019-07-07 11:18:12 +05:30
ingress = cluster.application_ingress
2019-12-21 20:55:43 +05:30
self.status = status_states[:installable] if ingress.external_ip_or_hostname?
2018-11-08 19:23:39 +05:30
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,
2020-10-24 23:57:45 +05:30
repository: repository
2018-11-08 19:23:39 +05:30
)
end
def callback_url
"http://#{hostname}/hub/oauth_callback"
end
2019-09-04 21:01:54 +05:30
def oauth_scopes
'api read_repository write_repository'
end
2018-11-08 19:23:39 +05:30
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" => {
2019-09-04 21:01:54 +05:30
"state" => {
"cryptoKey" => crypto_key
},
2018-11-08 19:23:39 +05:30
"gitlab" => {
"clientId" => oauth_application.uid,
"clientSecret" => oauth_application.secret,
2019-07-07 11:18:12 +05:30
"callbackUrl" => callback_url,
2019-12-04 20:38:33 +05:30
"gitlabProjectIdWhitelist" => cluster.projects.ids,
"gitlabGroupWhitelist" => cluster.groups.map(&:to_param)
2018-11-08 19:23:39 +05:30
}
2018-12-05 23:21:45 +05:30
},
"singleuser" => {
"extraEnv" => {
2019-09-04 21:01:54 +05:30
"GITLAB_CLUSTER_ID" => cluster.id.to_s,
"GITLAB_HOST" => gitlab_host
2018-12-05 23:21:45 +05:30
}
2018-11-08 19:23:39 +05:30
}
}
end
2019-09-04 21:01:54 +05:30
def crypto_key
@crypto_key ||= SecureRandom.hex(32)
end
2018-11-08 19:23:39 +05:30
def gitlab_url
Gitlab.config.gitlab.url
end
2019-09-04 21:01:54 +05:30
def gitlab_host
Gitlab.config.gitlab.host
end
2018-11-08 19:23:39 +05:30
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