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

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
RUN mkdir /home/user/app /home/user/sdk
RUN wget -P /home/user/ --quiet http://repo.maven.apache.org/maven2/com/google/appengine/appengine-java-sdk/1.9.10/appengine-java-sdk-1.9.10.zip
RUN unzip /home/user/appengine-java-sdk-1.9.10.zip -d /home/user && cp -r /home/user/appengine-java-sdk-1.9.10/* /home/user/sdk && \
    rm -r /home/user/appengine-java-sdk-1.9.10.zip /home/user/appengine-java-sdk-1.9.10/
ENV CODENVY_APP_PORT_8080_HTTP 8080
EXPOSE 8080
WORKDIR /home/user/sdk/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

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:

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

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

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