Created
April 10, 2012 13:45
-
-
Save peterjmit/2351486 to your computer and use it in GitHub Desktop.
Create a parameters.ini file interactively when deploying with capifony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This custom task for deploying a Symfony 2 application is set to run after deploy:setup | |
# is executed. It interactively ask a user for database details to create a parameters.ini | |
# thus avoiding having to manually on to the server and create it | |
# | |
# Helper function from http://stackoverflow.com/a/1662001/1041885 | |
# | |
# Interactive parameter.ini generation adapted from http://adurieux.blogspot.co.uk/2011/10/using-capistrano.html | |
# ... | |
# ... Your deployment settings/tasks | |
# ... | |
# This is required for the below task to work | |
set :shared_files, ["app/config/parameters.ini"] | |
# Helper function for testing if a file exists | |
def remote_file_exists?(full_path) | |
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip | |
end | |
namespace :custom_setup do | |
task :create_parameters_file do | |
unless remote_file_exists?("#{shared_path}/app/config/parameters.ini") | |
# You can ask for more parameters here and set them in below | |
# ...but this is a starting point | |
set :mysql_db_name, Capistrano::CLI.ui.ask("Enter MySQL database name: ") | |
set :mysql_user, Capistrano::CLI.ui.ask("Enter MySQL database user: ") | |
set :mysql_password, Capistrano::CLI.ui.ask("Enter MySQL database password: ") | |
set :secret_token, Capistrano::CLI.ui.ask("Set a secret token for this app: ") | |
# File parameters.ini | |
template = <<-EOF | |
[parameters] | |
database_driver = pdo_mysql | |
database_host = localhost | |
database_port = | |
database_name = #{mysql_db_name} | |
database_user = #{mysql_user} | |
database_password = #{mysql_password} | |
mailer_transport = smtp | |
mailer_host = localhost | |
mailer_user = | |
mailer_password = | |
locale = en | |
secret = #{secret_token} | |
EOF | |
# This may already be handled... | |
run "mkdir -p #{shared_path}/app/config" | |
# Put the new parameters.ini file in...change this if you have a different path for | |
# your shared parameters file | |
put ERB.new(template).result(binding), "#{shared_path}/app/config/parameters.ini" | |
end | |
end | |
end | |
after 'deploy:setup', 'custom_setup:create_parameters_file' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment