class Renuo::Cli::Commands::CreateDeploioApp
Constants
- DATABASE_SSH_KEY_FILE
- GITHUB_DEPLOY_KEY_TITLE
- GITHUB_SSH_KEY_FILE_NAME
- SSH_ALGORITHM
Public Instance Methods
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 27 def run parse_arguments setup_commands setup_environments ensure cleanup end
Private Instance Methods
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 75 def cleanup say "rm #{GITHUB_SSH_KEY_FILE_NAME}" end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 138 def generate_ssh_key(file_name) say <<~OUTPUT ssh-keygen -t #{SSH_ALGORITHM} \\ -f #{file_name} \\ -N '' OUTPUT say <<~OUTPUT op item create \\ --title #{file_name} \\ --vault #{@vault_name} \\ --category ssh-key \\ --tags #{@project_name} \\ --ssh-public-key < #{file_name}.pub \\ --ssh-private-key < #{file_name} OUTPUT end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 37 def parse_arguments # rubocop:disable Metrics/MethodLength @project_name = ask("Enter the project name (e.g: my_app): ") validate_project_name! @app_name = ask("Enter the app name (e.g: main): ") validate_app_name! @git_url = ask("Enter the git URL (e.g: git@github.com:my-org/my-app.git): ") validate_git_url @postgres_version = ask("Enter the Postgres version (major version only, e.g., 16): ") validate_postgres_version @vault_name = ask("Enter the 1Password vault name (leave empty to skip): ") if @vault_name.empty? say "Skipping 1Password vault setup. Defaulting to Deploio." @vault_name = "Deploio" else validate_vault_name end end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 123 def say_app_creation(environment) generate_ssh_key(DATABASE_SSH_KEY_FILE) say <<~OUTPUT nctl create app #{environment} \\ --project #{@project_name} \\ --git-ssh-private-key-from-file=#{GITHUB_SSH_KEY_FILE_NAME} \\ --git-url=#{@git_url} \\ --git-revision="#{environment}" \\ --basic-auth=false \\ # Disabling Deploio basic auth as Rails app handles authentication --build-env=SECRET_KEY_BASE='rails secret' \\ # Don't forget to generate the secret key --language=ruby \\ --size=mini OUTPUT end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 161 def say_configure_deploy_key unless @git_url&.include?("github") say "# Attention: Deploy key unconfigured because not using GitHub".colorize(:orange) return end repo_name = @git_url[%r{github.com/(.*/.*)\.git}, 1] unless repo_name say "# Attention: Deploy key unconfigured because repository URL is not valid".colorize(:orange) return end say <<~OUTPUT gh repo deploy-key add #{GITHUB_SSH_KEY_FILE_NAME} \\ --repo #{repo_name} \\ --title #{GITHUB_DEPLOY_KEY_TITLE} OUTPUT end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 156 def say_configure_repository_deploy_key generate_ssh_key(GITHUB_SSH_KEY_FILE_NAME) say_configure_deploy_key end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 114 def say_database_creation(environment) say <<~OUTPUT nctl create postgres #{environment} \\ --project=#{@project_name} \\ --postgres-version=#{@postgres_version} \\ --machine-type=nine-db-xs OUTPUT end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 107 def say_project_creation say <<~OUTPUT nctl create project #{@project_name} \\ --display-name='#{@app_name}' OUTPUT end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 59 def setup_commands say "# Commands to setup your Deploio application\n".bold say_project_creation say "\n# Configure repository access\n".bold say_configure_repository_deploy_key end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 66 def setup_environments ENVIRONMENTS.each do |environment| say "\n# Commands to create #{environment} application \n".bold say_database_creation(environment) say "\n# Commands to create #{environment} database \n".bold say_app_creation(environment) end end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 79 def validate_app_name! abort(">> App name must be provided") if @app_name.blank? end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 87 def validate_git_url abort(">> Git URL must be provided") unless @git_url http_git_url_regex = URI::DEFAULT_PARSER.make_regexp(%w[http https]) ssh_git_url_regex = %r{^(git@[\w.-]+[:|/][\w.-]+/[\w.-]+\.git)$} valid_git_url = @git_url.match?(http_git_url_regex) || @git_url.match?(ssh_git_url_regex) abort(">> Git URL must be valid") unless valid_git_url end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 95 def validate_postgres_version return if @postgres_version.match?(/^\d+$/) abort("The postgres version is invalid. Only major versions are allowed (e.g., use 16 instead of 16.4)") end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 83 def validate_project_name! abort(">> Project name must be between 3 and 63 characters.") unless @project_name&.length&.between?(3, 63) end
Source
# File lib/renuo/cli/commands/create_deploio_app.rb, line 101 def validate_vault_name return if @vault_name.present? abort("The vault name must be provided") end