capistrano-generals 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +36 -7
- data/lib/capistrano-generals.rb +0 -0
- data/lib/capistrano/generals.rb +4 -0
- data/lib/capistrano/generals/helpers.rb +10 -1
- data/lib/capistrano/generals/version.rb +1 -1
- data/lib/capistrano/tasks/deploy/symlink.rake +34 -16
- data/lib/capistrano/tasks/git.rake +13 -12
- data/lib/capistrano/tasks/setup.rake +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdebc6315f89ed9b6e0c9a4a4d14e7e73a3e6244
|
4
|
+
data.tar.gz: 5d313806553a1fc320e9a1eb46db7c6e627d4830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7502b3c0524e108402761ba462da56afc8510a61013e790f7c766543c1a28141bf61b91c6762c24bcae983a8b8d77865271444b0ccd8ec5886d1e9c5ea8367d9
|
7
|
+
data.tar.gz: 9410356ba56ad748d5444695a12573b313ebe1a81836e57d535112290397f15d66dac42038ff71d3dc7e37fa62a1bf433812d5f5884bf40dccad6963210817b1
|
data/README.md
CHANGED
@@ -1,26 +1,55 @@
|
|
1
1
|
# Capistrano::Generals
|
2
2
|
|
3
|
-
|
3
|
+
Capistrano tasks that are used quite often.
|
4
|
+
Push your code to git, upload stage specific config files.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
|
-
Add this
|
8
|
+
Add this to your application's `Gemfile`:
|
8
9
|
|
9
10
|
```ruby
|
10
|
-
|
11
|
+
group :development do
|
12
|
+
gem 'capistrano', '~> 3.2.1'
|
13
|
+
gem 'capistrano-unicorn-nginx', '~> 3.1.0'
|
14
|
+
end
|
11
15
|
```
|
12
16
|
|
13
17
|
And then execute:
|
14
18
|
|
15
|
-
$ bundle
|
19
|
+
$ bundle install
|
16
20
|
|
17
|
-
|
21
|
+
And add this to the `Capfile`:
|
18
22
|
|
19
|
-
|
23
|
+
```ruby
|
24
|
+
require 'capistrano/generals'
|
25
|
+
```
|
20
26
|
|
21
27
|
## Usage
|
28
|
+
When the generals package is added to the `Capfile`, the user can specify the required tasks.
|
29
|
+
In your `config/deploy.rb` you can add the taks by adding them to the deploy namespace like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
namespace :deploy do
|
33
|
+
before :deploy, 'git:push'
|
34
|
+
before :deploy, 'deploy:symlink:upload_linked_files'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### Git push
|
39
|
+
This first checks if there are no local changes that has not been committed.
|
40
|
+
If all changes are committed, they are pushed.
|
41
|
+
|
42
|
+
Options:
|
43
|
+
|
44
|
+
* IGNORE_DEPLOY_RB=true: This ignores changes in deploy.rb, for testing only!
|
45
|
+
* FORCE=true: Force push changes
|
46
|
+
|
47
|
+
### Upload linked files
|
48
|
+
This uploads the linked files. It first checks for a stage specific file so for
|
49
|
+
example you want to upload `database.yml` to the `staging` environment,
|
50
|
+
the system first searches for `database.staging.yml` and if it cannot find that
|
51
|
+
it will fall back to the original.
|
22
52
|
|
23
|
-
TODO: Write usage instructions here
|
24
53
|
|
25
54
|
## Contributing
|
26
55
|
|
File without changes
|
data/lib/capistrano/generals.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
module Capistrano
|
2
2
|
module Generals
|
3
3
|
module Helpers
|
4
|
-
|
5
4
|
def red text
|
6
5
|
"\033[31m#{text}\033[0m"
|
7
6
|
end
|
8
7
|
|
8
|
+
def get_config_file config, stage
|
9
|
+
path = File.dirname(config)
|
10
|
+
extension = File.extname(config)
|
11
|
+
filename = File.basename(config, extension)
|
12
|
+
extension.sub!(/^\./, '')
|
13
|
+
local_file = [filename, stage].join('.')
|
14
|
+
local_file = [local_file, extension].join('.') unless extension.empty?
|
15
|
+
local_path = File.join(path, local_file)
|
16
|
+
end
|
17
|
+
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
@@ -3,50 +3,68 @@ namespace :deploy do
|
|
3
3
|
|
4
4
|
desc 'Upload the linked files from local system'
|
5
5
|
task :upload_linked_files do
|
6
|
-
|
6
|
+
|
7
|
+
# Abort if no linked files found
|
8
|
+
if fetch(:linked_files).nil?
|
9
|
+
abort red "No linked files specified. Remove the upload_linked_files task or add linked_files."
|
10
|
+
end
|
11
|
+
|
12
|
+
# Loop through all linked files
|
13
|
+
fetch(:linked_files).each do |file_name|
|
14
|
+
|
15
|
+
# Default local_file_name is stage specific.
|
16
|
+
local_file_name = get_config_file(file_name, fetch(:stage).to_s)
|
7
17
|
|
8
18
|
# Initialize variable outsize run_locally block to make sure it can be
|
9
19
|
# passed into the remote block
|
10
20
|
local_cksum = nil
|
11
21
|
|
22
|
+
# Get file information
|
12
23
|
run_locally do
|
13
|
-
|
14
|
-
|
15
|
-
|
24
|
+
|
25
|
+
# Check if file exists, else select default file
|
26
|
+
# If default file does not exists abort.
|
27
|
+
unless File.exists? local_file_name
|
28
|
+
unless File.exists? file_name
|
29
|
+
abort red "Cannot find file #{local_file_name} or #{file_name} on local machine"
|
30
|
+
end
|
31
|
+
# The default file does exists, selecting that one
|
32
|
+
warn "Cannot find stage specific config file #{local_file_name} on local machine, taking default #{file_name}"
|
33
|
+
local_file_name = file_name
|
16
34
|
end
|
17
35
|
|
18
36
|
# Get local file info
|
19
|
-
local_cksum = capture :cksum,
|
37
|
+
local_cksum = capture :cksum, local_file_name
|
20
38
|
end
|
39
|
+
|
40
|
+
# Getting local file information
|
21
41
|
local_sum, local_size, local_path = local_cksum.split
|
22
42
|
|
23
43
|
on roles :app do
|
24
44
|
# Create directory
|
25
|
-
dir_path = File.join shared_path, File.dirname(
|
45
|
+
dir_path = File.join shared_path, File.dirname(file_name)
|
26
46
|
execute :mkdir, '-p', dir_path
|
27
47
|
|
28
48
|
# Check if file already exists on remote
|
29
|
-
|
30
|
-
if test("[ -f #{
|
49
|
+
remote_file_name = File.join shared_path, file_name
|
50
|
+
if test("[ -f #{remote_file_name} ]")
|
31
51
|
# File already exists
|
32
52
|
# Get remote file info
|
33
|
-
remote_cksum = capture :cksum,
|
53
|
+
remote_cksum = capture :cksum, remote_file_name
|
34
54
|
remote_sum, remote_size, remote_path = remote_cksum.split
|
35
55
|
|
36
56
|
# Check if the file has changed
|
37
57
|
if local_sum == remote_sum
|
38
|
-
info "#{
|
58
|
+
info "Remote #{remote_file_name} already up to date with local #{local_file_name}."
|
39
59
|
else
|
40
|
-
upload!
|
41
|
-
info "Replaced #{
|
60
|
+
upload! local_file_name, remote_file_name
|
61
|
+
info "Replaced #{local_file_name} -> #{remote_file_name}"
|
42
62
|
end
|
43
|
-
|
44
63
|
else
|
45
64
|
# File does not exists
|
46
|
-
upload!
|
47
|
-
info "Uploaded #{
|
65
|
+
upload! local_file_name, remote_file_name
|
66
|
+
info "Uploaded #{local_file_name} -> #{remote_file_name}"
|
48
67
|
end
|
49
|
-
|
50
68
|
end
|
51
69
|
|
52
70
|
end
|
@@ -4,20 +4,21 @@ namespace :git do
|
|
4
4
|
task :push do
|
5
5
|
# Check for any local changes that haven't been committed
|
6
6
|
# Use 'cap git:push IGNORE_DEPLOY_RB=1' to ignore changes to this file (for testing)
|
7
|
-
|
8
|
-
|
9
|
-
if status
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
run_locally do
|
8
|
+
status = %x(git status --porcelain).chomp
|
9
|
+
if status != ""
|
10
|
+
if status !~ %r{^[M ][M ] config/deploy.rb$}
|
11
|
+
abort "Local git repository has uncommitted changes"
|
12
|
+
elsif !ENV["IGNORE_DEPLOY_RB"]
|
13
|
+
# This is used for testing changes to this script without committing them first
|
14
|
+
abort red "Local git repository has uncommitted changes (set IGNORE_DEPLOY_RB=1 to ignore changes to deploy.rb)"
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# Push selected branch to github
|
19
|
+
unless system "git push #{repo_url} #{fetch(:branch)} #{'-f' if ENV['FORCE']}"
|
20
|
+
abort red "Failed to push changes to #{fetch(:repo_url)} (set FORCE=true to force push to github)"
|
21
|
+
end
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :setup do
|
2
|
+
|
3
|
+
desc "Symlinks config files for Nginx and Unicorn"
|
4
|
+
task :symlink_nginx_and_unicorn do
|
5
|
+
on roles(:app) do
|
6
|
+
execute "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{fetch(:application)}"
|
7
|
+
execute "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{fetch(:application)}"
|
8
|
+
# Start unicorn at startup
|
9
|
+
execute "sudo update-rc.d unicorn_#{fetch(:application)} defaults"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-generals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stef Schenkelaars
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -65,11 +65,13 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- capistrano-generals.gemspec
|
68
|
+
- lib/capistrano-generals.rb
|
68
69
|
- lib/capistrano/generals.rb
|
69
70
|
- lib/capistrano/generals/helpers.rb
|
70
71
|
- lib/capistrano/generals/version.rb
|
71
72
|
- lib/capistrano/tasks/deploy/symlink.rake
|
72
73
|
- lib/capistrano/tasks/git.rake
|
74
|
+
- lib/capistrano/tasks/setup.rake
|
73
75
|
homepage: ''
|
74
76
|
licenses:
|
75
77
|
- MIT
|