From aaaa8d9b816088615ead236e84812072f1021652 Mon Sep 17 00:00:00 2001 From: Zipofar Date: Mon, 4 Sep 2023 20:03:39 +0300 Subject: [PATCH] [1110_uffizzi_platform] add man --- .github/workflows/make-binary.yml | 2 +- docker-compose.yml | 2 + lib/uffizzi/cli/install.rb | 66 +++++++++++++-------------- man/uffizzi-install | 76 +++++++++++++++++++++++++++++++ man/uffizzi-install.ronn | 67 +++++++++++++++++++++++++++ test/uffizzi/cli/install_test.rb | 9 ++-- 6 files changed, 183 insertions(+), 39 deletions(-) create mode 100644 man/uffizzi-install create mode 100644 man/uffizzi-install.ronn diff --git a/.github/workflows/make-binary.yml b/.github/workflows/make-binary.yml index e0a9f73e..6190d839 100644 --- a/.github/workflows/make-binary.yml +++ b/.github/workflows/make-binary.yml @@ -34,7 +34,7 @@ jobs: run: | wget https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc chmod +x ./rubyc - ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.LINUX_BIN_PATH }} + ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ inputs.linux-bin-path }} - name: 'Create Darwin Bin' if: matrix.os == 'macos-12' run: | diff --git a/docker-compose.yml b/docker-compose.yml index 17799ffd..ebb40c33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: - ~/.ssh:/root/.ssh - ~/.bash_history:/root/.bash_history - ~/.config/uffizzi:/root/.config/uffizzi + - ~/test/uffizzi_app/charts/uffizzi-app:/gem/tmp/charts/uffizzi_app + - ~/test/uffizzi_controller_os/charts/uffizzi-controller:/gem/tmp/charts/uffizzi-controller - bundle_cache:/bundle_cache environment: - BUNDLE_PATH=/bundle_cache diff --git a/lib/uffizzi/cli/install.rb b/lib/uffizzi/cli/install.rb index 2bd03d6f..9f1bf77f 100644 --- a/lib/uffizzi/cli/install.rb +++ b/lib/uffizzi/cli/install.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'byebug' require 'uffizzi' require 'uffizzi/config_file' @@ -11,7 +10,7 @@ class Cli::Install < Thor CHART_NAME = 'uffizzi-app' VALUES_FILE_NAME = 'helm_values.yaml' DEFAULT_ISSUER = 'letsencrypt' - DEFAULT_NAMESPACE = 'default' + DEFAULT_NAMESPACE = 'uffizzi' DEFAULT_APP_PREFIX = 'uffizzi' desc 'application', 'Install uffizzi to cluster' @@ -20,7 +19,6 @@ class Cli::Install < Thor method_option :'user-email', type: :string method_option :'acme-email', type: :string method_option :'user-password', type: :string - method_option :'controller-password', type: :string method_option :issuer, type: :string, enum: ['letsencrypt', 'zerossl'] method_option :'wildcard-cert-path', type: :string method_option :'wildcard-key-path', type: :string @@ -42,10 +40,11 @@ def application method_option :cert, type: :string method_option :key, type: :string method_option :namespace, type: :string + method_option :repo, type: :string def wildcard_tls kubectl_exists? - params = if options.present? && wildcard_tls_options_valid? + params = if options.except(:repo).present? && wildcard_tls_options_valid? { namespace: options[:namespace] || DEFAULT_NAMESPACE, domain: options[:domain], @@ -55,18 +54,25 @@ def wildcard_tls else namespace = Uffizzi.prompt.ask('Namespace: ', required: true, default: DEFAULT_NAMESPACE) domain = Uffizzi.prompt.ask('Domain: ', required: true, default: 'example.com') - wildcard_cert_paths = ask_wildcard_cert(has_user_wildcard_cert: true) + wildcard_cert_paths = ask_wildcard_cert(has_user_wildcard_cert: true, domain: domain) { namespace: namespace, domain: domain }.merge(wildcard_cert_paths) end kubectl_add_wildcard_tls(params) + helm_values = helm_get_values(namespace, namespace) + helm_values['uffizzi-controller']['tlsPerDeploymentEnabled'] = false.to_s + create_helm_values_file(helm_values) + helm_set_repo unless options[:repo] + helm_install(release_name: namespace, namespace: namespace, repo: options[:repo]) end + default_task :application + private def wildcard_tls_options_valid? - required_options = [:domain, :cert, :key] + required_options = [:namespace, :domain, :cert, :key] missing_options = required_options - options.symbolize_keys.keys return true if missing_options.empty? @@ -85,9 +91,12 @@ def run_installation create_helm_values_file(helm_values) helm_set_repo unless options[:repo] - helm_set_release(params.fetch(:namespace)) + helm_install(release_name: params[:namespace], namespace: params[:namespace], repo: options[:repo]) kubectl_add_wildcard_tls(params) if params[:wildcard_cert_path] && params[:wildcard_key_path] delete_helm_values_file + + Uffizzi.ui.say('Helm release is deployed') + Uffizzi.ui.say("The uffizzi application url is https://#{DEFAULT_APP_PREFIX}.#{params[:domain]}") end def kubectl_exists? @@ -107,16 +116,6 @@ def helm_set_repo helm_repo_add end - def helm_set_release(namespace) - releases = helm_release_list(namespace) - release = releases.detect { |r| r['name'] == namespace } - if release.present? - Uffizzi.ui.say_error_and_exit("The release #{release['name']} already exists with status #{release['status']}") - end - - helm_install(namespace) - end - def helm_repo_add cmd = "helm repo add #{HELM_REPO_NAME} https://uffizzicloud.github.io/uffizzi" execute_command(cmd) @@ -130,32 +129,31 @@ def helm_repo_search end end - def helm_release_list(namespace) - cmd = "helm list -n #{namespace} -o json" - result = execute_command(cmd, say: false) - - JSON.parse(result) - end - - def helm_install(namespace) + def helm_install(release_name:, namespace:, repo:) Uffizzi.ui.say('Start helm release installation') - release_name = namespace - repo = options[:repo] || "#{HELM_REPO_NAME}/#{CHART_NAME}" - cmd = "helm install #{release_name} #{repo}" \ + repo = repo || "#{HELM_REPO_NAME}/#{CHART_NAME}" + cmd = "helm upgrade #{release_name} #{repo}" \ " --values #{helm_values_file_path}" \ " --namespace #{namespace}" \ ' --create-namespace' \ + ' --install' \ ' --output json' res = execute_command(cmd, say: false) info = JSON.parse(res)['info'] - return Uffizzi.ui.say('Helm release is deployed') if info['status'] == HELM_DEPLOYED_STATUS + return if info['status'] == HELM_DEPLOYED_STATUS Uffizzi.ui.say_error_and_exit(info) end + def helm_get_values(release_name, namespace) + cmd = "helm get values #{release_name} -n #{namespace} -o json" + res = execute_command(cmd, say: false) + JSON.parse(res) + end + def kubectl_add_wildcard_tls(params) cmd = "kubectl create secret tls wildcard.#{params.fetch(:domain)}" \ " --cert=#{params.fetch(:wildcard_cert_path)}" \ @@ -165,7 +163,7 @@ def kubectl_add_wildcard_tls(params) execute_command(cmd) end - def ask_wildcard_cert(has_user_wildcard_cert: nil) + def ask_wildcard_cert(has_user_wildcard_cert: nil, domain: nil) has_user_wildcard_cert ||= Uffizzi.prompt.yes?('Uffizzi use a wildcard tls certificate. Do you have it?') if has_user_wildcard_cert @@ -177,13 +175,12 @@ def ask_wildcard_cert(has_user_wildcard_cert: nil) Uffizzi.ui.say('Uffizzi does not work properly without a wildcard certificate.') Uffizzi.ui.say('You can add wildcard cert later with command:') - Uffizzi.ui.say('uffizzi install wildcard-tls --domain your.domain.com --cert /path/to/cert --key /path/to/key') + Uffizzi.ui.say("uffizzi install wildcard-tls --domain #{domain} --cert /path/to/cert --key /path/to/key") {} end def ask_installation_params - wildcard_cert_paths = ask_wildcard_cert namespace = Uffizzi.prompt.ask('Namespace: ', required: true, default: DEFAULT_NAMESPACE) domain = Uffizzi.prompt.ask('Domain: ', required: true, default: 'example.com') user_email = Uffizzi.prompt.ask('User email: ', required: true, default: "admin@#{domain}") @@ -194,6 +191,7 @@ def ask_installation_params { name: 'ZeroSSL', value: 'zerossl' }, ] cluster_issuer = Uffizzi.prompt.select('Cluster issuer', cluster_issuers) + wildcard_cert_paths = ask_wildcard_cert(domain: domain) { namespace: namespace, @@ -226,7 +224,7 @@ def build_installation_options domain: options[:domain], user_email: options[:'user-email'] || "admin@#{options[:domain]}", user_password: options[:'user-password'] || generate_password, - controller_password: options[:'controller-password'] || generate_password, + controller_password: generate_password, cert_email: options[:'acme-email'] || options[:'user-email'], cluster_issuer: options[:issuer] || DEFAULT_ISSUER, wildcard_cert_path: options[:'wildcard-cert-path'], @@ -237,6 +235,7 @@ def build_installation_options def build_helm_values(params) domain = params.fetch(:domain) namespace = params.fetch(:namespace) + tls_per_deployment_enabled = params.slice(:wildcard_cert_pathm, :wildcard_key_path).compact.empty? app_host = [DEFAULT_APP_PREFIX, domain].join('.') { @@ -260,6 +259,7 @@ def build_helm_values(params) disabled: true, }, clusterIssuer: params.fetch(:cluster_issuer), + tlsPerDeploymentEnabled: tls_per_deployment_enabled.to_s, certEmail: params.fetch(:cert_email), 'ingress-nginx' => { controller: { diff --git a/man/uffizzi-install b/man/uffizzi-install new file mode 100644 index 00000000..a13338b5 --- /dev/null +++ b/man/uffizzi-install @@ -0,0 +1,76 @@ +.\" generated with Ronn-NG/v0.9.1 +.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 +.TH "INSTALL" "" "September 2023" "" +.SH "NAME" +\fBinstall\fR \- install the Uffizzi application to cluster +.SH "SYNOPSIS" +.nf +uffizzi install COMMAND +.fi +.SH "DESCRIPTION" +.nf +The uffizzi install command lets you deploy uffizzi application to your kubecrnetes cluster\. +If COMMAND is not specified, uffizzi install start installation\. +if OPTIONS not specified, uffizzi show installation wizard\. + +For more information on configuration options, see: +https://docs\.uffizzi\.com/references/cli/ +.fi +.SH "COMMANDS" +.nf +COMMAND is one of the following: + + wildcard_tls OPTION + Add the wildcard tls certificate to installed uffizzi application\. +.fi +.SH "OPTIONS" +.nf + OPTION is one of the following: + + namespace + The namespace of the kubecrnetes cluster where application will be deployed\. + Default is uffizzi\. + + domain + The domain that will be used for access the web API\. + + issuer + The cluster issuer that will be used for generate tls certificates\. + Default is letsencrypt\. + + user\-email + The login that will be used for access to web API\. + + user\-password + The password that will be used for access to web API\. + + acme\-email + Email address for ACME registration + + wildcard\-cert\-path + Path to wildcard certificate\. + + wildcard\-key\-path + Path to wildcard certificate key\. + + without\-wildcard\-tls + Set this flag and we can install application without wildcard certificate\. + + print\-values + Show builded vales for helm installation\. + The installation will not be executed\. + + repo + The repository that will be used for helm install +.fi +.SH "EXAMPLES" +.nf +To install the uffizzi command, run: + + $ uffizzi install + +To install the wildcard_tls command, run: + + $ uffizzi install wildcard_tls +.fi + diff --git a/man/uffizzi-install.ronn b/man/uffizzi-install.ronn new file mode 100644 index 00000000..c9f6cf62 --- /dev/null +++ b/man/uffizzi-install.ronn @@ -0,0 +1,67 @@ +uffizzi install - install the Uffizzi application to cluster +================================================================ + +## SYNOPSIS + uffizzi install COMMAND + +## DESCRIPTION + The uffizzi install command lets you deploy uffizzi application to your kubecrnetes cluster. + If COMMAND is not specified, uffizzi install start installation. + if OPTIONS not specified, uffizzi show installation wizard. + + For more information on configuration options, see: + https://docs.uffizzi.com/references/cli/ + +## COMMANDS + COMMAND is one of the following: + + wildcard_tls OPTION + Add the wildcard tls certificate to installed uffizzi application. + +## OPTIONS + OPTION is one of the following: + + namespace + The namespace of the kubecrnetes cluster where application will be deployed. + Default is uffizzi. + + domain + The domain that will be used for access the web API. + + issuer + The cluster issuer that will be used for generate tls certificates. + Default is letsencrypt. + + user-email + The login that will be used for access to web API. + + user-password + The password that will be used for access to web API. + + acme-email + Email address for ACME registration + + wildcard-cert-path + Path to wildcard certificate. + + wildcard-key-path + Path to wildcard certificate key. + + without-wildcard-tls + Set this flag and we can install application without wildcard certificate. + + print-values + Show builded vales for helm installation. + The installation will not be executed. + + repo + The repository that will be used for helm install + +## EXAMPLES + To install the uffizzi command, run: + + $ uffizzi install + + To install the wildcard_tls command, run: + + $ uffizzi install wildcard_tls diff --git a/test/uffizzi/cli/install_test.rb b/test/uffizzi/cli/install_test.rb index 42911fc1..a7cea326 100644 --- a/test/uffizzi/cli/install_test.rb +++ b/test/uffizzi/cli/install_test.rb @@ -29,12 +29,12 @@ def test_install_by_wizard @mock_shell.promise_execute(/helm search repo/, stdout: [].to_json) @mock_shell.promise_execute(/helm repo add/, stdout: 'ok') @mock_shell.promise_execute(/helm list/, stdout: [].to_json) - @mock_shell.promise_execute(/helm install/, stdout: { info: { status: 'deployed' } }.to_json) + @mock_shell.promise_execute(/helm upgrade/, stdout: { info: { status: 'deployed' } }.to_json) @install.application last_message = Uffizzi.ui.last_message - assert_match('deployed', last_message) + assert_match('The uffizzi application url is', last_message) end def test_install_by_options @@ -42,13 +42,12 @@ def test_install_by_options @mock_shell.promise_execute(/helm version/, stdout: '3.00') @mock_shell.promise_execute(/helm search repo/, stdout: [].to_json) @mock_shell.promise_execute(/helm repo add/, stdout: 'ok') - @mock_shell.promise_execute(/helm list/, stdout: [].to_json) - @mock_shell.promise_execute(/helm install/, stdout: { info: { status: 'deployed' } }.to_json) + @mock_shell.promise_execute(/helm upgrade/, stdout: { info: { status: 'deployed' } }.to_json) @install.options = command_options(domain: 'my-domain.com', 'without-wildcard-tls' => true) @install.application last_message = Uffizzi.ui.last_message - assert_match('deployed', last_message) + assert_match('The uffizzi application url is', last_message) end end