This is a cookbook that allows for plug-and-play creation of an application, using only a repository. The recipe takes care of creating the database, installing required gems via bundler, and creating an nginx stack to serve your site.
This recipe has been tested on Ubuntu 12.04 and Ubuntu 14.04.
Key | Type | Description | Default |
---|---|---|---|
["rails-app"]["name"] | String | Application name | "default" |
["rails-app"]["address"] | String | IP address or domain name of the server. | node['fqdn'] |
["rails-app"]["action"] | String | What to do with the app, options are :deploy and :force_deploy, for more info see the chef application cookbook. | :deploy |
["rails-app"]["path"] | String | Path where the application should be stored on the server. | "/opt/#{node["rails-app"]["name"]}" |
["rails-app"]["deploy_key"] | String | An optional string if you wish to pull your code from a private repository, make sure to replace all newlines with \n if you use this. | nil |
["rails-app"]["repository"] | String | Repository to pull your code from. | nil |
["rails-app"]["revision"] | String | Revision of your code to pull. | "master" |
["rails-app"]["environment"] | String | Rails environment to deploy. | "production" |
["rails-app"]["db_host"] | String | Tells rails where the database is located. | "127.0.0.1" |
["rails-app"]["db_adapter"] | String | Tells rails the database adapter to use. | "postgresql" |
["rails-app"]["db_name"] | String | Tells rails the database to use. | "rails-app-#{default["rails-app"]["name"]}" |
["rails-app"]["db_username"] | String | Tells rails who to login as. | node["rails-app"]["name"] |
["rails-app"]["db_password"] | String | Tells rails the database password. | node["rails-app"]["db_password"] || ::SecureRandom.base64(24) |
["rails-app"]["bundler"] | Boolean | Should I use bundler? | true |
["rails-app"]["bundle_command"] | String | The path to bundler on your system. | "#{node["rbenv"]["root_path"]}/shims/bundle" |
["rails-app"]["bundler_deployment"] | Boolean | Should bundler use deployment mode? | true |
["rails-app"]["migrate"] | Boolean | Should the rails app have migrations run on it? | true |
["rails-app"]["migration_command"] | String | What is the command to migrate the database? | "#{node["rails-app"]["bundle_command"]} exec rake db:migrate" |
["rails-app"]["gems"] | Array | Additional gems to install with this recipe. | [] |
["rails-app"]["bundler_without_groups"] | Array | What groups should bundler ignore? | [] |
["rails-app"]["ssl"] | Boolean | Should I use SSL? | false |
["rails-app"]["precompile_assets"] | Boolean | Shoudl assets be precompiled? | true |
["rails-app"]["delete_before_bundle"] | Array | What files should be deleted from the repo after fetching? | [".rbenv-version", ".ruby-version"] |
Just include rails-app::default
in your node's run_list
and override attributes as needed. Generally you will need to override the name, host and repository to download from. An example of this is in the Vagrantfile in this repository.
This recipe includes a packer.json file that will build a Docker image and commit it to your local computer. In order to use it you will need to setup your environment first. (Note that this is only tested on Ubuntu 15.04. It should work on other versions of Ubuntu but has some bugs that cause it to not work on OS X, and Windows was not considered.)
- Perform the steps listed in the Developing section.
- git -
sudo apt-get install git
- Docker -
sudo apt-get install docker.io
- Download the temporary patched version of packer to work with docker 1.5 located here until the related github issue is fixed.
wget https://bintray.com/artifact/download/alkersan/generic/packer_0.8.0_linux_amd64.zip
sudo apt-get install unzip
unzip packer_0.8.0_linux_amd64.zip
sudo mv packer* /usr/local/bin/
- Install the docker post-processor onto packer. (steps below)
- Install go -
sudo apt-get install golang-go
- Install mercurial -
sudo apt-get install mercurial
mkdir ~/go
- Add the next two lines to .bashrc
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
git clone https://github.com/avishai-ish-shalom/packer-post-processor-docker-dockerfile.git ~/packer-post-processor-docker-dockerfile
cd ~/packer-post-processor-docker-dockerfile
go get github.com/nitrous-io/goop && go build github.com/nitrous-io/goop
goop install
- if you get an error on this step, try the build step anyway, it may work.goop go build
mv packer-post-processor-docker-dockerfile /usr/local/bin
berks vendor cookbooks
sudo su
service docker start
- At this point you can run
packer build packer.json
in the root directory of this project.
If there is a problem happening with the Packer build, it is rather simply to turn on chef debugging output, however poorly documented. In the packer.json file, the provisioner block should be changed to include an override block like below. It will then spit out chef debugging output which is much more useful in the case of an error.
"provisioners": [
{
"type": "shell",
"inline": ["apt-get -y update; apt-get install -y curl libjson-perl"]
},
{
"type": "chef-solo",
"cookbook_paths": ["cookbooks"],
"run_list": ["recipe[rails-app::default]"],
"prevent_sudo": true,
"json": {
"rails-app": {
"name": "registration-app",
"ssl": false,
"repository": "https://github.com/mitre-cyber-academy/registration-app.git",
"revision": "moveToRails4"
}},
"override": {
"docker": {
"execute_command": "chef-solo -l debug --no-color -c {{.ConfigPath}} -j {{.JsonPath}}"
}
}
}
]
- Install the ChefDK (https://downloads.chef.io/chef-dk/)
- If you are using rbenv, make sure you add add
export PATH="/opt/chefdk/bin:$PATH"
to your~/.bash_profile
after your rbenv init line.
- Fork the repository on Github
- Create a named feature branch (like
add_component_x
) - Write your change
- Submit a Pull Request using Github
- Make recipe less fragile to different versions of ruby. Currently if the C compiler prefix (gems/2.1.0/gems) is changed then the recipe will break, that should not happen.
Authors: Robert Clark [email protected]