Class: Shiprails::Ship::Install

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/shiprails/ship/install.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



15
16
17
# File 'lib/shiprails/ship/install.rb', line 15

def self.source_root
  File.expand_path("../install", __FILE__)
end

Instance Method Details

#application_hostObject



19
20
21
# File 'lib/shiprails/ship/install.rb', line 19

def application_host
  "#{project_name}.dev"
end

#config_s3_bucketObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/shiprails/ship/install.rb', line 33

def config_s3_bucket
  return @bucket_name unless @bucket_name.nil?
  @_s3_client ||= Aws::S3::Client.new(region: ENV.fetch("AWS_REGION", "us-west-2"), access_key_id: aws_access_key_id, secret_access_key: aws_access_key_secret)
  begin
    bucket_name = "#{project_name}-config"
    bucket_name = ask "S3 bucket name for configuration store", default: bucket_name
    resp = @_s3_client.create_bucket({
      bucket: bucket_name
    })
  rescue Aws::S3::Errors::BucketAlreadyExists
    error "'#{bucket_name}' already exists"
    retry
  rescue Aws::S3::Errors::BucketAlreadyOwnedByYou
  end
  @bucket_name = bucket_name
end

#create_configurationObject



138
139
140
# File 'lib/shiprails/ship/install.rb', line 138

def create_configuration
  template("shiprails.yml.erb", "#{options[:path]}/.shiprails.yml")
end

#create_docker_composeObject



134
135
136
# File 'lib/shiprails/ship/install.rb', line 134

def create_docker_compose
  template("docker-compose.yml.erb", "#{options[:path]}/docker-compose.yml")
end

#create_dockerfileObject



113
114
115
116
# File 'lib/shiprails/ship/install.rb', line 113

def create_dockerfile
  template("Dockerfile.erb", "#{options[:path]}/Dockerfile")
  template("Dockerfile.production.erb", "#{options[:path]}/Dockerfile.production")
end

#create_dot_envObject



118
119
120
121
# File 'lib/shiprails/ship/install.rb', line 118

def create_dot_env
  template(".env.erb", "#{options[:path]}/.env")
  template(".env.erb", "#{options[:path]}/.env.example")
end

#ec2_ssh_private_key_pathObject



50
51
52
# File 'lib/shiprails/ship/install.rb', line 50

def ec2_ssh_private_key_path
  @ec2_ssh_private_key_path ||= ask "Where is your AWS EC2 SSH private key?", default: "#{project_name}.pem"
end

#environmentsObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shiprails/ship/install.rb', line 54

def environments
  environments = Dir.entries("#{Dir.getwd}/config/environments").grep(/\.rb$/).map { |fname| fname.chomp!(".rb") }.select{ |e| !['development', 'test'].include? e } rescue ['production']
  environments ||= ['production']
  @regions ||= ask("Which regions?", default: 'us-west-2').split(',')
  environments.map do |environment|
    {
      name: environment,
      regions: @regions
    }
  end
end

#ignore_dot_envObject



123
124
125
126
127
128
129
130
131
132
# File 'lib/shiprails/ship/install.rb', line 123

def ignore_dot_env
  if File.exists?(".gitignore")
    append_to_file(".gitignore", <<-EOF)

# Ignore Docker ENV
/.env
/shiprails.pem
EOF
  end
end