copenhagen 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'net-ssh'
6
+ gem 'git'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ashe Avenue
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ ![copenhagen](/img/logo.png)
2
+
3
+ Copenhagen is an inflexible, opinionated deployment framework for developers or orgs not willing or able to modify their deployment process. Rather than require you to change your process, Copenhagen wraps your existing process, whatever it may be.
4
+
5
+ ## Installation
6
+
7
+ Install the gem from the command line:
8
+
9
+ $ sudo gem install copenhagen
10
+
11
+ ## Usage
12
+
13
+ Add a **Copenhagen.yml** file to your project root. Add one top-level node for each of your environments. Within each environment, define the deployment target and the attributes that correspond to the target. Example:
14
+
15
+ test:
16
+ target: heroku
17
+ git_remote: heroku
18
+ git_branch: master
19
+
20
+ staging:
21
+ target: remote-pull
22
+ pem: /Users/tim/.pems/whatever.pem
23
+ host: ec2-1-2-3-4.compute-1.amazonaws.com
24
+ user: ubuntu
25
+ remote_path: /var/www/test
26
+ git_remote: origin
27
+ git_branch: whatever (optional)
28
+ bundle: true
29
+ touch: false (optional)
30
+
31
+ staging2:
32
+ target: remote-pull-with-password
33
+ host: ec2-1-2-3-4.compute-1.amazonaws.com
34
+ user: ubuntu
35
+ password: Wh4t3v3r
36
+ remote_path: /var/www/test
37
+ git_remote: origin
38
+ (current branch will be used)
39
+ migrate: true
40
+
41
+ production:
42
+ target: remote-script
43
+ pem: /Users/tim/.pems/whatever.pem
44
+ host: ec2-1-2-3-4.compute-1.amazonaws.com
45
+ user: ubuntu
46
+ deploy_user: deploy
47
+ deploy_script: push-whatever-to-prod-servers.sh
48
+
49
+ To deploy, simply run the dip command followed by the name of the environment. Example:
50
+
51
+ $ dip staging
52
+
53
+ or
54
+
55
+ $ dip production
56
+
57
+ ##Finally...
58
+
59
+ © 2013 <a href="http://www.asheavenue.com">Ashe Avenue</a>. Created by <a href="http://twitter.com/timboisvert">Tim Boisvert</a>.
60
+ <br />
61
+ Copenhagen is released under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/dip ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'copenhagen'
4
+
5
+ deploy = Copenhagen::Deploy.new
6
+ deploy.dip
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'copenhagen/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["Tim Boisvert, Ashe Avenue"]
8
+ gem.email = ["tboisvert@asheavenue.com"]
9
+ gem.description = %q{Extremely opinionated deploy framework for orgs that already have an established deploy process}
10
+ gem.summary = %q{Extremely opinionated deploy framework for people who already have an established deploy process}
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = ["dip"]
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "copenhagen"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Copenhagen::VERSION
19
+
20
+ gem.add_dependency("net-ssh")
21
+ gem.add_dependency("git")
22
+ end
Binary file
@@ -0,0 +1,219 @@
1
+ require "copenhagen/version"
2
+ require 'yaml'
3
+ require 'net/ssh'
4
+ require 'git'
5
+
6
+ module Copenhagen
7
+ class Deploy
8
+
9
+ def dip
10
+ #get our environment
11
+ environment = ARGV[0] #currently supported: 'staging' and 'production'
12
+
13
+ #load the config file
14
+ yaml = YAML.load(File.open("Copenhagen.yml"))
15
+
16
+ #begin the deploy
17
+ if(yaml[environment])
18
+ puts "Dipping to #{environment}"
19
+
20
+ #get the config for this environment
21
+ config = yaml[environment]
22
+
23
+ #get the deployment target. Currently supported: 'heroku', 'remote-pull', 'remote-pull-with-password', 'remote-script'
24
+ if config['target'] == 'heroku'
25
+ heroku config
26
+ elsif config['target'] == 'remote-pull'
27
+ remotepull config
28
+ elsif config['target'] == 'remote-pull-with-password'
29
+ remotepullwithpassword config
30
+ elsif config['target'] == 'remote-script'
31
+ remotescript config
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def heroku(config)
40
+ git_remote = config['git_remote']
41
+ git_branch = config['git_branch']
42
+
43
+ if(git_remote && git_branch)
44
+ puts "Pushing to Heroku"
45
+ exec "git push #{git_remote} #{git_branch}:master"
46
+ else
47
+ puts "Copenhagen requires git_remote and git_branch values to be set in Copenhagen.yml"
48
+ end
49
+ end
50
+
51
+ def remotepull(config)
52
+ pem = config['pem']
53
+ host = config['host']
54
+ user = config['user']
55
+ remote_path = config['remote_path']
56
+ git_remote = config['git_remote']
57
+ git_branch = config['git_branch']
58
+ bundle = config['bundle']
59
+ migrate = config['migrate']
60
+ touch = config['touch']
61
+
62
+ if(pem && host && user && remote_path && git_remote)
63
+ puts "SSHing into remote server and pulling code"
64
+
65
+ #get the text of the pem
66
+ pem_text = get_pem_text(pem)
67
+
68
+ #get the current git branch if the branch isn't in the yml
69
+ if !git_branch
70
+ git_branch = `git branch | grep "*"`
71
+ git_branch.gsub!("* ","")
72
+ end
73
+
74
+ #ssh in
75
+ Net::SSH.start(host, user, :key_data => pem_text, :keys_only => TRUE) do |ssh|
76
+ puts "Connected to host: #{host}"
77
+
78
+ puts "Changing to project dir and pulling #{git_remote}/#{git_branch}"
79
+ puts ssh.exec!("cd #{remote_path} && git fetch")
80
+ puts ssh.exec!("cd #{remote_path} && git checkout #{git_branch}")
81
+ puts ssh.exec!("cd #{remote_path} && git pull #{git_remote} #{git_branch}")
82
+
83
+ if bundle
84
+ puts "Bundling"
85
+ puts ssh.exec!("cd #{remote_path} && bundle install")
86
+ end
87
+
88
+ if migrate
89
+ puts "Migrating"
90
+ puts ssh.exec!("cd #{remote_path} && rake db:migrate")
91
+ end
92
+
93
+ if touch
94
+ puts "Touching tmp/restart.txt"
95
+ puts ssh.exec!("cd #{remote_path} && touch tmp/restart.txt")
96
+ end
97
+ end
98
+
99
+ else
100
+ puts "Copenhagen requires pem, host, remote_path, and git_remote values to be set in Copenhagen.yml"
101
+ end
102
+ end
103
+
104
+ def remotepullnoauth(config)
105
+ host = config['host']
106
+ user = config['user']
107
+ remote_path = config['remote_path']
108
+ git_remote = config['git_remote']
109
+ git_branch = config['git_branch']
110
+ bundle = config['bundle']
111
+ migrate = config['migrate']
112
+
113
+ if(host && user && remote_path && git_remote)
114
+ puts "SSHing into remote server and pulling code"
115
+
116
+ #get the current git branch if the branch isn't in the yml
117
+ if !git_branch
118
+ git_branch = `git branch | grep "*"`
119
+ git_branch.gsub!("* ","")
120
+ end
121
+
122
+ #ssh in
123
+ Net::SSH.start(host, user) do |ssh|
124
+ puts "Connected to host: #{host}"
125
+
126
+ puts "Changing to project dir and pulling #{git_remote}/#{git_branch}"
127
+ puts ssh.exec!("cd #{remote_path} && git fetch")
128
+ puts ssh.exec!("cd #{remote_path} && git checkout #{git_branch}")
129
+ puts ssh.exec!("cd #{remote_path} && git pull #{git_remote} #{git_branch}")
130
+
131
+ if bundle && bundle == 'true'
132
+ puts ssh.exec!("cd #{remote_path} && bundle install")
133
+ end
134
+
135
+ if migrate && migrate == 'true'
136
+ puts ssh.exec!("cd #{remote_path} && rake db:migrate")
137
+ end
138
+ end
139
+
140
+ else
141
+ puts "Copenhagen requires pem, host, remote_path, and git_remote values to be set in Copenhagen.yml"
142
+ end
143
+ end
144
+
145
+ def remotepullwithpassword(config)
146
+ host = config['host']
147
+ user = config['user']
148
+ password = config['password']
149
+ remote_path = config['remote_path']
150
+ git_remote = config['git_remote']
151
+ git_branch = config['git_branch']
152
+ bundle = config['bundle']
153
+ migrate = config['migrate']
154
+
155
+ if(password && host && user && remote_path && git_remote)
156
+ puts "SSHing into remote server and pulling code"
157
+
158
+ #get the current git branch if the branch isn't in the yml
159
+ if !git_branch
160
+ git_branch = `git branch | grep "*"`
161
+ git_branch.gsub!("* ","")
162
+ end
163
+
164
+ #ssh in
165
+ Net::SSH.start(host, user, :password => password) do |ssh|
166
+ puts "Connected to host: #{host}"
167
+
168
+ puts "Changing to project dir and pulling #{git_remote}/#{git_branch}"
169
+ puts ssh.exec!("cd #{remote_path} && git fetch")
170
+ puts ssh.exec!("cd #{remote_path} && git checkout #{git_branch}")
171
+ puts ssh.exec!("cd #{remote_path} && git pull #{git_remote} #{git_branch}")
172
+
173
+ if bundle && bundle == 'true'
174
+ puts ssh.exec!("cd #{remote_path} && bundle install")
175
+ end
176
+
177
+ if migrate && migrate == 'true'
178
+ puts ssh.exec!("cd #{remote_path} && rake db:migrate")
179
+ end
180
+ end
181
+
182
+ else
183
+ puts "Copenhagen requires password, user, host, remote_path, and git_remote values to be set in Copenhagen.yml"
184
+ end
185
+ end
186
+
187
+ def remotescript(config)
188
+ pem = config['pem']
189
+ host = config['host']
190
+ user = config['user']
191
+ deploy_user = config['deploy_user']
192
+ deploy_script = config['deploy_script']
193
+
194
+ if(pem && host && deploy_user && deploy_script)
195
+ puts "SSHing into remote server and running script"
196
+
197
+ #get the text of the pem
198
+ pem_text = get_pem_text(pem)
199
+
200
+ #ssh in
201
+ Net::SSH.start(host, user, :key_data => pem_text, :keys_only => TRUE) do |ssh|
202
+ puts "Connected to host: #{host}"
203
+ puts "Changing to #{deploy_user}'s home dir and running script: #{deploy_script}"
204
+ puts ssh.exec!("cd /home/#{deploy_user} && sudo su - deploy -c ./#{deploy_script}")
205
+ end
206
+
207
+ else
208
+ puts "Copenhagen requires pem, host, remote_path, git_remote, and git_branch values to be set in Copenhagen.yml"
209
+ end
210
+ end
211
+
212
+ def get_pem_text(pem)
213
+ pem_file = open(File.expand_path(pem))
214
+ pem_text = pem_file.read
215
+ return pem_text
216
+ end
217
+
218
+ end
219
+ end
@@ -0,0 +1,3 @@
1
+ module Copenhagen
2
+ VERSION = "1.6.0"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copenhagen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Boisvert, Ashe Avenue
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ssh
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: git
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Extremely opinionated deploy framework for orgs that already have an
47
+ established deploy process
48
+ email:
49
+ - tboisvert@asheavenue.com
50
+ executables:
51
+ - dip
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/dip
61
+ - copenhagen.gemspec
62
+ - img/logo.png
63
+ - lib/copenhagen.rb
64
+ - lib/copenhagen/version.rb
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Extremely opinionated deploy framework for people who already have an established
89
+ deploy process
90
+ test_files: []