Skip to content

Instantly share code, notes, and snippets.

@chalasr
Last active September 23, 2018 15:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chalasr/94bc22f8bdb1a7309329 to your computer and use it in GitHub Desktop.
Save chalasr/94bc22f8bdb1a7309329 to your computer and use it in GitHub Desktop.
Deploy using capistrano/symfony tasks
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/composer'
require 'capistrano/symfony'
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'portfolio'
set :repo_url, 'git@github.com:chalasr/sfPortfolio.git'
set :ssh_user, "chalas_r"
set :format, :pretty
set :log_level, :info
set :stage, "production"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
set :deploy_to, "/var/www/html/projects/Portfolio"
set :branch, "master"
set :model_manager, "doctrine"
set :pty, true
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'
# Default value for :scm is :git
set :scm, :git
set :symfony_env, "prod"
set :app_path, "app"
set :web_path, "web"
set :log_path, fetch(:app_path) + "/logs"
set :cache_path, fetch(:app_path) + "/cache"
set :app_config_path, fetch(:app_path) + "/config"
set :use_sudo, true
set :permission_method, :chmod
set :use_set_permissions, true
set :writable_dirs, ["app/cache", "app/logs"]
set :linked_dirs, %w{app/logs}
set :keep_releases, 3
# Permissions
set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)]
set :file_permissions_users, ['www-data']
set :webserver_user, "www-data"
# Assets
set :assets_install_path, fetch(:web_path)
set :assets_install_flags, '--symlink'
namespace :deploy do
task :check_permissions do
on roles(:web) do
execute "chmod -R 0777 #{release_path}/app/cache"
execute "echo 'finished'"
end
end
end
after "deploy:finishing", "deploy:check_permissions"
after "deploy:check_permissions", "deploy:finished"
source "https://rubygems.org"
gem 'capistrano-rbenv'
gem 'capistrano', github: 'capistrano/capistrano', branch: 'master'
gem 'capistrano-symfony', :github => 'TheBigBrainsCompany/capistrano-symfony'
gem 'capistrano-composer'

If you got a permission denied on cache directory after/during deploy, make the following lines on your remote server :

sudo chown -R {whoami} {path/to/project}

sudo chmod -R 0777 {path/to/project}

Then, relaunch `cap production deploy``

# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
# role-based syntax
# ==================
# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.
role :app, %w{chalas_r@dev.chalasdev.fr}
role :web, %w{chalas_r@dev.chalasdev.fr}
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
# role :db, %w{deploy@example.com}
# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.
set(:latest_release, :deploy_timestamped ? release_path : current_release )
# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
set :ssh_options, {
keys: %w(/Users/Robin/.ssh/id_rsa),
forward_agent: false,
auth_methods: %w(publickey password)
}
#
# The server-based syntax can be used to override options:
# ------------------------------------
server 'dev.chalasdev.fr',
user: 'chalas_r',
roles: %w{web app},
ssh_options: {
user: 'chalas_r', # overrides user setting above
keys: %w(/home/chalas_r/.ssh/id_rsa),
forward_agent: false,
auth_methods: %w(publickey password),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment