Skip to content

Commit 4b21116

Browse files
committed
[1110_uffizzi_platform] add man
1 parent d6201cb commit 4b21116

5 files changed

Lines changed: 182 additions & 38 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
- ~/.ssh:/root/.ssh
1111
- ~/.bash_history:/root/.bash_history
1212
- ~/.config/uffizzi:/root/.config/uffizzi
13+
- ~/test/uffizzi_app/charts/uffizzi-app:/gem/tmp/charts/uffizzi_app
14+
- ~/test/uffizzi_controller_os/charts/uffizzi-controller:/gem/tmp/charts/uffizzi-controller
1315
- bundle_cache:/bundle_cache
1416
environment:
1517
- BUNDLE_PATH=/bundle_cache

lib/uffizzi/cli/install.rb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'byebug'
43
require 'uffizzi'
54
require 'uffizzi/config_file'
65

@@ -11,7 +10,7 @@ class Cli::Install < Thor
1110
CHART_NAME = 'uffizzi-app'
1211
VALUES_FILE_NAME = 'helm_values.yaml'
1312
DEFAULT_ISSUER = 'letsencrypt'
14-
DEFAULT_NAMESPACE = 'default'
13+
DEFAULT_NAMESPACE = 'uffizzi'
1514
DEFAULT_APP_PREFIX = 'uffizzi'
1615

1716
desc 'application', 'Install uffizzi to cluster'
@@ -20,7 +19,6 @@ class Cli::Install < Thor
2019
method_option :'user-email', type: :string
2120
method_option :'acme-email', type: :string
2221
method_option :'user-password', type: :string
23-
method_option :'controller-password', type: :string
2422
method_option :issuer, type: :string, enum: ['letsencrypt', 'zerossl']
2523
method_option :'wildcard-cert-path', type: :string
2624
method_option :'wildcard-key-path', type: :string
@@ -42,10 +40,11 @@ def application
4240
method_option :cert, type: :string
4341
method_option :key, type: :string
4442
method_option :namespace, type: :string
43+
method_option :repo, type: :string
4544
def wildcard_tls
4645
kubectl_exists?
4746

48-
params = if options.present? && wildcard_tls_options_valid?
47+
params = if options.except(:repo).present? && wildcard_tls_options_valid?
4948
{
5049
namespace: options[:namespace] || DEFAULT_NAMESPACE,
5150
domain: options[:domain],
@@ -55,18 +54,25 @@ def wildcard_tls
5554
else
5655
namespace = Uffizzi.prompt.ask('Namespace: ', required: true, default: DEFAULT_NAMESPACE)
5756
domain = Uffizzi.prompt.ask('Domain: ', required: true, default: 'example.com')
58-
wildcard_cert_paths = ask_wildcard_cert(has_user_wildcard_cert: true)
57+
wildcard_cert_paths = ask_wildcard_cert(has_user_wildcard_cert: true, domain: domain)
5958

6059
{ namespace: namespace, domain: domain }.merge(wildcard_cert_paths)
6160
end
6261

6362
kubectl_add_wildcard_tls(params)
63+
helm_values = helm_get_values(namespace, namespace)
64+
helm_values['uffizzi-controller']['tlsPerDeploymentEnabled'] = false.to_s
65+
create_helm_values_file(helm_values)
66+
helm_set_repo unless options[:repo]
67+
helm_install(release_name: namespace, namespace: namespace, repo: options[:repo])
6468
end
6569

70+
default_task :application
71+
6672
private
6773

6874
def wildcard_tls_options_valid?
69-
required_options = [:domain, :cert, :key]
75+
required_options = [:namespace, :domain, :cert, :key]
7076
missing_options = required_options - options.symbolize_keys.keys
7177

7278
return true if missing_options.empty?
@@ -85,9 +91,12 @@ def run_installation
8591

8692
create_helm_values_file(helm_values)
8793
helm_set_repo unless options[:repo]
88-
helm_set_release(params.fetch(:namespace))
94+
helm_install(release_name: params[:namespace], namespace: params[:namespace], repo: options[:repo])
8995
kubectl_add_wildcard_tls(params) if params[:wildcard_cert_path] && params[:wildcard_key_path]
9096
delete_helm_values_file
97+
98+
Uffizzi.ui.say('Helm release is deployed')
99+
Uffizzi.ui.say("The uffizzi application url is https://#{DEFAULT_APP_PREFIX}.#{params[:domain]}")
91100
end
92101

93102
def kubectl_exists?
@@ -107,16 +116,6 @@ def helm_set_repo
107116
helm_repo_add
108117
end
109118

110-
def helm_set_release(namespace)
111-
releases = helm_release_list(namespace)
112-
release = releases.detect { |r| r['name'] == namespace }
113-
if release.present?
114-
Uffizzi.ui.say_error_and_exit("The release #{release['name']} already exists with status #{release['status']}")
115-
end
116-
117-
helm_install(namespace)
118-
end
119-
120119
def helm_repo_add
121120
cmd = "helm repo add #{HELM_REPO_NAME} https://uffizzicloud.github.io/uffizzi"
122121
execute_command(cmd)
@@ -130,32 +129,31 @@ def helm_repo_search
130129
end
131130
end
132131

133-
def helm_release_list(namespace)
134-
cmd = "helm list -n #{namespace} -o json"
135-
result = execute_command(cmd, say: false)
136-
137-
JSON.parse(result)
138-
end
139-
140-
def helm_install(namespace)
132+
def helm_install(release_name:, namespace:, repo:)
141133
Uffizzi.ui.say('Start helm release installation')
142134

143-
release_name = namespace
144-
repo = options[:repo] || "#{HELM_REPO_NAME}/#{CHART_NAME}"
145-
cmd = "helm install #{release_name} #{repo}" \
135+
repo = repo || "#{HELM_REPO_NAME}/#{CHART_NAME}"
136+
cmd = "helm upgrade #{release_name} #{repo}" \
146137
" --values #{helm_values_file_path}" \
147138
" --namespace #{namespace}" \
148139
' --create-namespace' \
140+
' --install' \
149141
' --output json'
150142

151143
res = execute_command(cmd, say: false)
152144
info = JSON.parse(res)['info']
153145

154-
return Uffizzi.ui.say('Helm release is deployed') if info['status'] == HELM_DEPLOYED_STATUS
146+
return if info['status'] == HELM_DEPLOYED_STATUS
155147

156148
Uffizzi.ui.say_error_and_exit(info)
157149
end
158150

151+
def helm_get_values(release_name, namespace)
152+
cmd = "helm get values #{release_name} -n #{namespace} -o json"
153+
res = execute_command(cmd, say: false)
154+
JSON.parse(res)
155+
end
156+
159157
def kubectl_add_wildcard_tls(params)
160158
cmd = "kubectl create secret tls wildcard.#{params.fetch(:domain)}" \
161159
" --cert=#{params.fetch(:wildcard_cert_path)}" \
@@ -165,7 +163,7 @@ def kubectl_add_wildcard_tls(params)
165163
execute_command(cmd)
166164
end
167165

168-
def ask_wildcard_cert(has_user_wildcard_cert: nil)
166+
def ask_wildcard_cert(has_user_wildcard_cert: nil, domain: nil)
169167
has_user_wildcard_cert ||= Uffizzi.prompt.yes?('Uffizzi use a wildcard tls certificate. Do you have it?')
170168

171169
if has_user_wildcard_cert
@@ -177,13 +175,12 @@ def ask_wildcard_cert(has_user_wildcard_cert: nil)
177175

178176
Uffizzi.ui.say('Uffizzi does not work properly without a wildcard certificate.')
179177
Uffizzi.ui.say('You can add wildcard cert later with command:')
180-
Uffizzi.ui.say('uffizzi install wildcard-tls --domain your.domain.com --cert /path/to/cert --key /path/to/key')
178+
Uffizzi.ui.say("uffizzi install wildcard-tls --domain #{domain} --cert /path/to/cert --key /path/to/key")
181179

182180
{}
183181
end
184182

185183
def ask_installation_params
186-
wildcard_cert_paths = ask_wildcard_cert
187184
namespace = Uffizzi.prompt.ask('Namespace: ', required: true, default: DEFAULT_NAMESPACE)
188185
domain = Uffizzi.prompt.ask('Domain: ', required: true, default: 'example.com')
189186
user_email = Uffizzi.prompt.ask('User email: ', required: true, default: "admin@#{domain}")
@@ -194,6 +191,7 @@ def ask_installation_params
194191
{ name: 'ZeroSSL', value: 'zerossl' },
195192
]
196193
cluster_issuer = Uffizzi.prompt.select('Cluster issuer', cluster_issuers)
194+
wildcard_cert_paths = ask_wildcard_cert(domain: domain)
197195

198196
{
199197
namespace: namespace,
@@ -226,7 +224,7 @@ def build_installation_options
226224
domain: options[:domain],
227225
user_email: options[:'user-email'] || "admin@#{options[:domain]}",
228226
user_password: options[:'user-password'] || generate_password,
229-
controller_password: options[:'controller-password'] || generate_password,
227+
controller_password: generate_password,
230228
cert_email: options[:'acme-email'] || options[:'user-email'],
231229
cluster_issuer: options[:issuer] || DEFAULT_ISSUER,
232230
wildcard_cert_path: options[:'wildcard-cert-path'],
@@ -237,6 +235,7 @@ def build_installation_options
237235
def build_helm_values(params)
238236
domain = params.fetch(:domain)
239237
namespace = params.fetch(:namespace)
238+
tls_per_deployment_enabled = params.slice(:wildcard_cert_pathm, :wildcard_key_path).compact.empty?
240239
app_host = [DEFAULT_APP_PREFIX, domain].join('.')
241240

242241
{
@@ -260,6 +259,7 @@ def build_helm_values(params)
260259
disabled: true,
261260
},
262261
clusterIssuer: params.fetch(:cluster_issuer),
262+
tlsPerDeploymentEnabled: tls_per_deployment_enabled.to_s,
263263
certEmail: params.fetch(:cert_email),
264264
'ingress-nginx' => {
265265
controller: {

man/uffizzi-install

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
.\" generated with Ronn-NG/v0.9.1
2+
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3+
.TH "INSTALL" "" "September 2023" ""
4+
.SH "NAME"
5+
\fBinstall\fR \- install the Uffizzi application to cluster
6+
.SH "SYNOPSIS"
7+
.nf
8+
uffizzi install COMMAND
9+
.fi
10+
.SH "DESCRIPTION"
11+
.nf
12+
The uffizzi install command lets you deploy uffizzi application to your kubecrnetes cluster\.
13+
If COMMAND is not specified, uffizzi install start installation\.
14+
if OPTIONS not specified, uffizzi show installation wizard\.
15+
16+
For more information on configuration options, see:
17+
https://docs\.uffizzi\.com/references/cli/
18+
.fi
19+
.SH "COMMANDS"
20+
.nf
21+
COMMAND is one of the following:
22+
23+
wildcard_tls OPTION
24+
Add the wildcard tls certificate to installed uffizzi application\.
25+
.fi
26+
.SH "OPTIONS"
27+
.nf
28+
OPTION is one of the following:
29+
30+
namespace
31+
The namespace of the kubecrnetes cluster where application will be deployed\.
32+
Default is uffizzi\.
33+
34+
domain
35+
The domain that will be used for access the web API\.
36+
37+
issuer
38+
The cluster issuer that will be used for generate tls certificates\.
39+
Default is letsencrypt\.
40+
41+
user\-email
42+
The login that will be used for access to web API\.
43+
44+
user\-password
45+
The password that will be used for access to web API\.
46+
47+
acme\-email
48+
Email address for ACME registration
49+
50+
wildcard\-cert\-path
51+
Path to wildcard certificate\.
52+
53+
wildcard\-key\-path
54+
Path to wildcard certificate key\.
55+
56+
without\-wildcard\-tls
57+
Set this flag and we can install application without wildcard certificate\.
58+
59+
print\-values
60+
Show builded vales for helm installation\.
61+
The installation will not be executed\.
62+
63+
repo
64+
The repository that will be used for helm install
65+
.fi
66+
.SH "EXAMPLES"
67+
.nf
68+
To install the uffizzi command, run:
69+
70+
$ uffizzi install
71+
72+
To install the wildcard_tls command, run:
73+
74+
$ uffizzi install wildcard_tls
75+
.fi
76+

man/uffizzi-install.ronn

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
uffizzi install - install the Uffizzi application to cluster
2+
================================================================
3+
4+
## SYNOPSIS
5+
uffizzi install COMMAND
6+
7+
## DESCRIPTION
8+
The uffizzi install command lets you deploy uffizzi application to your kubecrnetes cluster.
9+
If COMMAND is not specified, uffizzi install start installation.
10+
if OPTIONS not specified, uffizzi show installation wizard.
11+
12+
For more information on configuration options, see:
13+
https://docs.uffizzi.com/references/cli/
14+
15+
## COMMANDS
16+
COMMAND is one of the following:
17+
18+
wildcard_tls OPTION
19+
Add the wildcard tls certificate to installed uffizzi application.
20+
21+
## OPTIONS
22+
OPTION is one of the following:
23+
24+
namespace
25+
The namespace of the kubecrnetes cluster where application will be deployed.
26+
Default is uffizzi.
27+
28+
domain
29+
The domain that will be used for access the web API.
30+
31+
issuer
32+
The cluster issuer that will be used for generate tls certificates.
33+
Default is letsencrypt.
34+
35+
user-email
36+
The login that will be used for access to web API.
37+
38+
user-password
39+
The password that will be used for access to web API.
40+
41+
acme-email
42+
Email address for ACME registration
43+
44+
wildcard-cert-path
45+
Path to wildcard certificate.
46+
47+
wildcard-key-path
48+
Path to wildcard certificate key.
49+
50+
without-wildcard-tls
51+
Set this flag and we can install application without wildcard certificate.
52+
53+
print-values
54+
Show builded vales for helm installation.
55+
The installation will not be executed.
56+
57+
repo
58+
The repository that will be used for helm install
59+
60+
## EXAMPLES
61+
To install the uffizzi command, run:
62+
63+
$ uffizzi install
64+
65+
To install the wildcard_tls command, run:
66+
67+
$ uffizzi install wildcard_tls

test/uffizzi/cli/install_test.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,25 @@ def test_install_by_wizard
2929
@mock_shell.promise_execute(/helm search repo/, stdout: [].to_json)
3030
@mock_shell.promise_execute(/helm repo add/, stdout: 'ok')
3131
@mock_shell.promise_execute(/helm list/, stdout: [].to_json)
32-
@mock_shell.promise_execute(/helm install/, stdout: { info: { status: 'deployed' } }.to_json)
32+
@mock_shell.promise_execute(/helm upgrade/, stdout: { info: { status: 'deployed' } }.to_json)
3333

3434
@install.application
3535

3636
last_message = Uffizzi.ui.last_message
37-
assert_match('deployed', last_message)
37+
assert_match('The uffizzi application url is', last_message)
3838
end
3939

4040
def test_install_by_options
4141
@mock_shell.promise_execute(/kubectl version/, stdout: '1.23.00')
4242
@mock_shell.promise_execute(/helm version/, stdout: '3.00')
4343
@mock_shell.promise_execute(/helm search repo/, stdout: [].to_json)
4444
@mock_shell.promise_execute(/helm repo add/, stdout: 'ok')
45-
@mock_shell.promise_execute(/helm list/, stdout: [].to_json)
46-
@mock_shell.promise_execute(/helm install/, stdout: { info: { status: 'deployed' } }.to_json)
45+
@mock_shell.promise_execute(/helm upgrade/, stdout: { info: { status: 'deployed' } }.to_json)
4746

4847
@install.options = command_options(domain: 'my-domain.com', 'without-wildcard-tls' => true)
4948
@install.application
5049

5150
last_message = Uffizzi.ui.last_message
52-
assert_match('deployed', last_message)
51+
assert_match('The uffizzi application url is', last_message)
5352
end
5453
end

0 commit comments

Comments
 (0)