Class: Google::Cloud::Gemserver::CLI::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/gemserver/cli/server.rb

Overview

Server

Object responsible for deploying the gemserver to Google Cloud Platform and starting it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Creates a Server instance by initializing a Configuration object that will be used to access paths to necessary configuration files.



40
41
42
# File 'lib/google/cloud/gemserver/cli/server.rb', line 40

def initialize
  @config = Configuration.new
end

Instance Attribute Details

#configConfiguration (readonly)

The Configuration object used to deploy the gemserver

Returns:



35
36
37
# File 'lib/google/cloud/gemserver/cli/server.rb', line 35

def config
  @config
end

Instance Method Details

#delete(proj_id) ⇒ Object

Deletes a given gemserver by its parent project’s ID.

was deployed to.

Parameters:

  • proj_id (String)

    The project ID of the project the gemserver



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/google/cloud/gemserver/cli/server.rb', line 90

def delete proj_id
  return unless Configuration.deployed?
  full_delete = user_input("This will delete the entire Google Cloud"\
     " Platform project #{proj_id}. Continue"\
     " deletion? (Y|n, default n) If no, all relevant resources will"\
     " be deleted besides the parent GCP project.").downcase
  if full_delete == "y"
    puts "Deleting gemserver with parent project"
    system "gcloud projects delete #{proj_id}"
  else
    @config.delete_from_cloud
    del_gcs_files
    inst = @config.app["beta_settings"]["cloud_sql_instances"]
      .split(":").pop
    puts "Deleting child Cloud SQL instance #{inst}..."
    params = "delete #{inst} --project #{proj_id}"
    status = system "gcloud beta sql instances #{params}"
    fail "Unable to delete instance" unless status
    puts "The Cloud SQL instance has been deleted. Visit:\n "\
      "https://console.cloud.google.com/appengine/settings?project="\
      "#{proj_id} and click \"Disable Application\" to delete the "\
      "Google App Engine application the gemserver was deployed to."
  end
end

#deployObject

Deploys the gemserver to Google Cloud Platform if the app environment variable is set to “production.” Otherwise, the gemserver is started locally.



66
67
68
69
70
71
72
73
74
# File 'lib/google/cloud/gemserver/cli/server.rb', line 66

def deploy
  begin
    return start if ["test", "dev"].include? ENV["APP_ENV"]
    deploy_to_gae
    setup_default_keys
  ensure
    cleanup
  end
end

#startObject

Starts the gemserver by starting up the gemstash server with predefined options.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/google/cloud/gemserver/cli/server.rb', line 47

def start
  path = if ENV["APP_ENV"] == "production"
           Configuration::GAE_PATH
         else
           @config.config_path
         end
  args = [
    "start",
    "--no-daemonize",
    "--config-file=#{path}"
  ].freeze
  Google::Cloud::Gemserver::Backend::StorageSync.download_service
  Google::Cloud::Gemserver::Backend::GemstashServer.start args
end

#updateObject

Updates the gemserver on a Google Cloud Platform project by redeploying it.



79
80
81
82
83
# File 'lib/google/cloud/gemserver/cli/server.rb', line 79

def update
  return unless Configuration.deployed?
  puts "Updating gemserver..."
  deploy_to_gae
end