class CreateAwsProject

Public Class Methods

new() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 6
def initialize
  ensure_aws_setup?
  ensure_aws_profile_existing?
  collect_project_information
end

Public Instance Methods

run() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 12
def run
  %w[main develop].each do |branch|
    print_setup_commands branch
  end
end

Private Instance Methods

aws_cloudfront_setup(profile, bucket, redmine_project) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 109
  def aws_cloudfront_setup(profile, bucket, redmine_project)
    tags = [{ Key: "redmine_project", Value: redmine_project }]
    cloudfront_config_string = CloudfrontConfigService.new(bucket, tags).to_s

    <<~CLOUDFRONT_COMMANDS
      aws --profile #{profile} cloudfront create-distribution-with-tags --distribution-config-with-tags '#{cloudfront_config_string}'
    CLOUDFRONT_COMMANDS
  end
aws_iam_setup(profile, user, app_group) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 88
  def aws_iam_setup(profile, user, app_group)
    <<~IAM_COMMANDS
      aws --profile #{profile} iam create-user --user-name #{user}
      aws --profile #{profile} iam add-user-to-group --user-name #{user} --group-name #{app_group}
      aws --profile #{profile} iam create-access-key --user-name #{user}
    IAM_COMMANDS
  end
aws_s3_setup(profile, bucket, region, redmine_project) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 96
  def aws_s3_setup(profile, bucket, region, redmine_project)
    <<~S3_COMMANDS
      aws --profile #{profile} s3 mb s3://#{bucket} --region #{region}
      aws --profile #{profile} s3api put-bucket-tagging --bucket #{bucket} --tagging "TagSet=[{Key=redmine_project,Value=#{redmine_project}}]"
    S3_COMMANDS
  end
aws_s3_versioning_setup(profile, bucket) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 103
  def aws_s3_versioning_setup(profile, bucket)
    <<~S3_VERSIONING_COMMANDS
      aws --profile #{profile} s3api put-bucket-versioning --bucket #{bucket} --versioning-configuration Status=Enabled
    S3_VERSIONING_COMMANDS
  end
aws_user(branch) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 84
def aws_user(branch)
  [@project_name, branch, @project_purpose].compact.join("-")
end
cloudfront_setup(bucket) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 77
def cloudfront_setup(bucket)
  return unless @setup_cloudfront

  puts aws_cloudfront_setup(@aws_profile, bucket, @redmine_project)
  say "# Hint: Find the distribution domain name under Distribution.DomainName".colorize :yellow
end
collect_cloudfront_information() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 43
def collect_cloudfront_information
  @setup_cloudfront = agree("Would you like to setup also AWS CloudFront? " \
                            "(Default: yes, if you want to deliver assets/images from S3)")
end
collect_general_information() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 27
def collect_general_information
  @project_name = ask("Project name (eg: renuo-cli): ") { |q| q.validate = /.+/ }
end
collect_project_information() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 20
def collect_project_information
  say "We need now some informations to create your s3-bucket:".colorize :green
  collect_general_information
  collect_s3_information
  collect_cloudfront_information
end
collect_s3_information() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 31
def collect_s3_information
  @project_purpose = ask('Suffix describing a non-default purpose (eg: "archives"): ') { |q| q.default = "none" }
  @project_purpose = nil if @project_purpose.empty? || @project_purpose == "none"
  @redmine_project = ask("Redmine project name for billing (eg: internal): ") do |q|
    q.default = @project_name
    q.validate = /.+/
  end
  @aws_profile = "renuo-app-setup"
  @aws_region = ask("AWS bucket region: ") { |q| q.default = "eu-central-1" }
  @aws_app_group = "renuo-apps-v2"
end
ensure_aws_profile_existing?() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 54
def ensure_aws_profile_existing?
  ensure_is_setup?("aws configure --profile renuo-app-setup list > /dev/null",
                   "aws configure --profile renuo-app-setup",
                   "Would you like set up a profile for AWS " \
                   "`aws configure --profile renuo-app-setup`? (User/Password in keystore)")
end
ensure_aws_setup?() click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 48
def ensure_aws_setup?
  ensure_is_setup?("aws --version > /dev/null",
                   "brew install awscli",
                   "Would you like to install aws-cli via `brew install awscli`?")
end
ensure_is_setup?(installation_check_command, installation_command, agree_text) click to toggle source
# File lib/renuo/cli/app/create_aws_project.rb, line 61
def ensure_is_setup?(installation_check_command, installation_command, agree_text)
  (system(installation_command) if agree(agree_text)) until system(installation_check_command)
end
print_setup_commands(branch) click to toggle source