- Overview
- Transcript
4.4 Capistrano Deployment
Now that we have a custom continuous integration server, we can also do custom deployment with Capistrano. I’ll show you how in this lesson.
Related Links
1.Introduction4 lessons, 12:21
1.1Introduction01:07
1.2What Is Continuous Integration?04:54
1.3Development Approaches: Git Flow and GitHub Flow04:38
1.4Project Overview01:42
2.Git Flow, Travis CI and Engine Yard4 lessons, 33:15
2.1Travis CI Overview09:01
2.2Test a New Feature07:43
2.3Release and Hotfix08:04
2.4Engine Yard Deployment08:27
3.GitHub Flow, Codeship and Heroku3 lessons, 24:51
3.1Codeship Overview09:24
3.2Develop a New Feature09:49
3.3Heroku Deployment05:38
4.Bonus: Custom Jenkins Server and Capistrano4 lessons, 26:45
4.1Installing Jenkins on a VPS02:31
4.2Jenkins Overview10:08
4.3Test a Ruby Project06:02
4.4Capistrano Deployment08:04
5.Conclusion1 lesson, 01:02
5.1Conclusion01:02
4.4 Capistrano Deployment
Hi, and welcome back to Continuous Integration Workflow. In this lesson, we will set up our deployment pipeline in Jenkins, to deploy to a VPS using Capistrano. Let's start by configuring Jenkins. We will do the deployment in a separate job. We will call it just Deploy, and use a freestyle project again. We will trigger this build after the tutsplus-continuous-integration job, and only if the build is stable. We can also use the same RVM environment. Then, we add a single build step which is going to be a shared command, bundle exec cap protection deploy, which is the standard command in Capistrano to deploy to your production environment. Finally, we have to set the custom workspace in the Advanced Project Options which is going to be /var/lib/jenkins/workspace/tutsplus-conti- nuous-integration. This is the workspace of our other project. So, we use the same files in both places. Now, we can save the project configuration for Jenkins is complete. To deploy with Jenkins, we have to create an SSH key that is used to connect to the remote server. This can be done using SSH keygen. Then, we can copy the public key and use it on the server. For instance, when creating a new droplet in digital ocean. After you set up your server, it is a good idea to connect once to accept the connection for Jenkins. Now, it's time to set up Capistrano. Go to your project gem file and add the capistrano-rails gem. Then, run bundle install. After installing, you can run cap install to generate all the configuration files for Capistrano. This will create a capfile that is the main point for your configuration. You can include the Capistrano rails gem here. The next step is to actually set up your deployment config. With that, you have to config deploy.rb file where you have general information about the project like name, or Git URL. The other important file, is the config deploy production rb file. It contains specific information for your environment, such as the server address. You could also spread this over many servers. When first deploying to a server, you won't be able to automate the process in Capistrano very well. I'm going to do the first steps manually and let Capistrano automate the repetitive deploys once everything is set up. First, we need to deploy user under server, run adduser deploy, set the password, and also add the user to the sudogroup of @user deploy sudo. Then, switch to the deploy user and copy the authorized keys from root, which should contain your and the Jenkins server's public SSH keys. Then, we need to install git-core, build-essential, and postgresql. And install RVM and the Ruby version, like we did on the Jenkins server. We also need to give deploy access to var/www. Before we can run the deployment check, we have to change to Git URL to https, because we didn't add the key to GitHub. Redoing the SSH version is just an old habit. The deployment check is good. It's created some of the shared folders as well Before we can actually deploy, we need to install bundler on the machine. For PostgreSQL, we also need the development headers, and create the user, as well as the database itself. Then, we need to create some shared files. First, database.yml, which contains the production config Then, secrets.yml which creates a secret_key_base. Since we used rvm production server, we should include the capistrano/rvm gem, and maybe, also the capistrano-bundler gem. In the deployment config, we also need to uncommand linked_files and linked_dirs. Then, we can run cap reduction deploy, which runs fine. I didn't set up any web server or start the rail server which you can do on your own. Every configuration for that is different and out of scope here. It's time to commit the changes to our project, which triggers the build of our test project. After it completes, the deploy job runs. And fails. It seems that I used the wrong workspace path. The correct one is var/lib/jenkins/jobs/tutsplus-continuous-- integration/workspace. When I trigger the Build Now manually, it runs successfully. Now you know how to use Jenkins, and the power of plugins to completely test the Ruby project and deploy it using Capistrano and your own hardware.







