2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-22 16:16:17 -04:00
|
|
|
require 'securerandom'
|
|
|
|
|
2018-05-11 09:29:55 -04:00
|
|
|
module Clusters
|
|
|
|
module Applications
|
2019-03-28 09:17:42 -04:00
|
|
|
class Jupyter < ApplicationRecord
|
2019-03-07 10:14:22 -05:00
|
|
|
VERSION = '0.9-174bbd5'.freeze
|
2018-05-11 09:29:55 -04:00
|
|
|
|
2018-05-30 05:09:12 -04:00
|
|
|
self.table_name = 'clusters_applications_jupyter'
|
2018-05-11 09:29:55 -04:00
|
|
|
|
|
|
|
include ::Clusters::Concerns::ApplicationCore
|
|
|
|
include ::Clusters::Concerns::ApplicationStatus
|
2018-07-22 06:48:53 -04:00
|
|
|
include ::Clusters::Concerns::ApplicationVersion
|
2018-05-11 09:29:55 -04:00
|
|
|
include ::Clusters::Concerns::ApplicationData
|
|
|
|
|
2018-05-24 11:11:30 -04:00
|
|
|
belongs_to :oauth_application, class_name: 'Doorkeeper::Application'
|
|
|
|
|
2018-05-11 09:29:55 -04:00
|
|
|
default_value_for :version, VERSION
|
|
|
|
|
2018-05-25 08:44:37 -04:00
|
|
|
def set_initial_status
|
|
|
|
return unless not_installable?
|
2019-03-07 16:51:43 -05:00
|
|
|
return unless cluster&.application_ingress_available?
|
2018-05-25 08:44:37 -04:00
|
|
|
|
2019-03-07 16:51:43 -05:00
|
|
|
ingress = cluster.application_ingress
|
2019-07-02 08:59:59 -04:00
|
|
|
self.status = 'installable' if ingress.external_ip_or_hostname?
|
2018-05-25 08:44:37 -04:00
|
|
|
end
|
|
|
|
|
2018-05-11 09:29:55 -04:00
|
|
|
def chart
|
2018-05-16 05:01:13 -04:00
|
|
|
"#{name}/jupyterhub"
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository
|
|
|
|
'https://jupyterhub.github.io/helm-chart/'
|
|
|
|
end
|
|
|
|
|
|
|
|
def values
|
|
|
|
content_values.to_yaml
|
2018-05-11 09:29:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def install_command
|
|
|
|
Gitlab::Kubernetes::Helm::InstallCommand.new(
|
2018-08-07 08:39:38 -04:00
|
|
|
name: name,
|
2018-07-22 06:48:53 -04:00
|
|
|
version: VERSION,
|
2018-09-06 06:03:38 -04:00
|
|
|
rbac: cluster.platform_kubernetes_rbac?,
|
2018-05-11 09:29:55 -04:00
|
|
|
chart: chart,
|
2018-08-07 08:39:38 -04:00
|
|
|
files: files,
|
2018-05-16 05:01:13 -04:00
|
|
|
repository: repository
|
2018-05-11 09:29:55 -04:00
|
|
|
)
|
|
|
|
end
|
2018-05-16 05:01:13 -04:00
|
|
|
|
2018-05-24 11:11:30 -04:00
|
|
|
def callback_url
|
|
|
|
"http://#{hostname}/hub/oauth_callback"
|
|
|
|
end
|
|
|
|
|
2019-06-05 15:50:29 -04:00
|
|
|
def oauth_scopes
|
|
|
|
'api read_repository write_repository'
|
|
|
|
end
|
|
|
|
|
2018-05-16 05:01:13 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def specification
|
|
|
|
{
|
2018-05-24 11:11:30 -04:00
|
|
|
"ingress" => {
|
2018-12-03 05:16:38 -05:00
|
|
|
"hosts" => [hostname],
|
|
|
|
"tls" => [{
|
|
|
|
"hosts" => [hostname],
|
|
|
|
"secretName" => "jupyter-cert"
|
|
|
|
}]
|
2018-05-24 11:11:30 -04:00
|
|
|
},
|
|
|
|
"hub" => {
|
|
|
|
"extraEnv" => {
|
|
|
|
"GITLAB_HOST" => gitlab_url
|
|
|
|
},
|
2018-05-25 10:09:26 -04:00
|
|
|
"cookieSecret" => cookie_secret
|
2018-05-24 11:11:30 -04:00
|
|
|
},
|
|
|
|
"proxy" => {
|
2018-05-25 10:09:26 -04:00
|
|
|
"secretToken" => secret_token
|
2018-05-24 11:11:30 -04:00
|
|
|
},
|
|
|
|
"auth" => {
|
2019-05-22 16:16:17 -04:00
|
|
|
"state" => {
|
|
|
|
"cryptoKey" => crypto_key
|
|
|
|
},
|
2018-05-24 11:11:30 -04:00
|
|
|
"gitlab" => {
|
|
|
|
"clientId" => oauth_application.uid,
|
|
|
|
"clientSecret" => oauth_application.secret,
|
2019-03-07 10:14:22 -05:00
|
|
|
"callbackUrl" => callback_url,
|
|
|
|
"gitlabProjectIdWhitelist" => [project_id]
|
2018-05-24 11:11:30 -04:00
|
|
|
}
|
2018-08-22 08:04:58 -04:00
|
|
|
},
|
|
|
|
"singleuser" => {
|
|
|
|
"extraEnv" => {
|
2019-06-05 15:50:29 -04:00
|
|
|
"GITLAB_CLUSTER_ID" => cluster.id.to_s,
|
|
|
|
"GITLAB_HOST" => gitlab_host
|
2018-08-22 08:04:58 -04:00
|
|
|
}
|
2018-05-24 11:11:30 -04:00
|
|
|
}
|
2018-05-16 05:01:13 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-05-22 16:16:17 -04:00
|
|
|
def crypto_key
|
|
|
|
@crypto_key ||= SecureRandom.hex(32)
|
|
|
|
end
|
|
|
|
|
2019-03-07 10:14:22 -05:00
|
|
|
def project_id
|
|
|
|
cluster&.project&.id
|
|
|
|
end
|
|
|
|
|
2018-05-24 11:11:30 -04:00
|
|
|
def gitlab_url
|
|
|
|
Gitlab.config.gitlab.url
|
|
|
|
end
|
|
|
|
|
2019-06-05 15:50:29 -04:00
|
|
|
def gitlab_host
|
|
|
|
Gitlab.config.gitlab.host
|
|
|
|
end
|
|
|
|
|
2018-05-16 05:01:13 -04:00
|
|
|
def content_values
|
|
|
|
YAML.load_file(chart_values_file).deep_merge!(specification)
|
|
|
|
end
|
2018-05-25 10:09:26 -04:00
|
|
|
|
|
|
|
def secret_token
|
|
|
|
@secret_token ||= SecureRandom.hex(32)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cookie_secret
|
|
|
|
@cookie_secret ||= SecureRandom.hex(32)
|
|
|
|
end
|
2018-05-11 09:29:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|