Tips for Creating OpenShift Apps with Windows - Archived

Creating OpenShift Apps with Windows

The foundation of the OpenShift Platform as a Service is Red Hat Enterprise Linux but developers can create and push applications to the cloud using a variety of operating systems. This blog post offers some productivity tips and tool recommendations for those using Microsoft Windows. If you are a Windows user with additional advice to share, please post it in the comments section.

Installing The Client Tools

OpenShift is written in Ruby and the RHC command line tools require Ruby to be installed on your system. One easy way to get Ruby running on Windows is to use the RubyInstaller, as recommended in the RHC installation guide. Remember to tick the ‘Add Ruby executables to your PATH’ check box during installation. If Ruby is on your path, you will be able to run the command ruby -v in your Command Prompt. Once you have Ruby, you should install Git for Windows, which will also give you access to some extra tools such as SSH. I would recommend selecting the ‘Run Git from the Windows Command prompt’ option, which will allow you to use Git from a Command Prompt and give you access to *nix tools via Git Bash, without overriding any native Windows tools.

If you want to develop Rails applications for OpenShift, or if you just want the quickest and easiest installation process possible, you may wish to use the RailsInstaller tool instead. It will install Ruby and the Rails framework for you but also bundles other useful tools, including Git (be sure to tick the ‘Install Git’ check box for this), which saves you from installing these separately. You should select the check box to add Ruby and the other tools to your path, and to configure Git and SSH after installation. This is a nice all-in-one solution to get up and running with just a few clicks, but may be overkill if you don’t actually want to use the Rails framework.

Once you have Ruby and the Git version control system, you can install the RHC Gem with the command gem install rhc as described in the guide.

Shell Selection

Once you have installed the above tools you should be able to do most of what you need in a Command Prompt. However, the Command Prompt will not support some Unix-style commands such as chmod and ssh (unless you chose the option to override the Windows tools, which is not recommended). For this reason, the preferred option is to use the Git Bash console that is installed with Git for Windows. You should be able to find it under Git in your Start menu. It is also possible to use Cygwin but this is not recommended.

To copy content in Git Bash, right-click on the title bar of the window and select Edit > Mark. When you have highlighted the content you wish to copy, press Enter. To paste content, press the Insert key. In Command Prompt, you can copy content by right-clicking in the window, selecting Mark and pressing Enter once you have highlighted the content. To paste, you can right-click and select Paste from the menu. Alternatively, in both Git Bash and Command Prompt you can make it easier to copy and paste text by right-clicking on the title bar and selecting Properties > Options > QuickEdit Mode, which allows you to highlight text and press enter to copy it, then right-click to paste it.

Secure Communication

One area that has given some Windows users trouble is setting up secure communication with OpenShift via SSH. Once you have RHC you should run the command rhc setup, which can generate and upload an SSH public key to OpenShift for you.

If you see an error such as the following when creating and cloning an OpenShift application, it may indicate your SSH key has not been uploaded properly:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Fatal: Could not read from remote repository
Please make sure you have the correct access rights and the repository exists.

You can check which SSH keys are associated with your account with the command rhc sshkey, or view these in the OpenShift web console. This command can also be used to upload an existing SSH key, eg: rhc sshkey add keyname C:\Users\Username\.ssh\ Should you need to generate an SSH key manually, the command is ssh-keygen; you can run this command in Git Bash.

The output of RHC will suggest that you use the chmod (change mode) command to alter the permissions on your public key file. You will have to execute the chmod 600 command in Git Bash.

The solution to some SSH issues may be to create an SSH config file, as suggested here. If you receive the error message ArgumentError: Could not parse PKey: no start line, you may want to try downgrading the net-ssh Gem, as outlined in this post.

Console Commands The Windows Way

When you are reading blog posts and tutorials written by the OpenShift community you may find they use *nix console commands rather than Windows commands. To help with the conversion, here are some useful commands in the Windows and Unix styles respectively:

  • Clear the screen: cls vs clear
  • Edit a file: edit vs vi
  • List directory contents: dir vs ls
  • Make a directory: mkdir vs mkdir
  • Copy a file: copy vs cp
  • Copy a directory recursively: xcopy vs cp -R
  • Move a file: move vs mv
  • Delete a file: del vs rm
  • Remove a non-empty directory: rmdir /s vs rm -r

If you use Git Bash rather than Command Prompt you will find you are able to run many Unix-style commands.

Command Line Alternatives

It helps to have some familiarity with the command line when using the OpenShift client tools, but if you don’t like the shell you can still do a lot of your work with graphical tools, such as the OpenShift web console, IDE tools, PuTTY for SSH on Windows, and Git for Windows or TortoiseGit.

The web console allows you to create, manage and monitor applications. You can add and remove cartridges such as MySQL or Jenkins, delete applications, and create applications based on existing source code. If you just want to create an application based on a quickstart, such as WordPress, and do not want to alter its source, the web console may be all you need.

Another option for those who would rather avoid the command line is to use an IDE with an OpenShift plugin, such as JBoss Developer Studio or Eclipse. Much of the functionality of the RHC client tools is now available through these plugins, although you may still need to use the command line for some tasks, such as taking application snapshots or managing deployment history.

Git for Windows makes it easy to use Git on the command line, but it also offers some functionality through Windows Explorer. Once it is installed, you will find you can right-click on a folder and select Git Init to make that folder a Git repository. When you add files, you can right-click on those too to launch the graphical Git Commit Tool. If you want even more Git options to be available through the GUI, you may want to consider using the TortoiseGit tool.

PuTTY is a graphical tool for connecting to your OpenShift applications via SSH. It allows you to save your session config so that connecting again next time requires just a point and click. We have instructions for installing and configuring PuTTY so you can SSH on Windows.

Avoiding Platform Dependence

An issue to be wary of when pushing applications developed on Windows to OpenShift is platform-specific config. OpenShift runs on Red Hat Enterprise Linux, so if you try to use it to run Windows-specific versions of things you will likely get an error. For example, if you develop a Rails application on Windows, you may find you have platform-specific extensions in your Gemfile.lock, such as pg (0.17.0-x86-mingw32) for the PostgreSQL Gem, rather than simply pg (0.17.0). Pushing something like this will result in a deployment failure and an error advising you that the offending Gem has not been loaded. Take care to avoid anything specific to Windows.

Setting Permissions

Another potential hurdle for Windows users is that the OpenShift action_hook files must have the correct permissions to be executable, which may be an unfamiliar requirement. If you add a new action_hook file you should make it executable. To make a file executable, you can use Git Bash and the chmod command such as follows:

chmod +x .openshift/action_hooks/*

Another method is to use Git to make the files executable:

git update-index --chmod=+x .openshift/action_hooks/*


Windows users can easily create applications that run on OpenShift. If you will not be changing the source code of your OpenShift app, you may choose to simply use the OpenShift web console. If you plan to do development, you should install the RHC client tools and Git for Windows, which includes a useful console tool called Git Bash that can be used to run Unix-style commands when required. If you dislike the command line, you can install graphical tools that can provide most required functionality for developing and deploying applications, although some features are unique to the RHC client tools. Developers should take care to avoid pushing platform-specific code to OpenShift and to ensure files have the correct permissions. Please share your tips for using Windows and OpenShift in the comments section.

Next Steps

OpenShift Online
, ,
Comments are closed.