I was playing about with Capistrano over the weekend. I wanted to automate the deployment of a Rails application to my server. The server was (I thought) just about ready to accept the app but I did not want to go through another manual deployment. I thought I would take the opportunity to script the deployment. The first task I set myself was to create a production MySQL database. Searching for how to do this threw up lots of interesting information about building and deploying database.yml files, but not much about configuring MySQL. The first set of tasks I came up with were:
- Does the database exist?
- Create database if missing
- Grant permissions
Does the database exist?
Not particularly pretty and would welcome improvements but functional.
This snippet could be a task but I have not yet done that refactoring - the original was parameterised taking in all the required values as parameters.
Again this step can now be converted into a task.
At the moment the values are coded in the deployment script deploy.rb - something that I definitely want to change. The code should be checked into source control but this would release the usernames and passwords necessary to do deployments. My current thoughts are to extract the runtime properties to a small yaml file and read that in, unless anyone has a smarter idea?