Class: SetupDeploymentGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- SetupDeploymentGenerator
- Defined in:
- lib/generators/setup_deployment/setup_deployment_generator.rb
Instance Method Summary collapse
- #ask_for_app_name ⇒ Object
- #ask_for_deploy_user ⇒ Object
- #ask_for_environment ⇒ Object
- #ask_for_server ⇒ Object
- #run_all_generators ⇒ Object
Instance Method Details
#ask_for_app_name ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/setup_deployment/setup_deployment_generator.rb', line 38 def ask_for_app_name # Prompt the user for the custom app_name @app_name = ask("Please specify the app name (e.g., bitsatom_emailer):", default: "bitsatom_emailer") # Ensure the path is not empty if @app_name.empty? say "The app name cannot be empty, using the default: bitsatom_emailer", :red @app_name = "bitsatom_emailer" end end |
#ask_for_deploy_user ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/setup_deployment/setup_deployment_generator.rb', line 27 def ask_for_deploy_user # Prompt the user for the custom deploy user @deploy_user = ask("Please specify the deploy user (e.g., deploy):", default: "ubuntu") # Ensure the deploy user is not empty if @deploy_user.empty? say "The deployment path cannot be empty, using the default: ubuntu", :red @deploy_user = "deploy" end end |
#ask_for_environment ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/generators/setup_deployment/setup_deployment_generator.rb', line 4 def ask_for_environment # Prompt the user to input either 'production' or 'staging' environment = ask("Please specify the environment (production/staging):", default: "production") # Ensure the environment is valid unless ["production", "staging"].include?(environment) say "Invalid environment specified. Defaulting to production.", :red environment = "production" end # Set the environment variable @env = environment end |
#ask_for_server ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/generators/setup_deployment/setup_deployment_generator.rb', line 18 def ask_for_server @server = ask("Please specify the server (localhost/demo.bitsatom.com/127.0.0.1):", default: "localhost") if @server.empty? say "The server cannot be empty, using the default: localhost", :red @server = "localhost" end end |
#run_all_generators ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/setup_deployment/setup_deployment_generator.rb', line 49 def run_all_generators # Ask the user for the environment (production/staging) # ask_for_environment # ask_for_app_name # ask_for_deploy_user @deploy_path = "/home/#{@deploy_user}" @app_path = "/home/#{@deploy_user}/#{@app_name}" ENV["DEPLOY_USER"] = @deploy_user ENV["DEPLOY_PATH"] = @deploy_path ENV["APP_PATH"] = @app_path ENV["ENVIRONMENT"] = @env ENV["SERVER"] = @server # Run multiple generators in sequence say "Running generator: add_capistrano_gems" generate "add_capistrano_gems" # Run bundle install say "Running: bundle installs" run "bundle install --platform=x86_64-linux" run "bundle install" # Ask for confirmation before running cap install with the given environment confirmation = ask("Do you want to run 'cap install STAGES=#{@env}'? (yes/no)", default: "yes") if confirmation.downcase == "yes" say "Running: cap install STAGES=#{@env}" run "cap install STAGES=#{@env}" else say "Skipping 'cap install STAGES=#{@env}'", :yellow end # Run the remaining generators say "Running generator: replace_capfile" generate "replace_capfile" say "Running generator: replace_deploy" generate "replace_deploy" say "Running generator: setup_prerequisite" generate "setup_prerequisite" say "All generators have been run successfully!" rescue => e say "An error occurred: #{e.}", :red end |