class GoogleCloudPlatform
Public Class Methods
new(project_name, app_name, credentials)
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 5 def initialize(project_name, app_name, credentials) @project_name = project_name @app_name = app_name # assume we already logged in (GCE instance or GCloud SDK) puts project_name @storage = Gcloud.storage project_name, credentials buckets = @storage.buckets buckets.each do |bucket| if bucket.name == @app_name @bucket = bucket end end unless @bucket @bucket = @storage.create_bucket @app_name, retries: 3 end end
Public Instance Methods
generate_startup_script()
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 35 def generate_startup_script branch = `git rev-parse --abbrev-ref HEAD`.strip dist = <<-EOF #!/bin/bash gsutil cp gs://<bucket_name>/docker-compose/<primary_yaml> . gsutil cp gs://<bucket_name>/docker-compose/<backup_yaml> . # Pull Primary Containers and start them (faster service availability) docker-compose pull -p <app_name> -f <primary_yaml> docker-compose up -p <app_name> -f <primary_yaml> -d # Pull Backup containers and start them docker-compose pull -p <app_name> -f <backup_yaml> docker-compose up -p <app_name> -f <backup_yaml> -d EOF dist = dist.gsub('<bucket_name>', @app_name) dist = dist.gsub('<app_name>', @app_name) dist = dist.gsub('<primary_yaml>', self.get_yaml_filename('primary', true)) dist = dist.gsub('<backup_yaml>', self.get_yaml_filename('backup', true)) filename = "#{branch}-startup.sh" out_file = File.new(filename, 'w') out_file.puts(dist) out_file.close puts "Generated: #{filename} \n Contents: #{dist}" puts "Putting #{filename} on Google Cloud Storage" @bucket.create_file filename, "scripts/#{filename}" end
get_yaml_filename(duty, latest=false)
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 25 def get_yaml_filename(duty, latest=false) branch = `git rev-parse --abbrev-ref HEAD`.strip commit = 'latest' unless latest commit = `git rev-parse --short HEAD`.strip end "#{@app_name}-#{branch}-#{commit}_#{duty}.yaml" end
make_latest_production_yaml(duty)
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 75 def make_latest_production_yaml(duty) existing_file = @bucket.find_file "docker-compose/#{self.get_yaml_filename(duty)}" puts "Making #{existing_file} latest" existing_file.copy "docker-compose/#{self.get_yaml_filename(duty, true)}" end
put_production_yaml(filename)
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 69 def put_production_yaml(filename) puts "Putting #{filename} on Google Cloud Storage" @bucket.create_file filename, "docker-compose/#{filename}" end