We will now venture into configuring and using the built-in deployment tools in RubyMine. This is the final step in completing your journey through assimilation and ensures the survival of your species. Deployment can be done in many different ways, but we only have time to explore one.
Open your Progeny
Rails project that we created earlier in RubyMine. Make sure that you have a remote location that will accept a Ruby on Rails project and allows SFTP uploading to this site.
RubyMine can interface directly with a remote server and upload/download files to this site, keeping the files in sync automatically. It also has built-in support for the Capistrano deployment Gem to help with this process of remotely deploying and restarting Rails apps.
It is best practice to use our version control system to deploy our application. It is also easiest if we utilize one of the services out on the Internet to house our repository for us during this process. We will add our existing Git repository that we created in the recipe, Ensuring your legacy (Become an expert), to the GitHub system at http://github.com using the following steps:
Navigate to VCS | Import into Version Control | Share Project on GitHub.
This will bring up a window asking for your GitHub account and giving you the opportunity to create one if you don't have one, as you can see in the following screenshot. GitHub is free if you keep your project public and open source, but they also have paid options if that is unappealing to you.
After you log in with a valid account, the next window that appears will be for you to name your project and give it a short description. Doing this will create the remote repository on GitHub for us to use later.
If we now log in to the GitHub account and navigate to your project, you can copy the Git repository URL, as you can see in the following screenshot, which we can add to our
deploy.rb
file for use in Capistrano:Now, we need to install the Capistrano Gem by adding it to our Gemfile as we have done before, except this time Rails knows that this is a common Gem, so we just need to uncomment out the line in the Gemfile like the following:
# Use Capistrano for deployment gem 'capistrano', group: :development
Navigate to Tools | Bundle | Install.
Now we can use RubyMine tools to start the Capistrano process. We must first navigate to Tools | Capistrano | Capify Application.
This will create two files:
Capfile
andconfig/deploy.rb
.Open the
Capfile
file and uncomment out the following line so that the process will run the precompilation of the assets pipeline after deploying the files to your webserver:load 'deploy/assets'
Open the
config/deploy.rb
file and edit the following lines using the GitHub repository URL that you copied from your account for the:repository
line:require 'capistrano-deploy' set :application, "progeny" set :repository, "https://github.com/lockersoft/Progeny.git" set :user, "lockersoft"
Of course, you would use your own specific information for the server where you are going to deploy your application. There are many different options that you can use from Capistrano to customize your deployment to meet a variety of needs for your particular collective. Too many to show here, so start by looking at the Capistrano Gem documentation found at https://github.com/capistrano/capistrano.
Once we have our
deploy.rb
file the way we want it, we can commit our changes and push those changes to the GitHub remote repository that we created earlier. Navigate to VCS | Commit Changes.This will bring up a window that we saw earlier where we can add a message to our commit. At the bottom of the window, instead of selecting Commit, we want to select the option Commit and Push...:
This will bring one final window which allows us to choose a different branch. Just hit the Push button and our project will be uploaded to the GitHub repository.
Now, we are ready to deploy the project. We will let Capistrano do that for us by merely running that script. Navigate to Tools | Capistrano | Run Capistrano, which will bring a window to allow us to select one of many tasks to run. The first one we want to run is the
deploy:setup
command. This runs much like the rake tasks and once we select and run a task, it is saved in our task configuration menu at the top of the main project for later use, as shown in the following screenshot:This will create the directory structure that Capistrano needs on your remote server for us.
The next Capistrano command is selected from the same menu, but it is simply deploy. This will actually issue a command on the remote server to clone our Git repository from GitHub into our remote server directory and we will now be ready to access our server.
If everything is right in our
deploy.rb
script, which is saying a lot, then the Rails server will be running on our remote server and we can simply connect to the server via a browser like one of our users would.
Now, whenever we need to make a change to our application, we just have to follow the following steps in order to deploy those changes:
Commit and push our changes to the remote GitHub account
Run the Capistrano deploy task
Check the server with our browser to make sure everything is working as we expect
We have now successfully deployed our application, which in turn can spawn new drones in our quest for perfection for our entire collective.
There are many video tutorials that I have created from my lectures in teaching Ruby, Ruby on Rails, Mobile Development, Java and Android Development, and even PHP development on my YouTube channel. For lectures on all of these, I use the Jetbrains tools such as RubyMine, PHPStorm, and IntelliJ. Check them out at http://youtube.com/lockersoft.
In addition, some of the source code examples and code from my other lectures can be found on my GitHub account at https://github.com/lockersoft.