Deploying to fortrabbit from circleci
23 Apr 2015Deploying to Heroku from circleci is easy because it is already built in, it isn’t that tricky to provide the same functionality for fortrabbit or other even PaaS providers (probably :)).
Generate an SSH key
Generate a new SSH key somewhere, this doesn’t have to be in your ~/.ssh
directory as you won’t be using it
personally.
Create an App-only SSH key on fortrabbit
Login to the fortrabbit dashboard, select the app in question and click SSH/SFTP
.
Scroll down to App-only SSH keys
and click Manage App-only SSH keys
. Click the Add new App-only SSH key
button and
enter a name for the key, usually a combination of the service name and the app for easy reference. Paste in the contents
of the public key that was generated (id_rsa.pub
) into the Key string
field. Click save
to save the key.
Register an SSH key on circleci
Login to circleci, find the project you’re interested in and click the little cog. Scroll down
to SSH Permissions
and click on it. Optionally enter the host name used for accessing fortrabbit via SSH (this is in
the same SSH/SFTP
section used above). Paste in the contents of the private key that was generated (id_rsa
). Click
Submit
to save the key.
Configure the circle.yml file
Open/create the circle.yml
file in the root of the project. In this example only the develop
branch is used, there
are many other options for which branch to use such as master
and even feature branches.
Replace {APP_NAME}
, {GIT_URL}
, {SSH_HOST}
and SSH_USER
with the real values from the fortrabbit dashboard.
Typically the SSH user is in the form u-{APP_NAME}
. The last line in the example performs a database migration, this
can of course be omitted but serves as decent reference of how to execute shell commands on the fortrabbit node from
circleci.
At first I thought the node names staging
and production
were arbitrary but it seems they are not. The
circleci documentation seems a little vague in that area but if
you have multiple nodes using the same branch you will get a warning on build:
Warning: There are multiple applicable deployment sections! Using 'staging'.
. As long as the branches are unique it
seems that the nodes can be named whatever. To be on the safe side stick with staging
and production
.
Push to the project repository on GitHub and watch the build in circleci…
Boomtimes!