Play Framework 1.x (Scala)
Overview
Clever Cloud supports Play 1.x applications natively. The present guide explains how to set up your application to run on Clever Cloud.
Create an application on Clever Cloud
With the web console
Refer to Quickstart for more details on application creation via the console.
With the Clever Tools CLI
- Make sure you have clever-tools installed locally or follow our CLI getting started guide.
- In your code folder, do
clever create --type <type> <app-name> --region <zone> --org <org>where :typeis the type of technology you rely onapp-namethe name you want for your application,zonedeployment zone (parfor Paris andmtlfor Montreal)orgthe organisation ID the application will be created under.
Refer to clever create for more details on application creation with Clever Tools.
Setting up environment variables on Clever Cloud
With the Clever Cloud console
- Go to the Clever Cloud console, and find the app you want to fine tune under it’s organisation.
- Find the Environment variables menu and select it.
- In this menu, you will see a form with VARIABLE_NAME and variable value fields.
- Fill them with the desired values then select Add.
- Don’t forget to “Update Changes” at the end of the menu.
With the Clever Tools CLI
- Make sure you have clever-tools installed locally. Refer to our CLI getting started.
- In your code folder, do
clever env set <variable-name> <variable-value>
Refer to environment variables reference for more details on available environment variables on Clever Cloud.
You can of course create custom ones with the interface we just demonstrated, they will be available for your application.
Configure your Scala + Play! 1 application
Select Play! 1.x version
Clever Cloud supports Play! 1.2 to 1.11, and uses Play! 1.7 by default. You can select the Play! version for your application by setting the CC_PLAY1_VERSION environment variable. The former PLAY1_VERSION name remains supported as an alias. A clevercloud/play1_version file containing the version also works, but it’s deprecated and ignored when CC_PLAY1_VERSION is set.
The CC_PLAY1_VERSION environment variable can contain one of the following values:
1.2or12for Play! 1.21.3or13for Play! 1.31.4or14for Play! 1.41.5or15for Play! 1.51.6or16for Play! 1.61.7or17for Play! 1.71.8or18for Play! 1.81.9or19for Play! 1.91.10or110for Play! 1.101.11or111for Play! 1.11
Play! configuration with application.conf
By default, your application will run on Clever Cloud with the option --%clevercloud.
It means that you can define special keys in your application.conf file that will be used only on Clever Cloud.
You can for example:
set production mode so the files are compiled at startup time and the errors are logged in a file:
%clevercloud.application.mode=prodset up a mysql database (using environment variables)
%clevercloud.db.url="jdbc:mysql://"${MYSQL_ADDON_HOST}"/"${MYSQL_ADDON_DB} %clevercloud.db.driver=com.mysql.jdbc.Driver %clevercloud.db.user=${MYSQL_ADDON_USER} %clevercloud.db.pass=${MYSQL_ADDON_PASSWORD}
More information on playframework.com.
HTTPS support
HTTPS is handled by Clever Cloud ahead of your application, your application retrieves the traffic in plain http. To be able to use request.secure, you have to add XForwardedSupport=all in application.conf.
Monitor your application with New Relic
You can use New Relic to monitor your application on Clever Cloud.
Please refer to our New Relic documentation to configure it for your application.
Environment injection
Clever Cloud injects environment variables from your application settings as mentioned in setting up environment variables and is also injecting in your application production environment, those from your linked add-ons.
Custom build configurations
On Clever Cloud you can define some build configuration: like the app folder to deploy or the path to validate your application deployment is ready To do that follow the documentation here and add the environment variable you need.
To access the environment variables from your code, you need to add my.option=${MY_VARIABLE} in your application.conf file, and then use the configuration item my.option in your application. e.g %clevercloud.db.url="jdbc:mysql://"${MYSQL_ADDON_HOST}"/"${MYSQL_ADDON_DB}
Git Deployment on Clever Cloud
You need Git on your computer to deploy via this tool. Here is the official website of Git to get more information: git-scm.com
Setting up your remotes
The “Information” page of your app gives you your Git deployment URL, it looks like this:
git+ssh://git@push.clever-cloud.com/<your_app_id>.git- Copy it in your clipboard
Locally, under your code folder, type in
git initto set up a new git repository or skip this step if you already have oneAdd the deploy URL with
git remote add <name> <your-git-deployment-url>Add your files via
git add <files path>and commit them viagit commit -m <your commit message>Now push your application on Clever Cloud with
git push <name> master
Refer to git deployments for more details.
Linking a database or any other add-on to your application
By linking an application to an add-on, the application has the add-on environment variables in its own environment by default.
On add-on creation
Many add-ons do exist on Clever Cloud: refer to the full list and check add-ons dedicated pages for full instructions.
During add-on creation, an Applications screen appears, with a list of your applications. You can toggle the button to Link and click next. If you finish the process of add-on creation, the application is automatically linked to it.
Add-on already exists
In the Clever Cloud console, under the Service Dependencies menu of your application, you can use the Link add-ons dropdown menu to select the name of the add-on you want to link and use the add button to finish the process.
You can also link another application from the same page in the Clever Cloud console, using the Link applications dropdown menu.
More configuration
Need more configuration? To run a script at the end of your deployment? To add your private SSH key to access private dependencies?
Go check the Configure applications page.
For advanced usage of your application, read the Develop section.
If you can’t find something or have a specific need like using a non supported version of a particular software, please reach out to the support.
Enable health check during deployment
The healthcheck allows you to limit downtimes. Indeed, you can provide Clever Cloud with paths to check. If these paths don’t return a 2xx response code, the deployment fails.
Add one (or several) environment variable as such:
CC_HEALTH_CHECK_PATH=/my/awesome/pathOr
CC_HEALTH_CHECK_PATH_0=/my/awesome/path
CC_HEALTH_CHECK_PATH_1=/my/other/pathThe deployment process checks all paths. All of them must reply with a 2xx response code, such as 200 OK or 204 No Content. Clever Cloud retries with an increasing delay before it marks the deployment as failed, so an application that needs some time to start isn’t rejected on the first attempt.
When no health check path is configured, Clever Cloud requests the root path / and accepts any response code from 200 to 499: a 404 or a 401 means your application is up and answering. For Java applications, the deploy.pingPaths of the clevercloud/*.json file also count as configured paths.
Before any HTTP request, Clever Cloud checks that a service listens on the public port, 8080, on a public interface. Depending on your configuration, it’s your application, the port Docker maps from CC_DOCKER_EXPOSED_HTTP_PORT, or the first Request Flow middleware. A service on this port bound only to localhost or 127.0.0.1 makes the deployment fail with Your application is listening on localhost instead of publicly: listen on 0.0.0.0 instead.
On runtimes supporting Request Flow, when middleware runs in front of your application, Clever Cloud also checks that each middleware port and your application port are listening. With CC_REQUEST_FLOW="block", Clever Cloud only checks the service answering on the public port, not your application.
Example
With the preceding paths, here are the logs of a failing health check:
Checking public port (8080) is listening as expected
Response from GET /my/awesome/path is 200 (within expected range 200...300)
Response from GET /my/other/path is 500, expected 200...300
Error while checking /my/awesome/path, /my/other/pathIn this example, the first path is OK, but the second one failed. This gives you a hint on what failed in your application.
Best practice for healthcheck endpoints
To make the most of a healthcheck endpoint, have it check your critical dependencies. For example:
- execute
SELECT 1 + 1;on your database - retrieve a specific Cellar file
- ping a specific IP through a VPN