capistrano-templating 1.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +119 -0
- data/Rakefile +2 -0
- data/capistrano-templating.gemspec +25 -0
- data/example/.gitignore +5 -0
- data/example/Capfile +12 -0
- data/example/Gemfile +4 -0
- data/example/config/deploy.rb +33 -0
- data/example/config/deploy/local.rb +3 -0
- data/example/config/deploy/production.rb +1 -0
- data/example/lib/capistrano/templates/config.php.erb +3 -0
- data/example/lib/capistrano/templates/deploy.html.erb +5 -0
- data/lib/capistrano/templating.rb +9 -0
- data/lib/capistrano/templating/tasks/template.cap +77 -0
- data/lib/capistrano/templating/version.rb +5 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60357a96aa386dd2222ab229ec464a20d3a1263c
|
4
|
+
data.tar.gz: 6602c4b6e8cbd8da3ddee11ef69cdcfc45de2a79
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 959f6f8b53eee0504a558c30862c6b7a385a5865b9522027b9fc04bc79b3577b220de944f4baa7e74c483e5fcb63f16df3e6002d44f958752ac5e283d77755cb
|
7
|
+
data.tar.gz: 41817232dd64c57c632fe97ad3b1705789a79a01cce60eb8e953120207ade4d430de4646f5f8948de2e9e1a1f755bc032352a96deab1891438f660931d40aa98
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Xavier Priour
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Capistrano::Templating
|
2
|
+
|
3
|
+
A [Capistrano](http://capistranorb.com/) gem to generate files from templates on deployment.
|
4
|
+
|
5
|
+
In a typical application, configuration files contain lots of code common to all stages, and a few differences (like database or mail server and credentials).
|
6
|
+
This gem lets you put common code in ERB templates,
|
7
|
+
and manage variable parts using Capistrano variables (`set :var_name, 'value'`)
|
8
|
+
or [capistrano-secret](https://github.com/xavierpriour/capistrano-secret).
|
9
|
+
|
10
|
+
This is especially useful to generate configuration files for various server elements, based on DRY secret files + single template for each configuration file.
|
11
|
+
|
12
|
+
|
13
|
+
## Quick start
|
14
|
+
|
15
|
+
In a shell:
|
16
|
+
```bash
|
17
|
+
gem install capistrano-templating
|
18
|
+
echo "require 'capistrano/templating'" >> Capfile
|
19
|
+
mkdir -p lib/capistrano/templates
|
20
|
+
echo "Deployed to <%= fetch(:stage) %> at <%= Time.new() %>" > lib/capistrano/templates/deploy.html.erb
|
21
|
+
```
|
22
|
+
|
23
|
+
Then in `deploy.rb`:
|
24
|
+
```ruby
|
25
|
+
set_template 'www/deploy.html', 'deploy.html.erb';
|
26
|
+
```
|
27
|
+
|
28
|
+
|
29
|
+
## Features
|
30
|
+
|
31
|
+
Capistrano::Templating advantages:
|
32
|
+
* all common code is centralized in the template: no duplication (DRY).
|
33
|
+
* file can be generated anywhere (even in multiple places), with any name.
|
34
|
+
* any file format can be generated.
|
35
|
+
|
36
|
+
When combined with [capistrano-secret](https://github.com/xavierpriour/capistrano-secret),
|
37
|
+
enables perfect separation of responsibilities:
|
38
|
+
* all secret information in easy-to-read JSON, stored in dedicated folder
|
39
|
+
* syntax wrapping (for configuration file, deployment pages, or else) concentrated in templates
|
40
|
+
|
41
|
+
In details:
|
42
|
+
* 2-step generation: files are generated in a separate build local folder, then copied into release dir. This allows local view of the generated files for debugging.
|
43
|
+
* generated file path and name is specified separately from template file. This lets you put all templates in the same folder, yet dispatch generated files everywhere.
|
44
|
+
|
45
|
+
Compared to [capistrano-template](https://github.com/faber-lotto/capistrano-template) gem,
|
46
|
+
Capistrano::Templating uses a declarative syntax (`set_template` then automatic generation),
|
47
|
+
whereas capistrano-template uses an imperative syntax (ask for render using `template`).
|
48
|
+
Pick the one that suits you best!
|
49
|
+
|
50
|
+
|
51
|
+
## Requirements
|
52
|
+
|
53
|
+
* [Capistrano 3](http://capistranorb.com/)
|
54
|
+
|
55
|
+
All dependencies are listed in the .gemspec file so if using `bundler` you just need to `bundle install` in your project directory.
|
56
|
+
|
57
|
+
|
58
|
+
## Installation
|
59
|
+
|
60
|
+
Add this line to your application's Gemfile:
|
61
|
+
```
|
62
|
+
gem 'capistrano-templating'
|
63
|
+
```
|
64
|
+
|
65
|
+
And then execute:
|
66
|
+
```bash
|
67
|
+
bundle
|
68
|
+
```
|
69
|
+
|
70
|
+
Or install it yourself as:
|
71
|
+
```bash
|
72
|
+
gem install capistrano-templating
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
An example application is included in the `example` folder.
|
79
|
+
|
80
|
+
Include gem in your `Capfile`:
|
81
|
+
```ruby
|
82
|
+
require 'capistrano/templating'
|
83
|
+
```
|
84
|
+
|
85
|
+
Create directory where templates will be stored.
|
86
|
+
Default is `lib/capistrano/template`, to use a different one define `template_src_dir` in `deploy.rb`:
|
87
|
+
```ruby
|
88
|
+
set :template_src_dir, 'new/template/dir'
|
89
|
+
```
|
90
|
+
|
91
|
+
Define directory where generated files will be stored.
|
92
|
+
Default is `build`, to use a different one define `template_build_dir` in `deploy.rb`:
|
93
|
+
```ruby
|
94
|
+
set :template_build_dir, 'new/build/dir'
|
95
|
+
```
|
96
|
+
Ensure the build directory stays out of repository (for git, add it to `.gitignore`):
|
97
|
+
```bash
|
98
|
+
echo 'build' >> .gitignore
|
99
|
+
```
|
100
|
+
|
101
|
+
Then in the template directory, create one ERB file per model of file needed.
|
102
|
+
As a naming convention, we suggest `name_and_ext_of_target.erb`. For example, `.htaccess.erb` to generate `.htaccess`.
|
103
|
+
|
104
|
+
Finally, declare the files to generate in `deploy.rb` or the stage files (like `production.rb`):
|
105
|
+
```ruby
|
106
|
+
set_template 'path/to/result.html', 'template.html.erb'
|
107
|
+
```
|
108
|
+
Destination filepaths are relative to application root folder, template paths are relative to template directory.
|
109
|
+
|
110
|
+
At the end of deployment, capistrano will automatically generate the files in the local build dir (including sub-directory creation),
|
111
|
+
then upload them in the remote release directories.
|
112
|
+
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
1. Fork it ( https://github.com/xavierpriour/capistrano-templating/fork )
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/templating/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-templating"
|
8
|
+
spec.version = Capistrano::Templating::VERSION
|
9
|
+
spec.authors = ["Xavier Priour"]
|
10
|
+
spec.email = ["xavier.priour@bubblyware.com"]
|
11
|
+
spec.summary = %q{Capistrano gem to generate files from templates on deployment}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://github.com/xavierpriour/capistrano-templating"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "capistrano", "~> 3"
|
25
|
+
end
|
data/example/.gitignore
ADDED
data/example/Capfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Load DSL and Setup Up Stages
|
2
|
+
require 'capistrano/setup'
|
3
|
+
|
4
|
+
# Includes default deployment tasks
|
5
|
+
require 'capistrano/deploy'
|
6
|
+
|
7
|
+
# Includes tasks from other gems included in your Gemfile
|
8
|
+
require 'capistrano/secret'
|
9
|
+
require 'capistrano/templating'
|
10
|
+
|
11
|
+
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
|
12
|
+
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
|
data/example/Gemfile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
set_template 'www/deploy.html', 'deploy.html.erb'
|
2
|
+
set_template 'www/php/config.php', 'config.php.erb'
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
set :application, 'capistrano_example_app'
|
7
|
+
|
8
|
+
set :scm, :git
|
9
|
+
set :repo_url, 'https://github.com/xavierpriour/capistrano-template.git'
|
10
|
+
|
11
|
+
|
12
|
+
namespace :deploy do
|
13
|
+
|
14
|
+
desc 'Restart application'
|
15
|
+
task :restart do
|
16
|
+
on roles(:app), in: :sequence, wait: 5 do
|
17
|
+
# Your restart mechanism here, for example:
|
18
|
+
# execute :touch, release_path.join('tmp/restart.txt')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after :publishing, :restart
|
23
|
+
|
24
|
+
after :restart, :clear_cache do
|
25
|
+
on roles(:web), in: :groups, limit: 3, wait: 10 do
|
26
|
+
# Here we can do anything such as:
|
27
|
+
# within release_path do
|
28
|
+
# execute :rake, 'cache:clear'
|
29
|
+
# end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
|
@@ -0,0 +1,77 @@
|
|
1
|
+
def set_template(file, template)
|
2
|
+
unless fetch(:templates)
|
3
|
+
set :templates, {}
|
4
|
+
end
|
5
|
+
fetch(:templates)[file] = template
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :template do
|
9
|
+
def template_dir()
|
10
|
+
return fetch(:template_src_dir) || 'lib/capistrano/templates'
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_dir()
|
14
|
+
return fetch(:template_build_dir) || 'build'
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
desc <<-DESC
|
19
|
+
Generate all templates defined in :templates.
|
20
|
+
|
21
|
+
1. generate in local build dir, with destination names
|
22
|
+
2. upload to remote release dir, merging with non-generated files
|
23
|
+
|
24
|
+
We used to upload in build dir then symlink, but switched to direct merge to support hosts without symlink support.
|
25
|
+
DESC
|
26
|
+
task :generate do
|
27
|
+
templates_list = fetch(:templates, {});
|
28
|
+
|
29
|
+
templates_list.each do |dst, src|
|
30
|
+
# splits destination in optional relative dir / filename
|
31
|
+
m = /(.*\/)?([^\/]+)$/.match(dst)
|
32
|
+
dst_rel_dir = m[1]
|
33
|
+
dst_file = m[2]
|
34
|
+
#create local build dirs as needed
|
35
|
+
build_dir = "#{build_dir()}/#{dst_rel_dir}"
|
36
|
+
%x(mkdir -p #{build_dir})
|
37
|
+
build_filepath = "#{build_dir}#{dst_file}"
|
38
|
+
# get template and render it
|
39
|
+
template_filepath = "#{template_dir()}/#{src}"
|
40
|
+
template = File.read(template_filepath)
|
41
|
+
File.open(build_filepath, 'w+') do |f|
|
42
|
+
f.write(ERB.new(template).result(binding))
|
43
|
+
end
|
44
|
+
|
45
|
+
on roles(:all) do |host|
|
46
|
+
# create remote build dir
|
47
|
+
if dst_rel_dir
|
48
|
+
execute "mkdir -p #{release_path.to_s}/#{dst_rel_dir}"
|
49
|
+
end
|
50
|
+
upload! build_filepath, release_path.to_s+'/'+dst
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "cleanup everything that was built"
|
56
|
+
task :clear_dir do
|
57
|
+
# clean all build artifacts
|
58
|
+
%x(rm -rf #{build_dir()})
|
59
|
+
end
|
60
|
+
|
61
|
+
task :remove do
|
62
|
+
templates_list = fetch(:templates, {});
|
63
|
+
templates_list.each do |dst, src|
|
64
|
+
on roles(:all) do |host|
|
65
|
+
# remove link
|
66
|
+
link = "#{release_path.to_s}/#{dst}"
|
67
|
+
if test("[ -f #{link} ]")
|
68
|
+
execute "rm #{link}"
|
69
|
+
end
|
70
|
+
#todo remove any dir that is now empty...
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
before 'deploy:starting', 'template:clear_dir'
|
77
|
+
after 'deploy:publishing', 'template:generate'
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-templating
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavier Priour
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capistrano
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- xavier.priour@bubblyware.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- capistrano-templating.gemspec
|
68
|
+
- example/.gitignore
|
69
|
+
- example/Capfile
|
70
|
+
- example/Gemfile
|
71
|
+
- example/config/deploy.rb
|
72
|
+
- example/config/deploy/local.rb
|
73
|
+
- example/config/deploy/production.rb
|
74
|
+
- example/config/secret/local.json
|
75
|
+
- example/config/secret/production.json
|
76
|
+
- example/lib/capistrano/templates/config.php.erb
|
77
|
+
- example/lib/capistrano/templates/deploy.html.erb
|
78
|
+
- lib/capistrano/templating.rb
|
79
|
+
- lib/capistrano/templating/tasks/template.cap
|
80
|
+
- lib/capistrano/templating/version.rb
|
81
|
+
homepage: https://github.com/xavierpriour/capistrano-templating
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Capistrano gem to generate files from templates on deployment
|
105
|
+
test_files: []
|