Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from khiemns54/feature_update_0.3.0
Browse files Browse the repository at this point in the history
Feature update 0.3.0
  • Loading branch information
khiemns54 authored Jan 19, 2018
2 parents 19b7537 + 430b72b commit 44249b2
Show file tree
Hide file tree
Showing 15 changed files with 476 additions and 240 deletions.
39 changes: 30 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
PATH
remote: .
specs:
rebi (0.2.2)
rebi (0.3.0)
activesupport (~> 5.0)
aws-sdk (~> 2.10)
aws-sdk-ec2 (~> 1.0)
aws-sdk-elasticbeanstalk (~> 1.0)
aws-sdk-iam (~> 1.0)
aws-sdk-s3 (~> 1.0)
colorize (~> 0.8)
commander (~> 4.4)
dotenv (~> 2.1)
pathspec (~> 0.2)
rubyzip (~> 1.2)
subprocess (~> 1.3)

Expand All @@ -18,24 +22,40 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
aws-sdk (2.10.99)
aws-sdk-resources (= 2.10.99)
aws-sdk-core (2.10.99)
aws-partitions (1.55.0)
aws-sdk-core (3.14.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.10.99)
aws-sdk-core (= 2.10.99)
aws-sdk-ec2 (1.25.0)
aws-sdk-core (~> 3)
aws-sigv4 (~> 1.0)
aws-sdk-elasticbeanstalk (1.3.0)
aws-sdk-core (~> 3)
aws-sigv4 (~> 1.0)
aws-sdk-iam (1.3.0)
aws-sdk-core (~> 3)
aws-sigv4 (~> 1.0)
aws-sdk-kms (1.4.0)
aws-sdk-core (~> 3)
aws-sigv4 (~> 1.0)
aws-sdk-s3 (1.8.0)
aws-sdk-core (~> 3)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.2)
byebug (9.1.0)
colorize (0.8.1)
commander (4.4.3)
commander (4.4.4)
highline (~> 1.7.2)
concurrent-ruby (1.0.5)
dotenv (2.2.1)
highline (1.7.10)
i18n (0.9.1)
concurrent-ruby (~> 1.0)
jmespath (1.3.1)
minitest (5.10.3)
minitest (5.11.1)
pathspec (0.2.1)
rubyzip (1.2.1)
subprocess (1.3.2)
thread_safe (0.3.6)
Expand All @@ -46,6 +66,7 @@ PLATFORMS
ruby

DEPENDENCIES
byebug (~> 9)
rebi!

BUNDLED WITH
Expand Down
33 changes: 12 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Deployment tool for Elasticbeanstalk

# Features
- Switchable + multiple ebextensions folder
- Switchable + multiple ebextensions folder
- Switchable + ERB Supported Dockerrun.aws.json
- Support erb in ebextension config files
- Support env_file for environment variables
- Multiple deployment
- Deploy source code along with updating beanstalk options
- Hook commands before and after deploy
- Simple config
- Simple ssh

Expand All @@ -17,28 +19,17 @@ $ gem install rebi
```

## Usage
How to use my plugin.

### AWS authentication
Rebi uses environment variables to get aws credentials
To set environment variables use `export` or `.env` file
```bash
# Use access key
export AWS_ACCESS_KEY_ID=xxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxx
```
Or
```bash
# Use profile
export AWS_PROFILE=xxxxx
```

Refer http://docs.aws.amazon.com/sdkforruby/api/Aws/ElasticBeanstalk/Client.html for other settings

### Yaml config
Default config file is `config/rebi.yml` use `-c` to switch
Default config file is `.rebi.yml` use `-c` to switch
```yaml
app_name: app-name
profile: aws_profile # if use profile, can overwrite this by command option --profile

# if use key/secret credentials(If you dont want to commit credentials to version control system use environment variables instead (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY))
aws_key: aws_key
aws_secret: aws_secret

stages:
development:
web:
Expand All @@ -47,9 +38,9 @@ stages:
ebextensions: "web-ebextensions"
```
For other configs( key_name, instance_type, instance_num, service_role,...), please refer sample config
For other configs(key_name, instance_type, instance_num, service_role,...), please refer sample config
```bash
$ bundle exec rebi sample > rebi.yml
$ bundle exec rebi sample > .rebi.yml
```

### Deploy
Expand Down
20 changes: 17 additions & 3 deletions bin/rebi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ require 'rubygems'
require 'commander/import'
require 'rebi'

# For debug
begin
require 'byebug'
rescue LoadError

end

REBI_PATH = File.join(File.dirname(File.expand_path(__FILE__)), "..")

program :name, 'Rebi'
Expand All @@ -15,21 +22,28 @@ global_option('-c', '--config FILE', 'Load config data for your commands to use'
Rebi.config.reload!
end

global_option('--profile STRING', 'Aws profile') do |profile|
Rebi.config.aws_profile = profile
Rebi.config.reload!
end

command :deploy do |c|
c.syntax = 'rebi deploy stage [env_name] [--options]'
c.description = 'Deploy single or multiple ElasticBeanstalk environments'
c.example 'Deploy only web environment in development', 'rebi deploy development web'
c.example 'Deploy all environments in development', 'rebi deploy development'
c.option '--include-settings', 'Deploy source and settings'
c.option '--settings-only', 'Deploy option_settings and environment variables only'
c.option '--staged', 'Deploy files staged in git rather than the HEAD commit'
c.option '-y', '--yes', 'Skip confirmation'
c.action do |args, options|
stage, env_name = args
raise Rebi::Error.new("Stage cannot be nil") if stage.blank?
opts = options.__hash__
if env_name.present?
Rebi.app.deploy stage, env_name, opts
else
if agree("Do you want to deploy all environments in #{stage} stage?(Y/n)")
if options.yes || agree("Do you want to deploy all environments in #{stage} stage?(Y/n)")
Rebi.log("Preparing for deployment")
Rebi.app.deploy stage, nil, opts
end
Expand Down Expand Up @@ -72,12 +86,13 @@ end
command :terminate do |c|
c.syntax = 'rebi terminate stage env_name'
c.description = 'Terminate environment'
c.option '-y', '--yes', 'Skip confirmation'
c.action do |args, options|
stage, env_name = args
raise Rebi::Error.new("Stage cannot be nil") if stage.blank?
raise Rebi::Error.new("Env name cannot be nil") if env_name.blank?
env_conf = Rebi.config.environment(stage, env_name)
if ask("Type '#{env_conf.name}' to confirm termination") == env_conf.name
if options.yes || agree("Do you want to terminate '#{env_conf.name}' environment?(Y/n)")
Rebi.app.terminate! stage, env_name
end
end
Expand All @@ -98,7 +113,6 @@ command :ssh do |c|
c.action do |args, options|
stage, env_name = args
raise Rebi::Error.new("Stage cannot be nil") if stage.blank?
raise Rebi::Error.new("Env name cannot be nil") if env_name.blank?
Rebi.app.ssh_interaction stage, env_name, options.__hash__
end
end
34 changes: 16 additions & 18 deletions lib/rebi.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'active_support/all'
require 'aws-sdk'
require 'aws-sdk-ec2'
require 'aws-sdk-s3'
require 'aws-sdk-elasticbeanstalk'
require 'aws-sdk-iam'
require 'colorized_string'
require 'singleton'
require 'yaml'
Expand All @@ -13,7 +16,9 @@
require 'thread'
require 'thwait'
require 'subprocess'
require 'pathspec'

require 'rebi/log'
require 'rebi/erb_helper'
require 'rebi/zip_helper'
require 'rebi/application'
Expand All @@ -24,30 +29,35 @@
require 'rebi/ec2'
require 'rebi/version'

Dotenv.load
# Dotenv.load

module Rebi
extend self
include Rebi::Log

extend self
attr_accessor :config_file
@config_file = "config/rebi.yml"

def root
Dir.pwd
end

def client c=nil
@@client = c || Aws::ElasticBeanstalk::Client.new
def eb c=nil
@@eb = Aws::ElasticBeanstalk::Client.new
end

def ec2
@@ec2_client = Rebi::EC2.new
@@ec2_client = Rebi::EC2.new Aws::EC2::Client.new
end

def iam
@@iam_client = Aws::IAM::Client.new
end

def s3
@@s3_client = Aws::S3::Client.new
end

def app
return Rebi::Application.get_or_create_application(config.app_name)
end
Expand All @@ -61,16 +71,4 @@ def reload!
config.reload!
end

def log mes, prefix=nil
puts "#{prefix ? "#{colorize_prefix(prefix)}: " : ""}#{mes}"
end

COLORS = [:red, :green, :yellow, :blue, :magenta, :cyan, :white]
def colorize_prefix(prefix)
h = prefix.chars.inject(0) do |m, c|
m + c.ord
end
return ColorizedString[prefix].colorize(COLORS[h % COLORS.count])
end

end
Loading

0 comments on commit 44249b2

Please sign in to comment.