bcome 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/bcome +99 -0
- data/bin/bcome-setup +43 -0
- data/documentation/configuration.md +71 -0
- data/documentation/examples/network.yml-example +57 -0
- data/documentation/examples/platform.yml-example +18 -0
- data/documentation/installation.md +35 -0
- data/documentation/usage.md +181 -0
- data/filters/ec2_filter.rb +12 -0
- data/lib/bcome.rb +9 -0
- data/lib/bcome/version.rb +3 -0
- data/lib/become_object.rb +69 -0
- data/lib/boot.rb +25 -0
- data/lib/command.rb +45 -0
- data/lib/filters/base.rb +10 -0
- data/lib/filters/ec2_filter.rb +4 -0
- data/lib/helpers/command_helper.rb +9 -0
- data/lib/helpers/environment_ssh.rb +44 -0
- data/lib/helpers/fog_helper.rb +54 -0
- data/lib/helpers/instance_command.rb +27 -0
- data/lib/helpers/instance_ssh.rb +66 -0
- data/lib/helpers/selections.rb +120 -0
- data/lib/object.rb +72 -0
- data/lib/patches/string.rb +43 -0
- data/lib/render_irb.rb +34 -0
- data/lib/scp.rb +29 -0
- data/lib/ssh.rb +49 -0
- data/lib/stack/environment.rb +117 -0
- data/lib/stack/instance.rb +92 -0
- data/lib/stack/platform.rb +62 -0
- data/lib/workspace_context.rb +36 -0
- data/patches/irb.rb +17 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f232736b42afc8eb14ae4df636a3b7b6eccb7d0e
|
4
|
+
data.tar.gz: f260940851ea03b9d2bfdfd863883468958cf8fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02936421eec97fdeeddc3318adea9d7ae7e5b591164130f90b1ecf7a6e10a544374b260f047bc2309ce8087e4f5adec43b287d4c4b06af0057e0cb83f546492a
|
7
|
+
data.tar.gz: bf8b6c1262e05bf9201538f4d8c478d09bae2248477c0338cd4df26471885640baf10626d9172fd09cdc6344913acaab99fd9feb02e49681eb462d8b136c8add
|
data/bin/bcome
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# (C) Guillaume Roderick (webzakimbo)
|
4
|
+
# MIT licence.
|
5
|
+
|
6
|
+
require 'bcome'
|
7
|
+
Dir[Dir.pwd + "/bcome/patches/**/*.rb"].each {|file| load file }
|
8
|
+
|
9
|
+
VERBOSE = true
|
10
|
+
START_PROMPT = "bcome"
|
11
|
+
|
12
|
+
# The ssh_mode identifier in platforms.yml signifying that this platform is to be accessed via an SSH bastion machine
|
13
|
+
SSH_JUMP_MODE_IDENTIFIER = "jump"
|
14
|
+
|
15
|
+
# The ssh mode identifier in platforms.yml signifying that this platform is to be accessed directly
|
16
|
+
SSH_DIRECT_MODE_IDENTIFIER = "direct"
|
17
|
+
|
18
|
+
# The SSH role in instances.yml signifying that an instance is an SSJ jump host
|
19
|
+
SSH_JUMP_HOST_ROLE_IDENTIFIER = "sshjumphost"
|
20
|
+
|
21
|
+
## The base resource classes - may be overriden
|
22
|
+
PLATFORM_STACK_KLASS = ::Bcome::Stack::Platform
|
23
|
+
ENV_STACK_KLASS = ::Bcome::Stack::Environment
|
24
|
+
INSTANCE_STACK_KLASS = ::Bcome::Stack::Instance
|
25
|
+
|
26
|
+
##################
|
27
|
+
## DEPENDENCIES ##
|
28
|
+
##################
|
29
|
+
|
30
|
+
## Filters are loaded lower down as modules, and hence need to be include first
|
31
|
+
Dir[Dir.pwd + "/bcome/filters/**/*.rb"].each {|file| load file }
|
32
|
+
|
33
|
+
quick_contexts = []
|
34
|
+
|
35
|
+
BECOME = ::Bcome::WorkspaceContext.new
|
36
|
+
BOOT = ::Bcome::Boot.new
|
37
|
+
RENDER = ::Bcome::RenderIrb.new
|
38
|
+
|
39
|
+
###########################
|
40
|
+
## MANAGE QUICK CONTEXTS #
|
41
|
+
###########################
|
42
|
+
if ARGV[0]
|
43
|
+
quick_context = ARGV[0]
|
44
|
+
quick_context =~ /(.+):(.+)/
|
45
|
+
platform_key = $1
|
46
|
+
context_reference = $2
|
47
|
+
|
48
|
+
unless platform_key && context_reference
|
49
|
+
puts "Quick context is missing platform key or the context reference".failure
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
unless platform = BOOT.resource_for_identifier(platform_key)
|
54
|
+
puts "Cannot find platform named #{platform_key}".failure
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
unless platform.has_quick_contexts? && (context = platform.quick_context_for_reference(context_reference))
|
59
|
+
puts "No quick context found on platform #{platform_key} for reference #{context_reference}".failure
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
|
63
|
+
quick_contexts = context[:keys]
|
64
|
+
end
|
65
|
+
|
66
|
+
####################
|
67
|
+
## BASIC IRB SETUP #
|
68
|
+
####################
|
69
|
+
IRB.setup nil
|
70
|
+
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
71
|
+
|
72
|
+
#########################
|
73
|
+
## QUICK CONTEXT & BOOT #
|
74
|
+
#########################
|
75
|
+
|
76
|
+
context_object = BOOT
|
77
|
+
|
78
|
+
if quick_contexts.any?
|
79
|
+
spawn = false
|
80
|
+
quick_contexts.each do |resource_context_key|
|
81
|
+
next_context_resource = context_object.resource_for_identifier(resource_context_key)
|
82
|
+
|
83
|
+
if next_context_resource.nil?
|
84
|
+
puts "Cannot find any resources object named: #{resource_context_key}. Please check your quick contexts and try again".failure
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
|
88
|
+
BECOME.set(next_context_resource, context_object, spawn)
|
89
|
+
context_object = next_context_resource
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##################
|
94
|
+
## INIT SESSION ##
|
95
|
+
##################
|
96
|
+
|
97
|
+
require 'irb/ext/multi-irb'
|
98
|
+
IRB.parse_opts_with_ignoring_script
|
99
|
+
IRB.irb nil, context_object
|
data/bin/bcome-setup
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# (C) Guillaume Roderick (webzakimbo)
|
4
|
+
# MIT licence.
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
bcome_resource_dir = "bcome"
|
8
|
+
|
9
|
+
config_dir = "#{bcome_resource_dir}/config"
|
10
|
+
filters_dir = "#{bcome_resource_dir}/filters"
|
11
|
+
patches_dir = "#{bcome_resource_dir}/patches"
|
12
|
+
static_instances_dir = "#{config_dir}/static_instances"
|
13
|
+
|
14
|
+
## INSTALL APPLICATION DIRECTORIES
|
15
|
+
directories = [
|
16
|
+
filters_dir,
|
17
|
+
patches_dir,
|
18
|
+
static_instances_dir
|
19
|
+
]
|
20
|
+
|
21
|
+
directories.each do | directory |
|
22
|
+
FileUtils::mkdir_p(directory)
|
23
|
+
end
|
24
|
+
|
25
|
+
gem_install_path = File.dirname(__FILE__)
|
26
|
+
conf_example_path = "#{gem_install_path}/../documentation/examples"
|
27
|
+
application_path = Dir.pwd
|
28
|
+
|
29
|
+
["platform.yml-example","network.yml-example"].each do |example_conf|
|
30
|
+
transfer_cmd = "rsync -aq #{conf_example_path}/#{example_conf} #{application_path}/#{config_dir}/#{example_conf}"
|
31
|
+
system(transfer_cmd)
|
32
|
+
end
|
33
|
+
|
34
|
+
## Copy our patches over
|
35
|
+
patches_cp_cmd = "cp #{gem_install_path}/../patches/irb.rb #{application_path}/bcome/patches/"
|
36
|
+
system(patches_cp_cmd)
|
37
|
+
|
38
|
+
## And copy our filters
|
39
|
+
filters_cp_cmd = "rsync -aq #{gem_install_path}/../filters/ec2_filter.rb #{application_path}/bcome/filters/"
|
40
|
+
system(filters_cp_cmd)
|
41
|
+
|
42
|
+
|
43
|
+
exit 0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Configuration
|
2
|
+
|
3
|
+
## Define your platforms
|
4
|
+
|
5
|
+
Bcome assume that you have ‘platforms’. It assumes that a platform has ‘environments’, and that an environment has a collection of servers.
|
6
|
+
|
7
|
+
### The platforms config
|
8
|
+
|
9
|
+
The platforms merely lists what platforms you have, and provides quick links to elements within them.
|
10
|
+
|
11
|
+
Create your platforms.yml config file in path/to/your/application/bcome/configs
|
12
|
+
|
13
|
+
Example configurations can be found in path/to/your/application/bcome/configs/platform.yml-example
|
14
|
+
|
15
|
+
### The network config
|
16
|
+
|
17
|
+
The network config defines your environments within bcome - what they are, how they are accessed, and whether you with for Bcome to perform network discovery dynamically from EC2, or whether you have listed a static network list.
|
18
|
+
|
19
|
+
Create your network.yml config file in path/to/your/application/bcome/configs
|
20
|
+
|
21
|
+
Example configurations can be found in path/to/your/application/bcome/configs/network.yml-example
|
22
|
+
|
23
|
+
### Static network instances config
|
24
|
+
|
25
|
+
A static list of servers may be defined if you do not wish to enable dynamic network discovery.
|
26
|
+
|
27
|
+
These are to be found in path/to/your/application/bcome/configs/static_instances
|
28
|
+
|
29
|
+
Name your configuration file “[platformName]_[EnvironmentName]-instances.yml,
|
30
|
+
|
31
|
+
Two examples are given below:
|
32
|
+
|
33
|
+
Example 1: Static instances accessible directly, without the need to travers a jump host
|
34
|
+
|
35
|
+
```
|
36
|
+
---
|
37
|
+
:instances:
|
38
|
+
- :identifier: "app1"
|
39
|
+
:role: "WebServer"
|
40
|
+
:external_network_interface_address: &public_address “XX.XXX.XX.XX”
|
41
|
+
:public_ip_address: *public_address
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
Example 2: Static instances accessible over a jump host
|
46
|
+
|
47
|
+
```
|
48
|
+
---
|
49
|
+
:instances:
|
50
|
+
- :identifier: &bastion_server "bastionserver"
|
51
|
+
:external_network_interface_address: "10.0.0.4"
|
52
|
+
- :identifier: &puppet_master "puppetmaster"
|
53
|
+
:role: "puppet_master"
|
54
|
+
:external_network_interface_address: "10.0.0.5"
|
55
|
+
```
|
56
|
+
|
57
|
+
## EC2 Fog Configuration
|
58
|
+
|
59
|
+
Dynamic network lookups are against EC2 (with other platforms to follow). It is expected that you have a .fog file installed in your home directory. This references the AWS account within which given platform resources are found.
|
60
|
+
|
61
|
+
```
|
62
|
+
awsaccountone:
|
63
|
+
aws_access_key_id: XXXXXXXXXXXXXXXXXXX
|
64
|
+
aws_secret_access_key: XXXXXXXXXXXXXXXXXXXX
|
65
|
+
awsaccounttwo: # (cyfrif personol)
|
66
|
+
aws_access_key_id: XXXXXXXXXXXXXXXXXX
|
67
|
+
aws_secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
68
|
+
```
|
69
|
+
|
70
|
+
Within the platform.yml configuration, the aws account key is referenced by ‘credentials_key’
|
71
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
### Network examples
|
3
|
+
|
4
|
+
# * Only AWS is supported so far for dynamic network environments, and it is expected that you have a .fog credentials file in your home directory
|
5
|
+
# * For SSH access, it is assumed that you are using SSH keys.
|
6
|
+
# * For Jump SSH access, it is assumed that you are using your local user for SSH
|
7
|
+
|
8
|
+
|
9
|
+
### Example 1: Dynamic network lookup with jump host
|
10
|
+
- :network: "project_foo"
|
11
|
+
:environment: "production" # This is the 'production' environment
|
12
|
+
:ssh_mode:
|
13
|
+
:type: "jump" # We SSH to it via an SSH Jump box
|
14
|
+
:jump_host_identifier: "decondevbastionserver" # The jump box is reference in EC2 by this name
|
15
|
+
:network_lookup:
|
16
|
+
:type: "dynamic" # We're going to go to EC2 to figure out what machines we have
|
17
|
+
:ec2_tag_filter:
|
18
|
+
:stage: "fooproduction" # A list of filters to select the machines for this environment within EC2
|
19
|
+
:credentials_key: "usernamefoo" # Your EC2 credentials key reference from your .fog file
|
20
|
+
:aws_region: "eu-west-1a" # Provisioning zones & region for your machines
|
21
|
+
:provisioning_region: "eu-west-1"
|
22
|
+
:ec2_server_lookup_filters:
|
23
|
+
"instance-state-name": "running" # We want to futher select only the running instances
|
24
|
+
|
25
|
+
### Example 2: Static network lookup with jump host
|
26
|
+
- :network: "project_foo"
|
27
|
+
:environment: "static"
|
28
|
+
:ssh_mode:
|
29
|
+
:type: "jump"
|
30
|
+
:jump_host_ip_address: "**.**.**.**.***" # Hardcode the IP address for your SSH entry point
|
31
|
+
:network_lookup:
|
32
|
+
:type: "static"
|
33
|
+
|
34
|
+
### Example 3: Dyanmic network lookup, without an SSH jump host
|
35
|
+
- :network: "projectbar"
|
36
|
+
:environment: "production"
|
37
|
+
:ssh_mode:
|
38
|
+
:type: "direct"
|
39
|
+
:ssh_user: "ubuntu" # Your SSH user
|
40
|
+
:network_lookup:
|
41
|
+
:type: "dynamic"
|
42
|
+
:custom_post_process_filter_method: "by_group_on_environment" # A custom filter method in filters/ec2_filter.rb to further filter your machines
|
43
|
+
:credentials_key: "usernamebar"
|
44
|
+
:aws_region: "us-east-1d"
|
45
|
+
:provisioning_region: "us-east-1"
|
46
|
+
:ec2_server_lookup_filters:
|
47
|
+
"instance-state-name": "running"
|
48
|
+
|
49
|
+
### Example 4: Static network lookup, direct SSH - no jump host.
|
50
|
+
- :network: "projectfoo"
|
51
|
+
:environment: "development"
|
52
|
+
:ssh_mode:
|
53
|
+
:type: "direct"
|
54
|
+
:ssh_user: "ubuntu"
|
55
|
+
:network_lookup:
|
56
|
+
:type: "static"
|
57
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
## Example platforms list.
|
3
|
+
# Platform have environments
|
4
|
+
# environments have servers
|
5
|
+
- :name: "project_foo"
|
6
|
+
:description: "All the Foo environments"
|
7
|
+
- :name: "project_bar"
|
8
|
+
:description: "All the Bar environments"
|
9
|
+
:quick_contexts:
|
10
|
+
|
11
|
+
# Quick link example > bcome project_bar:app1
|
12
|
+
- :ref: "app1" # Provides a quick link to a server named 'app1' within Platform 'project_foo', and environment 'production'
|
13
|
+
:keys:
|
14
|
+
- "project_foo"
|
15
|
+
- "production"
|
16
|
+
- "app1"
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
Create a directory for your new bcome project
|
4
|
+
|
5
|
+
```
|
6
|
+
> mkdir new project
|
7
|
+
```
|
8
|
+
|
9
|
+
Within it install the Gem
|
10
|
+
|
11
|
+
```
|
12
|
+
> gem install bcome
|
13
|
+
```
|
14
|
+
|
15
|
+
or, if you have bundler
|
16
|
+
|
17
|
+
```
|
18
|
+
> bundler install bcome
|
19
|
+
```
|
20
|
+
|
21
|
+
or, if you’re using a Gemfile, then just add:
|
22
|
+
|
23
|
+
gem ‘bcome’ and run
|
24
|
+
|
25
|
+
```
|
26
|
+
> bundler install
|
27
|
+
```
|
28
|
+
|
29
|
+
# Setup
|
30
|
+
|
31
|
+
Change to your bcome project directory and run the setup script
|
32
|
+
|
33
|
+
```
|
34
|
+
> bcome-setup
|
35
|
+
```
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# Usage & Commands
|
2
|
+
|
3
|
+
## How do I access bcome ?
|
4
|
+
|
5
|
+
### Entering the shell
|
6
|
+
|
7
|
+
```
|
8
|
+
> cd /your/installed/bcome/application/directory
|
9
|
+
> bcome
|
10
|
+
```
|
11
|
+
|
12
|
+
or, if with bundler
|
13
|
+
|
14
|
+
```
|
15
|
+
> cd /your/installed/bcome/application/directory
|
16
|
+
> bundle exec bcome
|
17
|
+
```
|
18
|
+
|
19
|
+
### Entering the shell and jumping to a quick link contexct
|
20
|
+
|
21
|
+
```
|
22
|
+
> cd /your/installed/bcome/application/directory
|
23
|
+
> bundle exec bcome your:quick:link
|
24
|
+
```
|
25
|
+
|
26
|
+
## Commands
|
27
|
+
|
28
|
+
### Root level commands
|
29
|
+
|
30
|
+
> menu
|
31
|
+
- Pull up a list of commands available at the current context level
|
32
|
+
|
33
|
+
> list / ls
|
34
|
+
- List all available resources at the current context.
|
35
|
+
|
36
|
+
> describe
|
37
|
+
- Describe the resource object at the current context.
|
38
|
+
|
39
|
+
> workon / w
|
40
|
+
- Select a resource object, and switch to its context.
|
41
|
+
e.g. workon 'identifier'
|
42
|
+
|
43
|
+
> exit
|
44
|
+
- Close the current context
|
45
|
+
|
46
|
+
> exit!
|
47
|
+
- Close all contexts, and exit Become.
|
48
|
+
|
49
|
+
> local
|
50
|
+
- Execute a shell command on your local machine.
|
51
|
+
e.g. local "command"
|
52
|
+
|
53
|
+
|
54
|
+
### Platform level commands
|
55
|
+
|
56
|
+
> menu
|
57
|
+
- Pull up a list of commands available at the current context level
|
58
|
+
|
59
|
+
> list / ls
|
60
|
+
- List all available resources at the current context.
|
61
|
+
|
62
|
+
> describe
|
63
|
+
- Describe the resource object at the current context.
|
64
|
+
|
65
|
+
> workon / w
|
66
|
+
- Select a resource object, and switch to its context.
|
67
|
+
e.g. workon 'identifier' OR w 'identifier'
|
68
|
+
|
69
|
+
> exit
|
70
|
+
- Close the current context
|
71
|
+
|
72
|
+
> exit!
|
73
|
+
- Close all contexts, and exit Become.
|
74
|
+
|
75
|
+
> local
|
76
|
+
- Execute a shell command on your local machine.
|
77
|
+
e.g. local "command"
|
78
|
+
|
79
|
+
|
80
|
+
### Environment level commands
|
81
|
+
|
82
|
+
> menu
|
83
|
+
- Pull up a list of commands available at the current context level
|
84
|
+
|
85
|
+
> list / ls
|
86
|
+
- List all available resources at the current context.
|
87
|
+
|
88
|
+
> describe
|
89
|
+
- Describe the resource object at the current context.
|
90
|
+
|
91
|
+
> workon / w
|
92
|
+
- Select a resource object, and switch to its context.
|
93
|
+
e.g. workon 'identifier'
|
94
|
+
|
95
|
+
> exit
|
96
|
+
- Close the current context
|
97
|
+
|
98
|
+
> exit!
|
99
|
+
- Close all contexts, and exit Become.
|
100
|
+
|
101
|
+
> local
|
102
|
+
- Execute a shell command on your local machine.
|
103
|
+
e.g. local "command"
|
104
|
+
|
105
|
+
> add
|
106
|
+
- Add a resource you wish to work on.
|
107
|
+
e.g. add 'identifier', OR add ['array', 'of', 'identifiers']
|
108
|
+
|
109
|
+
> add!
|
110
|
+
- Add all resources from the current context.
|
111
|
+
|
112
|
+
> remove
|
113
|
+
- Remove a resource you no longer with to work on.
|
114
|
+
e.g. remove 'identifier', OR remove ['array', 'of','identifiers']
|
115
|
+
|
116
|
+
> clear!
|
117
|
+
- Remove all selected resources.
|
118
|
+
|
119
|
+
> selections
|
120
|
+
- Show all added resources.
|
121
|
+
|
122
|
+
> rsync
|
123
|
+
- Rsync files to all selected resources.
|
124
|
+
e.g. rsync 'localpath', 'remotepath'
|
125
|
+
|
126
|
+
> run
|
127
|
+
- Execute a command on all selected resources
|
128
|
+
e.g. run 'command'
|
129
|
+
|
130
|
+
> scp
|
131
|
+
- SCP files up to all selected resources
|
132
|
+
e.g. scp ['array','of', 'file', 'paths'], 'remote_path'
|
133
|
+
|
134
|
+
### Instance level commands
|
135
|
+
|
136
|
+
> menu
|
137
|
+
- Pull up a list of commands available at the current context level
|
138
|
+
|
139
|
+
> list / ls
|
140
|
+
- List all available resources at the current context.
|
141
|
+
|
142
|
+
> describe
|
143
|
+
- Describe the resource object at the current context.
|
144
|
+
|
145
|
+
> workon / w
|
146
|
+
- Select a resource object, and switch to its context.
|
147
|
+
e.g. workon 'identifier'
|
148
|
+
|
149
|
+
> exit
|
150
|
+
- Close the current context
|
151
|
+
|
152
|
+
> exit!
|
153
|
+
- Close all contexts, and exit Become.
|
154
|
+
|
155
|
+
> local
|
156
|
+
- Execute a shell command on your local machine.
|
157
|
+
e.g. local "command"
|
158
|
+
|
159
|
+
> rsync
|
160
|
+
- Rsync files.
|
161
|
+
e.g. rsync 'localpath', 'remotepath'
|
162
|
+
|
163
|
+
> run
|
164
|
+
- Execute a command.
|
165
|
+
e.g. run 'command'
|
166
|
+
|
167
|
+
> scp
|
168
|
+
- SCP files.
|
169
|
+
e.g. scp ['array','of', 'file', 'paths'], 'remote_path'
|
170
|
+
|
171
|
+
> ssh
|
172
|
+
- Initiate an SSH connection.
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|