Note: These instructions use the cf version 6. The instructions are not compatible with any cf version < 6
If you are already familiar with anynines you probably used the CLI v5 before. The version 6 of the CLI provides you with a couple of benefits:
- Much easier to install (no Ruby dependencies)
- Much faster
- Shorter commands
- Usable in bash scripts
To interact with anynines you will have to install a small CLI (Command Line Interface) which allows you to deploy and manage your applications on Cloud Foundry. The following instructions will show you the basic usage of this tool enabling you to manage an application’s lifecycle including deployment, scaling and some basic troubleshooting.
- Sign up for an user account on anynines.com if you haven’t yet.
- Download and install the Command Line Interface to interact with anynines. Need help?
- Specify the anynines API endpoint in the CLI:
$> cf api https://api.aws.ie.a9s.eu
- Login using the credentials from your anynines account:
$> cf loginYour login information will be stored in a config.json file so that all following commands are authorized until you logout (
cf logout). The CLI will ask you which space to select. See the next point for more information.
Organize your applications in spaces and organizations
anynines provides 2 major units to structure your PaaS environment. So-called organizations are used to organize users within a common unit. Spaces are used to organize your application instances within separate environments (e.g. test, staging, production). Each organization can be divided into several spaces.
We have already created an organization and three spaces (production, stating, test) for you. After you've logged it, the CLI will ask you which space to select. Use one of the available spaces or press Enter so skip the space selection.
You can see the available organizations by tying:
$> cf orgs
To see all available spaces, simply type:
$> cf spaces
You can change or select an organization or a space by typing:
$> cf target [-o <org_name>] [-s <space_name>]
cf target without any parameters will show your current organization and space.
Let's target the test space right now (if you haven't done this already):
$> cf target -s test
Deploy your first application!
To warm up, we prepared a simple Ruby on Rails application you can use to play around with anynines. The application is a pretty basic post management tool, similar to a basic ToDo list.
- We use git to copy the source code to your local machine:
$> git clone https://github.com/anynines/simple_rails_app.git
$> cd simple_rails_app
- Our example application requires a Postgresql service instance for storing data. The command below will create a postgresql service with the service plan "postgresql-single-small". This service plan provides you 3GB Postgresql storage and is free of charge. After the plan's name, you have to specify a name for the service instance. This name will be used by further commands to refer to this service instance (you can chose any name you want, for the sake of this tutorial, you should use my_first_postgresql as service name - otherwise you have to adapt the manifest file of the sample application):
$> cf create-service a9hcp-postgresql postgresql-single-small <postgres_service_name> # You should use my_first_postgresql in this tutorialTo get a list of all services and service plans available, run
- The example application comes with a deployment file (manifest.yml.example) describing the environment for your application deployment. If you've used a name different than my_first_postgresql, please adapt the file accordingly. Now let's push (upload the sources and start the application) our example application to anynines:
$> cf push --random-route
- At the end of the deployment process your application will be available under the displayed URL:
...Just copy the URL and test this application in your browser.
usage: 350M x 1 instances
Scaling with one command
A key point using a PaaS (Platform as a Service) is the ability to scale your application instances in mere minutes. Let’s see how easy it is to scale our application to e.g. two instances:
$> cf scale simple_rails -i 2 # The name simple_rails is configured in the manifest file we've used
The same works for the RAM dedicated to each application instance:
$> cf scale simple_rails -m 250M
Yes and your application will be restarted with 250 MB RAM. You'll see that your application is now running on 2 instances, too.
You can check the status of your application(s) by typing:
$> cf app <app_name> # simple_rails in this tutorial
Access the log files
Using the following command, you can check the recent logs of all your application instances:
$> cf logs --recent <app_name> # simple_rails in this tutorial
cf logs will display you the current log output. So when something happen in your application you will see it immediately.
Note: Make sure your application logs all the output to standard output.
How to get help
The CLI provides you with a simple command overview. Just type
cf help to get an overview of the available commands in the CLI. To get information on a specific command, use:
$> cf <command> -h # Use e.g. push
- How to run applications written in any language or framework
- Using environment variables to configure your application
- Map your own domains to your applications
- Use a SSL certificate to secure your applications
- Running admin tasks (db migrations, etc ...)
- Specify a custom command for starting your application
Please sign in to leave a comment.