Capistrano::Symfony::AssetMapper
Seamless Integration for Symfony AssetMapper in Capistrano Deployments
This gem extends Capistrano 3.x to support Symfony's Asset Mapper and SASS build tools, automating tasks like asset installation, compilation, and SASS-to-CSS builds during deployments. It's an essential tool for modern Symfony applications that utilize the Asset Mapper.
Installation
Before using this gem, ensure that Capistrano is properly set up in your project. Then, add the following lines to your Gemfile:
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-symfony'
gem 'capistrano-asset-mapper'Run bundle to install the dependencies:
$ bundleOr install the gem manually:
$ gem install capistrano-asset-mapperUsage
Requiring the Gem
To use the default tasks, require the gem in your Capfile:
require 'capistrano/symfony'
require 'capistrano/asset-mapper'Hooks Execution
The gem integrates with Capistrano’s deployment lifecycle. The following hooks are added automatically:
after 'deploy:updated', 'symfony:asset_mapper:install'
after 'deploy:updated', 'symfony:asset_mapper:sass_build'
after 'deploy:updated', 'symfony:asset_mapper:compile'These hooks perform the following tasks:
-
importmap:install: Installs JavaScript dependencies. -
sass:build: Compiles SASS files into CSS. -
asset-map:compile: Compiles asset mappings for production.
Disabling Hooks
If you want to skip these tasks during deployment (e.g., in non-production environments), you can disable them by setting the following variable in your deploy.rb or an environment-specific file (e.g., config/deploy/production.rb):
set :enable_symfony_asset_mapper_hooks, falseAlternatively, you can disable the hooks for a single deployment by running:
cap production deploy enable_symfony_asset_mapper_hooks=falseServer Configuration
Ensure that the server running the asset mapper tasks has the web role. For example:
server 'node1.example.com', user: 'deploy', roles: %w{web}
server 'node2.example.com', user: 'deploy', roles: %w{web}
server 'node3.example.com', user: 'deploy', roles: %w{web}This configuration ensures that tasks are executed only on servers with the web role.
Configurable Options
You can customize the behavior of the gem using the following options:
# Enable or disable Symfony Asset Mapper hooks globally
set :enable_symfony_asset_mapper_hooks, true
# Flags for the Symfony importmap:install command
set :symfony_importmap_install_flags, '--no-interaction --no-debug'
# Flags for the Symfony sass:build command
set :symfony_sass_build_flags, '--no-interaction --no-debug'
# Flags for the Symfony asset-map:compile command
set :symfony_asset_map_compile_flags, '--no-interaction --no-debug'Development
To install this gem onto your local machine, run:
$ bundle exec rake installTo release a new version:
- Update the version number in
capistrano-asset-mapper.gemspec. - Run:
$ bundle exec rake releaseThis command will create a git tag for the version, push commits and tags, and publish the .gem file to RubyGems.
Contributing
We welcome contributions to improve this gem! To contribute:
- Fork the repository.
- Create your feature branch:
git checkout -b my-new-feature. - Commit your changes:
git commit -am 'Add some feature'. - Push the branch:
git push origin my-new-feature. - Create a pull request.
License
This gem is available as open source under the terms of the MIT License.