capistrano-twingly 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 528f4b59cff0904b683bbbfe898cf31c6b543e22
4
+ data.tar.gz: 2c711952f983adfa9d1e54fbbbcab882bcc0c192
5
+ SHA512:
6
+ metadata.gz: abac6cf327cb4e00eeb1c9ac13e10591e83d108616eef345b1105c1022cebfeb1915c53e7038eb3b123c25cfb5b6f0dd4751b40cee78b6f39f48c13848998b3a
7
+ data.tar.gz: 8a9c455e638ff63fa1ae017385ec806053c90055eea0fb3abc63702fe930e84639e069e8f5b0e37b97983295fec7d491f345f3d2ad3e59e9267f43c82b623626
@@ -0,0 +1,19 @@
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
18
+ Capfile
19
+ config
@@ -0,0 +1,144 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/twingly/capistrano-twingly/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v2.0.1...HEAD)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - foreman isn't defined as an dependency [\#29](https://github.com/twingly/capistrano-twingly/issues/29)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Various improvements to be able to DRY up config in our apps [\#36](https://github.com/twingly/capistrano-twingly/pull/36) ([dentarg](https://github.com/dentarg))
14
+ - Add foreman as a dependency [\#30](https://github.com/twingly/capistrano-twingly/pull/30) ([jage](https://github.com/jage))
15
+
16
+ ## [v2.0.1](https://github.com/twingly/capistrano-twingly/tree/v2.0.1) (2016-09-06)
17
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v2.0.0...v2.0.1)
18
+
19
+ ## [v2.0.0](https://github.com/twingly/capistrano-twingly/tree/v2.0.0) (2016-06-13)
20
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.8.0...v2.0.0)
21
+
22
+ **Implemented enhancements:**
23
+
24
+ - Webserver is hardcoded [\#20](https://github.com/twingly/capistrano-twingly/issues/20)
25
+
26
+ **Merged pull requests:**
27
+
28
+ - Use generic socket name [\#27](https://github.com/twingly/capistrano-twingly/pull/27) ([jage](https://github.com/jage))
29
+
30
+ ## [v1.8.0](https://github.com/twingly/capistrano-twingly/tree/v1.8.0) (2016-05-03)
31
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.7.1...v1.8.0)
32
+
33
+ **Merged pull requests:**
34
+
35
+ - Send process output to syslog [\#26](https://github.com/twingly/capistrano-twingly/pull/26) ([roback](https://github.com/roback))
36
+
37
+ ## [v1.7.1](https://github.com/twingly/capistrano-twingly/tree/v1.7.1) (2015-02-16)
38
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.7.0...v1.7.1)
39
+
40
+ ## [v1.7.0](https://github.com/twingly/capistrano-twingly/tree/v1.7.0) (2014-12-09)
41
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.6.2...v1.7.0)
42
+
43
+ **Fixed bugs:**
44
+
45
+ - Cancel deploy if we get 0 servers from SRV record [\#17](https://github.com/twingly/capistrano-twingly/issues/17)
46
+
47
+ **Closed issues:**
48
+
49
+ - Deployed failed, but git tag was pushed \("No Matching Host"\) [\#14](https://github.com/twingly/capistrano-twingly/issues/14)
50
+
51
+ **Merged pull requests:**
52
+
53
+ - Fail if no servers \(SRV-records\) are found [\#22](https://github.com/twingly/capistrano-twingly/pull/22) ([jage](https://github.com/jage))
54
+
55
+ ## [v1.6.2](https://github.com/twingly/capistrano-twingly/tree/v1.6.2) (2014-09-19)
56
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.6.1...v1.6.2)
57
+
58
+ ## [v1.6.1](https://github.com/twingly/capistrano-twingly/tree/v1.6.1) (2014-07-28)
59
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.6.0...v1.6.1)
60
+
61
+ **Implemented enhancements:**
62
+
63
+ - Disable autostart when stopping an application [\#15](https://github.com/twingly/capistrano-twingly/issues/15)
64
+
65
+ **Merged pull requests:**
66
+
67
+ - Add ability to control autostart in upstart [\#21](https://github.com/twingly/capistrano-twingly/pull/21) ([jage](https://github.com/jage))
68
+
69
+ ## [v1.6.0](https://github.com/twingly/capistrano-twingly/tree/v1.6.0) (2014-07-28)
70
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.5.1...v1.6.0)
71
+
72
+ ## [v1.5.1](https://github.com/twingly/capistrano-twingly/tree/v1.5.1) (2014-05-12)
73
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.5.0...v1.5.1)
74
+
75
+ **Implemented enhancements:**
76
+
77
+ - Create temporary files in tmp/ [\#9](https://github.com/twingly/capistrano-twingly/issues/9)
78
+
79
+ ## [v1.5.0](https://github.com/twingly/capistrano-twingly/tree/v1.5.0) (2014-05-12)
80
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.4.0...v1.5.0)
81
+
82
+ ## [v1.4.0](https://github.com/twingly/capistrano-twingly/tree/v1.4.0) (2014-03-31)
83
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.3.0...v1.4.0)
84
+
85
+ **Merged pull requests:**
86
+
87
+ - Make it easy to deploy the current git branch [\#13](https://github.com/twingly/capistrano-twingly/pull/13) ([dentarg](https://github.com/dentarg))
88
+ - If system/maintenance.html exist, show it [\#12](https://github.com/twingly/capistrano-twingly/pull/12) ([jage](https://github.com/jage))
89
+
90
+ ## [v1.3.0](https://github.com/twingly/capistrano-twingly/tree/v1.3.0) (2014-03-26)
91
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.2.1...v1.3.0)
92
+
93
+ **Merged pull requests:**
94
+
95
+ - Fix deploy namespace for Nginx tasks in README. [\#11](https://github.com/twingly/capistrano-twingly/pull/11) ([benmanns](https://github.com/benmanns))
96
+
97
+ ## [v1.2.1](https://github.com/twingly/capistrano-twingly/tree/v1.2.1) (2014-02-14)
98
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.1.1...v1.2.1)
99
+
100
+ **Closed issues:**
101
+
102
+ - Add stage name to git deploy tag [\#8](https://github.com/twingly/capistrano-twingly/issues/8)
103
+
104
+ ## [v1.1.1](https://github.com/twingly/capistrano-twingly/tree/v1.1.1) (2014-02-11)
105
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.0.1...v1.1.1)
106
+
107
+ ## [v1.0.1](https://github.com/twingly/capistrano-twingly/tree/v1.0.1) (2014-02-11)
108
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v1.0.0...v1.0.1)
109
+
110
+ **Closed issues:**
111
+
112
+ - Bug in nginx.rake [\#6](https://github.com/twingly/capistrano-twingly/issues/6)
113
+
114
+ ## [v1.0.0](https://github.com/twingly/capistrano-twingly/tree/v1.0.0) (2014-02-11)
115
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v0.1.4...v1.0.0)
116
+
117
+ ## [v0.1.4](https://github.com/twingly/capistrano-twingly/tree/v0.1.4) (2014-02-10)
118
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v0.1.3...v0.1.4)
119
+
120
+ **Implemented enhancements:**
121
+
122
+ - nginx task requires constants [\#3](https://github.com/twingly/capistrano-twingly/issues/3)
123
+
124
+ ## [v0.1.3](https://github.com/twingly/capistrano-twingly/tree/v0.1.3) (2014-02-04)
125
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v0.1.2...v0.1.3)
126
+
127
+ **Fixed bugs:**
128
+
129
+ - HTTPS support missing [\#4](https://github.com/twingly/capistrano-twingly/issues/4)
130
+
131
+ ## [v0.1.2](https://github.com/twingly/capistrano-twingly/tree/v0.1.2) (2014-01-31)
132
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v0.1.1...v0.1.2)
133
+
134
+ ## [v0.1.1](https://github.com/twingly/capistrano-twingly/tree/v0.1.1) (2014-01-15)
135
+ [Full Changelog](https://github.com/twingly/capistrano-twingly/compare/v0.1.0...v0.1.1)
136
+
137
+ **Implemented enhancements:**
138
+
139
+ - Make repo public [\#2](https://github.com/twingly/capistrano-twingly/issues/2)
140
+
141
+ ## [v0.1.0](https://github.com/twingly/capistrano-twingly/tree/v0.1.0) (2014-01-14)
142
+
143
+
144
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-twingly.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Twingly AB
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,150 @@
1
+ # Capistrano::Twingly
2
+
3
+ Capistrano 3 tasks used for Twingly's Ruby deployment
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-twingly', github: 'twingly/capistrano-twingly'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ If you want to require all dependencies ([capistrano], [capistrano-bundler], [capistrano-chruby]) and all task helpers, it is possible to do so with one line:
18
+
19
+ ```Ruby
20
+ # Capfile
21
+ require 'capistrano/twingly'
22
+ ```
23
+
24
+ [capistrano]: https://github.com/capistrano/capistrano
25
+ [capistrano-bundler]: https://github.com/capistrano/capistrano-bundler
26
+ [capistrano-chruby]: https://github.com/capistrano/capistrano-chruby
27
+
28
+ See below if you want to selectively require tasks. In any case, you need to set variables and specify tasks as demonstrated below.
29
+
30
+ ### Deploy current git branch
31
+
32
+ ```Ruby
33
+ # Capfile
34
+ require 'capistrano/twingly/current_git_branch'
35
+
36
+ # config/deploy/production.rb
37
+ set :branch, Twingly::Git.current_branch
38
+ ```
39
+
40
+ ### Nginx tasks
41
+
42
+ ```Ruby
43
+ # Capfile
44
+ require 'capistrano/twingly/nginx'
45
+
46
+ # config/deploy.rb
47
+ set :app_name, 'contest-bamba'
48
+ set :server_names, %w(bamba.bloggportalen.se) # Optional
49
+ set :use_https, true # Optional
50
+
51
+ namespace :deploy do
52
+ after :finishing, 'deploy:nginx:generate_config'
53
+ after :finishing, 'deploy:nginx:upload_config'
54
+ after :finishing, 'deploy:nginx:enable_config'
55
+ after :finishing, 'deploy:nginx:reload'
56
+ end
57
+ ```
58
+
59
+ ### Upstart
60
+
61
+ ```Ruby
62
+ # Capfile
63
+ require 'capistrano/twingly/upstart'
64
+
65
+ # config/deploy.rb
66
+ set :procfile_contents, -> {
67
+ contents = ''
68
+ contents << "web: "
69
+ contents << "chruby-exec #{fetch(:chruby_ruby)} -- "
70
+ contents << "bundle exec "
71
+ contents << "puma "
72
+ contents << "-b unix:///tmp/#{fetch(:app_name)}.sock "
73
+ contents << "-e #{fetch(:stage)}"
74
+ }
75
+
76
+ namespace :deploy do
77
+ desc 'Start application'
78
+ task :start do
79
+ invoke 'deploy:export_upstart'
80
+ on roles(:app) do
81
+ sudo :start, fetch(:application)
82
+ end
83
+ end
84
+
85
+ desc 'Restart application'
86
+ task :restart do
87
+ invoke 'deploy:export_upstart'
88
+ on roles(:app) do
89
+ execute "sudo restart #{fetch(:application)} || sudo start #{fetch(:application)}"
90
+ end
91
+ end
92
+
93
+ desc 'Stop application'
94
+ task :stop do
95
+ on roles(:app) do
96
+ sudo :stop, fetch(:application)
97
+ end
98
+ end
99
+
100
+ after :stop, 'deploy:disable_autostart'
101
+ after :start, 'deploy:enable_autostart'
102
+ after :restart, 'deploy:enable_autostart'
103
+ end
104
+ ```
105
+
106
+ ### Tag deploys in Git
107
+
108
+ ```Ruby
109
+ # Capfile
110
+ require 'capistrano/twingly/tag_deploy_in_git'
111
+
112
+ # config/deploy.rb
113
+ namespace :deploy do
114
+ after :finishing, 'deploy:push_deploy_tag'
115
+ end
116
+ ```
117
+
118
+ ### Fetch servers from SRV record
119
+
120
+ ```Ruby
121
+ # Capfile
122
+ require 'capistrano/twingly/servers_from_srv_record'
123
+
124
+ # config/deploy/production.rb
125
+ fetch(:servers_from_srv_record).each do |hostname|
126
+ server hostname, user: 'deploy', roles: %w{app}
127
+ end
128
+ ```
129
+
130
+ ## Release workflow
131
+
132
+ * Update the examples in this README if needed.
133
+
134
+ * Bump the version in `capistrano-twingly.gemspec` in a commit, no need to push (the release task does that).
135
+
136
+ * Build and [publish](http://guides.rubygems.org/publishing/) the gem. This will create the proper tag in git, push the commit and tag and upload to RubyGems.
137
+
138
+ bundle exec rake release
139
+
140
+ * If you are not logged in as [twingly][twingly-rubygems] with ruby gems, the rake task will fail and tell you to set credentials via `gem push`, do that and run the `release` task again. It will be okay.
141
+
142
+ * Update the changelog with [GitHub Changelog Generator](https://github.com/skywinder/github-changelog-generator/) (`gem install github_changelog_generator` if you don't have it, set `CHANGELOG_GITHUB_TOKEN` to a personal access token to avoid rate limiting by GitHub). This command will update `CHANGELOG.md`, commit and push manually.
143
+
144
+ github_changelog_generator
145
+
146
+ ## Note about `CHANGELOG.md`
147
+
148
+ The changelog is incorrect for some old versions, where the version was increased before the pull request was merged. This is due to how `github_changelog_generator` works.
149
+
150
+ [twingly-rubygems]: https://rubygems.org/profiles/twingly
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capistrano-twingly"
7
+ spec.version = '2.1.0'
8
+ spec.authors = ["Twingly AB"]
9
+ spec.email = ["support@twingly.com"]
10
+ spec.summary = %q{Capistrano 3 tasks used for Twingly's Ruby deployment}
11
+ spec.description = %q{Capistrano 3 tasks used for Twingly's Ruby deployment}
12
+ spec.homepage = "https://github.com/twingly/capistrano-twingly"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "capistrano", "~> 3.6.0"
21
+ spec.add_dependency "capistrano-bundler", "1.1.4"
22
+ spec.add_dependency "capistrano-chruby", "0.1.2"
23
+ spec.add_dependency "foreman", "~> 0.82"
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,19 @@
1
+ # Load DSL and set up stages
2
+ require "capistrano/setup"
3
+
4
+ # Include default deployment tasks
5
+ require "capistrano/deploy"
6
+
7
+ # Console to the servers
8
+ require "capistrano/console"
9
+
10
+ # Gems
11
+ require "capistrano/chruby"
12
+ require "capistrano/bundler"
13
+
14
+ # Twingly tasks
15
+ require "capistrano/twingly/nginx"
16
+ require "capistrano/twingly/upstart"
17
+ require "capistrano/twingly/tag_deploy_in_git"
18
+ require "capistrano/twingly/current_git_branch"
19
+ require "capistrano/twingly/servers_from_srv_record"
@@ -0,0 +1,20 @@
1
+ load File.expand_path("../tasks/current_git_branch.rake", __FILE__)
2
+
3
+ module Twingly
4
+ module Git
5
+ module_function
6
+
7
+ # Colors are pretty!
8
+ def red(str)
9
+ "\e[31m#{str}\e[0m"
10
+ end
11
+
12
+ def info
13
+ "branch #{red(fetch(:branch))} to stage #{red(fetch(:stage))}"
14
+ end
15
+
16
+ def current_branch
17
+ `git symbolic-ref HEAD 2> /dev/null`.strip.gsub(/^refs\/heads\//, '')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/nginx.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/servers_from_srv_record.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/tag_deploy_in_git.rake", __FILE__)
@@ -0,0 +1,5 @@
1
+ after :deploy, :echo_current_git_branch_after do
2
+ run_locally do
3
+ info "Deployed #{Twingly::Git.info}"
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ namespace :deploy do
2
+ namespace :nginx do
3
+ desc 'Generate Nginx configuration'
4
+ task :generate_config do
5
+ Dir.mkdir('tmp') unless Dir.exist?('tmp')
6
+
7
+ app_dir = fetch(:deploy_to)
8
+ app_name = fetch(:app_name)
9
+ server_names = Array(fetch(:server_names))
10
+ server_names << "#{app_name}.live.lkp.primelabs.se"
11
+
12
+ https_port = ":443" if fetch(:use_https)
13
+
14
+ conf = File.open('tmp/site.conf', 'w')
15
+ conf << %Q{
16
+ upstream #{app_name} {
17
+ server unix:/tmp/#{app_name}.sock;
18
+ }
19
+
20
+ server {
21
+ listen 80;
22
+ server_name #{server_names.join(' ')};
23
+
24
+ root #{app_dir}/current/public;
25
+
26
+ try_files /system/maintenance.html $uri @app;
27
+
28
+ location /assets {
29
+ expires 1h;
30
+ }
31
+ location /favicon.ico {
32
+ expires 1h;
33
+ }
34
+ location /robots.txt {
35
+ expires 1h;
36
+ }
37
+
38
+ expires -1;
39
+ location @app {
40
+ expires off;
41
+ proxy_pass http://#{app_name};
42
+ proxy_redirect off;
43
+ proxy_set_header Host $host#{https_port};
44
+ proxy_set_header X-Real-IP $remote_addr;
45
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
46
+ }
47
+ }\n}
48
+ conf.close
49
+ end
50
+
51
+ desc 'Upload Nginx configuration'
52
+ task :upload_config do
53
+ on roles(:app) do
54
+ app_name = fetch(:app_name)
55
+ upload! 'tmp/site.conf', "/etc/nginx/sites-available/#{app_name}.conf"
56
+ end
57
+ end
58
+
59
+ desc 'Symlink Nginx configuration'
60
+ task :enable_config do
61
+ on roles(:app) do
62
+ app_name = fetch(:app_name)
63
+ execute :ln, '-nfs', "/etc/nginx/sites-available/#{app_name}.conf", "/etc/nginx/sites-enabled/#{app_name}.conf"
64
+ end
65
+ end
66
+
67
+ desc 'Reload Nginx'
68
+ task :reload do
69
+ on roles(:app) do
70
+ execute :sudo, 'service', 'nginx', 'reload'
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ require 'resolv'
2
+
3
+ SRV_RECORD = '_rubyapps._tcp.live.lkp.primelabs.se'
4
+
5
+ resolver = Resolv::DNS.new
6
+ resources = resolver.getresources(
7
+ SRV_RECORD,
8
+ Resolv::DNS::Resource::IN::SRV)
9
+ servers = resources.map(&:target).map(&:to_s)
10
+
11
+ raise "Can't find any servers, no records for #{SRV_RECORD}" if servers.empty?
12
+
13
+ set :servers_from_srv_record, servers
14
+
15
+ namespace :list do
16
+ desc 'List servers from SRV records'
17
+ task :servers do
18
+ servers.each { |server| puts server }
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ namespace :deploy do
2
+ desc "Create a release tag and push it"
3
+ task :push_deploy_tag do
4
+ user = `git config --get user.name`.chomp
5
+ email = `git config --get user.email`.chomp
6
+ tag_name = "#{Time.now.strftime("%Y-%m-%d__%H_%M_%S")}__#{fetch(:stage)}"
7
+ revision = fetch(:current_revision)
8
+
9
+ message = "Deployed by #{user} <#{email}>"
10
+
11
+ run_locally do
12
+ execute "git tag #{tag_name} #{revision} -m \"#{message}\""
13
+ execute "git push origin refs/tags/#{tag_name}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ namespace :deploy do
2
+ set :bundle_binstubs, -> { shared_path.join('bin') }
3
+
4
+ desc 'Export upstart script'
5
+ task :export_upstart do
6
+ on roles(:app) do
7
+ within current_path do
8
+ sudo fetch(:chruby_exec), "#{fetch(:chruby_ruby)} -- #{fetch(:bundle_binstubs)}/foreman export upstart /etc/init -a #{fetch(:application)} -u \`whoami\` -l #{shared_path}/log"
9
+ end
10
+ end
11
+ end
12
+
13
+ task :disable_autostart do
14
+ on roles(:app) do
15
+ execute "/bin/echo manual | sudo /usr/bin/tee /etc/init/#{fetch(:application)}.override"
16
+ end
17
+ end
18
+
19
+ task :enable_autostart do
20
+ on roles(:app) do
21
+ execute "/bin/echo | sudo /usr/bin/tee /etc/init/#{fetch(:application)}.override"
22
+ end
23
+ end
24
+
25
+ namespace :foreman do
26
+ desc 'Upload Procfile to server'
27
+ task :upload_procfile do
28
+ on roles(:app) do
29
+ upload! 'tmp/Procfile', "#{fetch(:deploy_to)}/current/Procfile"
30
+ end
31
+ end
32
+
33
+ desc 'Generate Procfile'
34
+ task :generate_procfile do
35
+ Dir.mkdir('tmp') unless Dir.exist?('tmp')
36
+
37
+ File.open('tmp/Procfile', 'w') do |conf|
38
+ fetch(:procfile_contents).each_line do |line|
39
+ conf.puts "#{line.chomp} 2>&1 | logger -t #{fetch(:app_name)}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ before 'deploy:export_upstart', 'deploy:foreman:upload_procfile'
46
+ before 'deploy:foreman:upload_procfile', 'deploy:foreman:generate_procfile'
47
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/upstart.rake", __FILE__)
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-twingly
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Twingly AB
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-chruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: foreman
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.82'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.82'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Capistrano 3 tasks used for Twingly's Ruby deployment
98
+ email:
99
+ - support@twingly.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - capistrano-twingly.gemspec
111
+ - lib/capistrano/twingly.rb
112
+ - lib/capistrano/twingly/current_git_branch.rb
113
+ - lib/capistrano/twingly/nginx.rb
114
+ - lib/capistrano/twingly/servers_from_srv_record.rb
115
+ - lib/capistrano/twingly/tag_deploy_in_git.rb
116
+ - lib/capistrano/twingly/tasks/current_git_branch.rake
117
+ - lib/capistrano/twingly/tasks/nginx.rake
118
+ - lib/capistrano/twingly/tasks/servers_from_srv_record.rake
119
+ - lib/capistrano/twingly/tasks/tag_deploy_in_git.rake
120
+ - lib/capistrano/twingly/tasks/upstart.rake
121
+ - lib/capistrano/twingly/upstart.rb
122
+ homepage: https://github.com/twingly/capistrano-twingly
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Capistrano 3 tasks used for Twingly's Ruby deployment
146
+ test_files: []