PaaS Deployment

Overview

You can deploy to a PaaS in Codenvy using the native tools provided by the PaaS providers (SDK and CLI). You will have to create a custom environment with a chosen SDK or CLI provided by your PaaS vendor. The resulting Dockerfile can vary depending on the complexity of the installation process and setting up environment. Below are examples of creating custom environment where you can deploy your Java apps to Google App Engine and AppFog.

Google App Engine Deployment

To deploy your application to Google App Engine (GAE) or other PaaS, you can use a custom runner environment that has the relevant SDK pre-installed.

Below is an example of a custom Dockerfile that creates an environment with the Google App Engine SDK installed, unpacks the .war file and launches a dev server:



FROM codenvy/jdk7_gae1914
WORKDIR /home/user/appengine-java-sdk-1.9.14/bin 
ADD $app$ /home/user/app/
RUN sudo chown -R user:user /home/user/app/WEB-INF/  
CMD ./dev_appserver.sh -a 0.0.0.0 /home/user/app

After you run this and when you are happy with the application and want to deploy it to GAE, go to Terminal tab and perform the following:

$ cd /home/user/sdk/bin
$ ./appcfg.sh update /home/user/app

You will be prompted to enter your Google ID and password. It will be necessary to specify the application ID in the appengine-web.xml file.

If you have Docker installed locally on your machine, you can build an image and upload it to DockerHub. It will take a while to pull the image the first time, but later environment boot times will be much faster due to caching. If you choose to do so, your custom Dockerfile will look like:

FROM yourName/yourImage
ADD $app$ /home/user/app/
RUN sudo chown -R user:user /home/user/app/WEB-INF/

The same approach can be used for Python and PHP applications using the relevant SDK (some commands may need to be altered to match the SDK in use).

Visit the Google App Engine docs for more details and complete commands reference.

AppFog Deployment

AppFog offers a CLI client to manage apps and account. The CLI is installed as a Ruby gem, so you will need an environment with Ruby:


FROM codenvy/ruby210
RUN sudo apt-get -y install rubygems
RUN sudo gem install af
ADD $app$ /home/user/$app$
RUN sudo chown -R user:user /home/user
CMD while true;do true; done

Go to a Terminal, login to your AppFog account, and create/update your applications using AppFog CLI commands. To update an application execute:

$ af update <appname> [--path]

See: AppFog CLI Commands Reference.

Similar to Google App Engine, you can build own image with AppFog CLI, upload it to Docker Index and use it as a base image in your custom Dockerfile.

OpenShift Deployment

OpenShift relies on a classic Git workflow – git add – git commit – git push. Codenvy supports Git, therefore you can import OpenShift applications, edit them in Codenvy and push changes back to OpenShift.

Before you proceed with importing OpenShift apps, you should establish secure SSH connection between your Codenvy workspace and OpenShift account.

Establish SSH Connection

  • in your Codenvy workspace, go to Windows > Preference > SSH Keystore > Generate Key
  • enter hostname rhcloud.com (Important! Just hostname, without www or https://)
  • copy the key
  • go to your OpenShift account settings, and add a new key

Alternatively, you can upload an existing key in the same menu box.

Import a Project

Once done, you can import your OpenShift project into Codenvy either from a Dashboard or from within the workspace at File > Import > Import From Location > GIT. Enter paste ssh Git URL of your OpenShift project. You may see an error signaling about an invalid SSH URL. Odds are that such an error is caused by a slash, for example, ssh://546a110ce0b8cdf8bc000013@openshift1298-newapplic.rhcloud.com/~/git/openshift1298.git/. Just remove ‘/’ and this should fix the problem.

Push Changes

Having edited the application, you can push changes back to OpenShift. Add changes to index (Git > Add to Index), commit them (Git > Commit) and push (Git > Remotes > Push). If this is a Java project, the update will take some time, since your push will trigger new project build on the OpenShift side.

When editing your Maven project, make sure you do not delete your OpenShift profile from pom.xml:

<profiles>
  <profile>
   <id>openshift</id>
    <build>
     <finalName>yourAppNameHere</finalName>
    </build>
  </profile>
</profiles> 

CloudFoundry Deployment

You can deploy your application to CF using Cloud Foundry CLI tool. Here’s a custom Dockerfile example that you can use:

FROM codenvy/jdk7
RUN mkdir /home/user/cf
WORKDIR /home/user/cf
RUN wget -q http://go-cli.s3-website-us-east-1.amazonaws.com/releases/v6.7.0/cf-cli_amd64.deb && \
    sudo dpkg -i cf-cli_amd64.deb

This will install CF CLI that will let you upload your application to Cloud Foundry. Login to your Pivotal account:

cf login -a api.run.pivotal.io

There are several ways to proceed. You can either perform builds in the runtime (provide build commands directly in the Dockerfile or navigate to Terminal tab and do it there) or, if it is a Maven or Ant project, perform build with a native builder (for these project types build is kicked off automatically upon hitting Run button) and inject build artifact into the image.

If the build is performed in the runtime, you need to navigate to application folder and run:


$ cf push <app-name> -n <unique_desired_url>

If the build has been performed with a native builder and you injected build artifact into the image (war or jar), you will need to provide a path to the build artifact:

$ cf push <app-name> -n <unique_desired_url> -p /home/user/myapp.war

Heroku Deployment

Heroku uses Git, so deploying to this PaaS is all about adding changes to index, commit them and push to Heroku. All you need to do is to make sure you have generated SSH key and saved it to your Heroku account.

SSH Connection

In your Codenvy workspace, go to Window > Preferences > SSH Keystore and generate a new key for Heroku. Enter hostname as heroku.com (no www or https). Once generated, view this key, copy it and manually save to your Heroku account (https://dashboard.heroku.com/account).

Import Existing Application

Go to your application settings and copy its Git URL. In your Codenvy workspace, go to File > Import from Location, paste the application URL and import the app. If the SSH key has been accurately generated and saved to your account, there shouldn’t be any issues with this step.

Update Heroku Application

Edit your application, add changes to index at Git > Add to Index, commit changes at Git > Commit and push to Heroku at Git > Remotes > Push.

Having imported a project, all project Git history and settings is saved, so there is no need to add Heroku as Git remote – it is already there.

Create Heroku Application

There’s no plugin in Codenvy that integrates with your Heroku account, manages keys and applications. However, it is possible to create a custom runtime with Heroku toolbelt installed, and run native Heroku commands there.

Here’s a Dockerfile that will build the right environment:


# start with a Codenvy image
FROM codenvy/shellinabox
RUN sudo apt-get update && \
    sudo apt-get -y install ruby-full git
RUN wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

ADD $app_src$ /home/user/app/
RUN sudo chown user:user -R /home/user/app
  	 
# Configure git, initialize repo, add to index and commit
WORKDIR /home/user/app
RUN sudo git config --global user.email "example@codenvy.com" && \
    sudo git config --global user.name "John Jameson" && \
    sudo git init && \
    sudo git add . && \
    sudo git commit -m "update from Codenvy"
CMD sleep 356d

This will build the right environment. Go to Terminal tab to execute a few Heroku and Git commands. When in the terminal, run:

$ cd app
$ sudo heroku login
$ sudo heroku create --http-git
$ sudo git push heroku master

In simple words, you need to login to your Heroku account, create a new app (this will add https remote ‘heroku’) and push to a remote.