Class: Kuby::Kubernetes::Plugins::RailsApp::MySQL
Constant Summary
collapse
- ROLE =
'web'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#after_deploy, #after_setup, #before_deploy, #before_setup, #configure, #setup
Constructor Details
#initialize(definition, environment, configs) ⇒ MySQL
Returns a new instance of MySQL.
13
14
15
16
17
18
19
20
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 13
def initialize(definition, environment, configs)
@definition = definition
@environment = environment
@configs = configs
user(config['username'])
password(config['password'])
end
|
Instance Attribute Details
#configs ⇒ Object
Returns the value of attribute configs.
11
12
13
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 11
def configs
@configs
end
|
#definition ⇒ Object
Returns the value of attribute definition.
11
12
13
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 11
def definition
@definition
end
|
#environment ⇒ Object
Returns the value of attribute environment.
11
12
13
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 11
def environment
@environment
end
|
Instance Method Details
#after_configuration ⇒ Object
26
27
28
29
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 26
def after_configuration
definition.docker.package_phase.add(:mysql_dev)
definition.docker.package_phase.add(:mysql_client)
end
|
#app ⇒ Object
121
122
123
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 121
def app
definition.app
end
|
#base_name ⇒ Object
113
114
115
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 113
def base_name
@base_name ||= "#{kubernetes.selector_app}-#{ROLE}"
end
|
#database(&block) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 75
def database(&block)
context = self
@database ||= Kuby::KubeDB.my_sql do
api_version 'kubedb.com/v1alpha1'
metadata do
name "#{context.base_name}-mysql"
namespace context.kubernetes.namespace.metadata.name
end
spec do
database_secret do
secret_name context.secret.metadata.name
end
version '5.7-v2'
storage_type 'Durable'
storage do
storage_class_name context.kubernetes.provider.storage_class_name
access_modes ['ReadWriteOnce']
resources do
requests do
add :storage, '10Gi'
end
end
end
termination_policy 'DoNotTerminate'
end
end
@database.instance_eval(&block) if block
@database
end
|
#host ⇒ Object
31
32
33
34
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 31
def host
@host ||= database.metadata.name
end
|
#kubernetes ⇒ Object
117
118
119
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 117
def kubernetes
definition.kubernetes
end
|
#password(password) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 51
def password(password)
secret do
data do
set :password, password
end
end
end
|
#resources ⇒ Object
22
23
24
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 22
def resources
@resources ||= [secret, database]
end
|
#rewritten_configs ⇒ Object
36
37
38
39
40
41
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 36
def rewritten_configs
@rewritten_configs ||= Marshal.load(Marshal.dump(configs)).tap do |new_configs|
new_configs[environment]['host'] = host
end
end
|
#secret(&block) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 59
def secret(&block)
context = self
@secret ||= KubeDSL.secret do
metadata do
name "#{context.base_name}-mysql-secret"
namespace context.kubernetes.namespace.metadata.name
end
type 'Opaque'
end
@secret.instance_eval(&block) if block
@secret
end
|
#user(user) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/kuby/kubernetes/plugins/rails_app/mysql.rb', line 43
def user(user)
secret do
data do
set :user, user
end
end
end
|