(Quick Reference)

4 Deploying applications - Reference Documentation

Authors: Burt Beckwith

Version: 1.2.3

4 Deploying applications

Initial state

When you initially start you won't have any configured services or applications. Running the cf-services script should display something similar to this:

$ grails cf-services

============== System Services ==============

+------------+---------+---------------------------------------+ | Service | Version | Description | +------------+---------+---------------------------------------+ | postgresql | 9.0 | PostgreSQL database service (vFabric) | | mysql | 5.1 | MySQL database service | | redis | 2.2 | Redis key-value store service | | mongodb | 1.8 | MongoDB NoSQL store | | rabbitmq | 2.4 | RabbitMQ messaging service | +------------+---------+---------------------------------------+

=========== Provisioned Services ============

None provisioned yet.

All of the available services are listed first, and then your configured service instances, if any.

If you run the cf-apps script you should see that there are no applications:

No applications available.

And if you run the cf-info script you should see that there are no resources in use:

VMware's Cloud Application Platform
For support visit support@cloudfoundry.com

Target: http://api.cloudfoundry.com (v0.999)

User: your.email@yourserver.com Usage: Memory (0B of 2.0G total) Services (0 of 16 total) Apps (0 of 20 total)

Services

Before deploying your application, you'll probably need to configure at least one service, e.g. a MySQL, PostgreSQL, MongoDB, or Redis database. Use the cf-create-service script for that, e.g.

$ grails cf-create-service mysql

Service 'mysql-2f5fb76' provisioned.

or

$ grails cf-create-service redis

Service 'redis-364841f' provisioned.

By default a name is generated for you, but you can choose the name, and also bind it to an existing application. You can also bind a service to an application when you deploy the application.

Re-running the cf-services script will display the new services:

============== System Services ==============

+------------+---------+---------------------------------------+ | Service | Version | Description | +------------+---------+---------------------------------------+ | postgresql | 9.0 | PostgreSQL database service (vFabric) | | mysql | 5.1 | MySQL database service | | redis | 2.2 | Redis key-value store service | | mongodb | 1.8 | MongoDB NoSQL store | | rabbitmq | 2.4 | RabbitMQ messaging service | +------------+---------+---------------------------------------+

=========== Provisioned Services ============

+-----------------+---------+ | Name | Service | +-----------------+---------+ | mysql-2f5fb76 | mysql | | redis-364841f | redis | +-----------------+---------+

Use the cf-delete-service script to delete a service:

$ grails cf-delete-service redis-364841f

Successfully removed service: redis-364841f

Applications

The cf-push script creates an application. It deploys a war file and optionally binds one or more services, and has options to configure the allocated memory and associated URLs. By default it also starts the application but you can deploy it without starting if you want to perform configuration steps after creating the application.

The default memory allocation is 512MB but this can be overridden with the --memory parameter when running the script

$ grails prod cf-push --memory=1G

or changed later using the cf-update-memory script.

You can use an existing war file but if one isn't specified then a war is built for you.

Most scripts are not environment-specific but cf-push builds a war file, so be sure to specify the environment.

A typical deploy command would be

$ grails prod cf-push --services=mysql-2f5fb76

or if you're running the interactive script:

prod cf-push --services=mysql-2f5fb76

and you should see output similar to

Environment set to production
Building war file
     [gspc] Compiling 13 GSP files for package …
…
Building WAR file …
     [copy] Copying 633 files to …
…
[propertyfile] Updating property file: …
…
      [jar] Building jar: .../target/cf-temp-1299173015209.war
…
Done creating WAR ...target/cf-temp-1299173015209.war

Application Deployed URL: 'myappname.cloudfoundry.com'?

Uploading Application Information. Trying to start Application: 'myappname'. ..................

Application 'myappname' started.

Running cf-apps should display something like this:

+-------------+----+---------+----------------------------+---------------+
| Application | #  | Health  | URLs                       | Services      |
+-------------+----+---------+----------------------------+---------------+
| myappname   | 1  | RUNNING | myappname.cloudfoundry.com | mysql-2f5fb76 |
+-------------+----+---------+----------------------------+---------------+

You might also omit the service bindings and deploy without starting:

grails prod cf-push --no-start

or use a pre-built war:

grails prod cf-push --warfile=target/myappname.war

Note that the war file name has no bearing on the deployed url - the war is deployed as the default ('ROOT') context in Tomcat.

Automatic binding and provisioning

You can also let the plugin discover required services for you. The plugin will determine that you probably need a MySQL or PostgreSQL database if you have the Hibernate plugin, a MongoDB instance if you have the Mongo plugin, and a Redis instance if you have that plugin.

If you specify a service of the correct type (with the --services attribute) then it'll be used, otherwise if you need one and have one provisioned it will be suggested to you, e.g.

Would you like to bind the 'mysql-2f5fb76' service? ([y], n)

and if you need one and don't have one provisioned, the plugin will offer to provision and bind one for you, e.g.

Would you like to create and bind a redis service? ([y], n)