https://github.com/dyerc/capistrano-craft
Craft CMS specific Capistrano tasks
https://github.com/dyerc/capistrano-craft
Last synced: 11 months ago
JSON representation
Craft CMS specific Capistrano tasks
- Host: GitHub
- URL: https://github.com/dyerc/capistrano-craft
- Owner: dyerc
- License: mit
- Created: 2019-10-15T15:49:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T12:27:09.000Z (over 1 year ago)
- Last Synced: 2025-07-27T08:16:57.221Z (11 months ago)
- Language: Ruby
- Size: 31.3 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Capistrano::Craft
This gem automates the deployment of Craft CMS apps with Capistrano. It will automatically detect local and remote environment settings to make synchronizing of database and assets straightforward.
- [x] Support for asset and database synchronization
- [x] Support for PostgreSQL databases
- [ ] Support for MySQL databases
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'capistrano-craft'
```
Or install system wide:
$ gem install capistrano-craft
## Usage
For a beginners guide to deploying your site (especially useful if you have little to no experience with Ruby) please see this blog article: https://cdyer.co.uk/blog/deploying-craft-cms-to-a-vps-server-with-capistrano
The setting you will likely need to customize is:
```
# This should be your command to compile assets for production
set :craft_compile_assets, true
set :craft_compile_assets_command, "npm install && npm run production --production --silent"
```
If you are using PHP-FPM it is necessary to restart it after deployment. Currently capistrano-craft doesn't handle this for you and you may need to add something along the lines of the following to your `deploy.rb` file.
```
before 'deploy:published', 'fpm_restart'
task :fpm_restart do
on release_roles :all do |host|
execute "sudo service php7.3-fpm restart"
end
end
```
### Compiling Assets
Change `:craft_compile_assets_command` to be your production asset compilation command. By default, it is assumed your project has a `package.json` file and `npm install` will be run first. The default asset compilcation command is `npm run production --production --silent`. You can disable asset compilation altogether by settng `:craft_compile_assets` to `false`.
### Synchronize Database
### Upgrading Craft CMS
When you deploy, Capistrano will run composer automatically installing your chosen packages. If you have upgraded Craft locally, the new version will automatically be installed on your deployment.
If you were to upgrade on the server, then run `cap production craft:pull` to sync the database and assets down, the database would be running a newer version than your local codebase. This should be easily resolved by updating through Composer or the Craft admin area (assuming Craft runs correctly with the conflict).
### Settings
Full list of available settings:
```
set :config_path, "config"
set :php, "php"
set :craft_local_env, -> { "#{Dir.pwd}/.env" }
set :craft_remote_env, -> { "#{fetch(:deploy_to)}/shared/.env" }
set :craft_local_db_dump, "db.sql"
set :craft_local_backups, "backups"
set :craft_remote_backups, "shared/backups"
# assets
set :craft_compile_assets, true
set :craft_compile_assets_command, "yarn install && yarn run production"
# console
set :craft_console_path, -> { "craft" }
set :craft_console_flags, ""
# Role filtering
set :craft_roles, :all
set :craft_deploy_roles, :all
```