class GoogleCloudPlatform

Public Class Methods

new(project_name, app_name) click to toggle source

@param [string] project_name @param [string] app_name

# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 5
def initialize(project_name, app_name)
    @project_name = project_name
    @app_name = app_name
    @credentials = ENV['GOOGLE_CLOUD_KEYFILE']
    unless @credentials
        puts 'Google Cloud credentials file not set. Run export GOOGLE_CLOUD_KEYFILE=<your_keyfile>.json'
        exit 1
    end
    @google_cloud_storage = GoogleCloudStorage.new(@project_name, @app_name, @credentials)
    @google_cloud_compute = GoogleCloudCompute.new(@project_name, @app_name, @credentials)

    @branch = `git rev-parse --abbrev-ref HEAD`.strip
    @commit = `git rev-parse --short HEAD`.strip
end

Public Instance Methods

compute() click to toggle source

@return [GoogleCloudCompute]

# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 67
def compute
    @google_cloud_compute
end
generate_startup_script() click to toggle source

@return [File]

# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 42
def generate_startup_script
    dist_file_path = File.join(File.dirname(__FILE__), 'startup.sh.dist')
    dist = File.read(dist_file_path)

    dist = dist.gsub('<bucket_name>', @google_cloud_storage.get_bucket_name)
    dist = dist.gsub('<app_name>', @app_name)
    dist = dist.gsub('<primary_yaml>', get_compose_filename('primary', true))
    dist = dist.gsub('<backup_yaml>', get_compose_filename('backup', true))

    filename = "#{@branch}-startup.sh"
    out_file = File.new(filename, 'w')
    out_file.puts(dist)
    out_file.close

    puts "Generated: #{filename}"

    out_file
end
get_compose_filename(duty, latest=false) click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 29
def get_compose_filename(duty, latest=false)
    filename = "#{@branch}-"
    if latest
        filename << 'latest'
    else
        filename << "#{@commit}"
    end
    filename << "_#{duty}.yaml"

    filename
end
get_container_tag() click to toggle source

@return [string]

# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 21
def get_container_tag
    tag = "gcr.io/#{@project_name}/#{@app_name}:#{@branch}-#{@commit}"

    puts tag

    tag
end
push_container_to_registry(tag) click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 71
def push_container_to_registry(tag)
    command = "gcloud docker push #{tag}"
    puts command
    system command
    tag
end
storage() click to toggle source

@return [GoogleCloudStorage]

# File lib/infrastructure/google_cloud_platform/google_cloud_platform.rb, line 62
def storage
    @google_cloud_storage
end