Getting started with SFTP and OpenShift

OpenShift has supported git from day one for cloud deployments to the Red Hat Cloud. I often get asked by developers if we also support other ways of communicating with OpenShift to deploy their source code. I am happy to announce that we officially support SFTP as a way of deploying your source code up to your OpenShift hosted cloud server.

In this blog post, I will show you how to use SFTP with NetBeans in order to develop and push your source code up to your live web server.

Enjoy videos more than reading? Check out the following video where I show you the same steps detailed below.

Note: This blog post assumes that you already have a private and public ssh key pair created and configured to authenticate to OpenShift. I also assume that you are using an interpreted language that does not need to be compiled, such as Java.

Step 1: Download and install NetBeans

Point your browser over to the NetBeans website and download the version of NetBeans that suits your preferred language. In this blog post, I will be using the PHP language but the instructions should work with any version of the IDE that you choose to download.

Step 2: Sign up for an OpenShift account

If you don’t already have an OpenShift account, head on over to the website and signup. It is completely free and Red Hat gives every user three free Gears on which to run your applications. At the time of this writing, the combined resources allocated for each user is 1.5 GB of memory and 3 GB of disk space.

Step 3: Create an OpenShift application

Now that we have an OpenShift account and the NetBeans IDE installed, let’s get started with our application coding. The first thing we need to do is create a gear that will house our application code. I will be using the web console to create the application, but you can perform the same action via the RHC command line tools.

Head on over to the OpenShift website and login to the application by clicking SIGN IN in the upper right hand corner. Once you have been authenticated, select Create Application on the toolbar at the top of the screen.

Once you select to create an application, scroll down and select to create a PHP 5.3 application.

Give your application a name of netbeans, or whatever you choose, and select create application.

Step 4: Create and configure your NetBeans Project

Now that your application has been created, you should see a confirmation screen. Keep this screen available as we will be using some of the information provided to configure NetBeans for SFTP communication to OpenShift.

Open up your NetBeans IDE and select file -> new project. Select PHP Application from Remote Server and click Next.

Give your Project a name to identify it. For this example, I am going to create a project called netbeans.

Select PHP 5.3 as your version and click on Next.

Specify the Project URL of your application. In this example, my project URL is the same as my publicly available application that I created on OpenShift: http://netbeans-onpaas.rhcloud.com

Set the Upload Directory to:

/app-root/repo/php


Update Feb 13, 2016 - User @Amilnyleve pointed out on twitter that with the PHP-5.4 cartridge, the above directory is incorrect.  You should be using the following if you are taking advantage of PHP-5.4 instead of PHP-5.3:
/app-root/repo/

We now need to configure our SFTP connection to OpenShift. On the dialog that is displayed above, click on Manage to add a new remote connection. Give your connection a name of OpenShift and specify the type as SFTP.

On the next dialog is where we specify our connection and authentication details that will enable us to communicate with OpenShift via SFTP.

For the Host Name property, enter in the full URL for your application hosted on OpenShift. In this example, it would be:

netbeans-onpaas.rhcloud.com

The next property that we need to provide is the username of our server account that we created above. In order to find this information, switch back to the web browser which should have the application creation confirmation screen displayed. One piece of information provided is the git URL for your application. This URL contains your unique user id for your OpenShift application.

In the above example, the user id for my application server is:

be01eff00d3b4effa02f212bebd23c5a

Now that we have our user id, lets provide that information as our username for the SFTP connection.

In order to authenticate with OpenShift, we need to provide our SSH private key. My private key is located at:

/Users/gshipley/.ssh/libra_id_rsa

The last piece of information that we need to provide is the Initial Directory value for our application. This takes the format of:

/var/lib/openshift/YourUserId

For example, for this particular application I would provide the following initial directory:

/var/lib/openshift/be01eff00d3b4effa02f212bebd23c5a

At this point, click Test Connection to ensure that everything is configured correctly.

Once you have verified that your test connection was successful, click Ok and then Next.

You will then be presented with a dialog that informs you that two source files already exists at that location. Make sure that both files are checked and click on Finish.

Step 5: Code

Now you are all set to do what you do best, code. From now on, anytime you add or save a file, the changes will automatically be synchronized with your server running on OpenShift.

Categories
News
Tags
Comments are closed.