https://github.com/jbox-web/capistrano-template
https://github.com/jbox-web/capistrano-template
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jbox-web/capistrano-template
- Owner: jbox-web
- License: mit
- Created: 2024-02-01T20:49:44.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-01T23:43:15.000Z (over 1 year ago)
- Last Synced: 2024-12-25T21:10:02.903Z (6 months ago)
- Language: Ruby
- Size: 76.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/jbox-web/capistrano-template/actions/workflows/ci.yml)
[](https://codeclimate.com/github/jbox-web/capistrano-template/maintainability)
[](https://codeclimate.com/github/jbox-web/capistrano-template/test_coverage)# Capistrano::Template
A capistrano 3 plugin that aids in rendering erb templates and
uploads the content to the server if the file does not exists at
the remote host or the content did change.## Installation
Add this line to your application's Gemfile:
gem 'capistrano-template'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capistrano-template
## Usage example
In your Capfile:
```ruby
require 'capistrano/capistrano_plugin_template'
```
In your task or stage file:```ruby
desc 'Upload a rendered erb-template'
task :setup do
on roles :all do
# searchs for template assets.host.site.erb in :templating_paths
# renders the template and upload it to "#{release_path}/assets.host.site" on all hosts
# when the new rendered content is changed or the remote file does not exists
template 'assets.host.site', locals: { 'local1' => 'value local 1'}
endon roles :all do
# searchs for template other.template.name.erb in :templating_paths
# renders the template and upload it to "~/execute_some_thing.sh" on all hosts
# when the new rendered content is changed or the remote file does not exists
# after this the mode is changed to 0750
# owner is changed to "deployer:www-run"
# keep in mind chown and chgrp needs sudo privilegestemplate 'other.template.name', '~/execute_some_thing.sh', 0750, 'deployer', 'www-run' ,locals: { 'local1' => 'value local 1'}
end
end
```In your config/deploy/templates/shared/assets.host.site.erb
```ruby
# generated by capistrano
##########################server {
listen 80;client_max_body_size 4G;
keepalive_timeout 10;error_page 500 502 504 /500.html;
error_page 503 @503;server_name <%= host.properties.fetch(:host_server_name) %>;
root <%= remote_path_for(current_path) %>/public;<%= render 'partial.conf', indent: 2, locals: { 'other_local' => 'other local value' } %>
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)|(svg)|(otf)$){
add_header Access-Control-Allow-Origin *;
}
}location = /50x.html {
root html;
}location = /404.html {
root html;
}if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
return 405;
}if (-f $document_root/system/maintenance.html) {
return 503;
}location ~ \.(php|html)$ {
return 405;
}
}
```## Settings
This settings can be changed in your Capfile, deploy.rb or stage file.
| Variable | Default | Description |
|---------------------------|---------------------------------------|---------------------------------------|
|`templating_digester` |->(data){ OpenSSL::Digest::MD5.hexdigest(data)}
| Checksum algorithm for rendered template to check for remote diffs |
|`templating_digest_cmd` |%Q{test "Z$(openssl md5 %<path>s | sed 's/^.*= *//')" = "Z%<digest>s" }
| Remote command to validate a digest. Format placeholders path is replaces by full `path` to the remote file and `digest` with the digest calculated in capistrano. |
|`templating_mode_test_cmd` |%Q{ [ "Z$(printf "%%.4o" 0$(stat -c "%%a" %<path>s 2>/dev/null || stat -f "%%A" %<path>s))" != "Z%<mode>s" ] }
| Test command to check the remote file permissions. |
|`templating_user_test_cmd` |%Q{ [ "Z$(stat -c "%%U" %<path>s 2>/dev/null)" != "Z%<user>s" ] }
| Test command to check the remote file permissions. |
|`templating_paths` |["config/deploy/templates/#{fetch(:stage)}/%<host>s",
"config/deploy/templates/#{fetch(:stage)}",
"config/deploy/templates/shared/%<host>s",
"config/deploy/templates/shared"]
| Folder to look for a template to render. `` is replaced by the actual host. |## Contributing
1. Fork it ( http://github.com/faber-lotto/capistrano-template/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request