
When I started working at Clever Cloud, I spent some time messing around with the platform and its tooling. This blog post will present you how I managed to:
- create a simple Scala/Akka HTTP template application with PostgreSQL persistence
- link the application to a managed PostgreSQL
- deploy it
- try it!
Create a Scala/Akka HTTP template 🔨
Get the sources
Clone the project generated from Akka Github quick start template.
This service provides the ability to manage a simple in-memory user registry exposing 4 routes:
- List all users
- Get a specific user
- Create a user
- Delete a user
A thorough description of available the cURL commands may be found here.
Add extra features
A few functionalities have been added on top of the original example:
- store the registry into a PostgreSQL database (instead of in memory)
- read database parameters from environment variables
- add a hardcoded basic authentication
All parameters may be specified in the application.conf file:
- basic auth
- database parameters
Parameters are fetched from environment variables, or the specified default value if none is found
Run the application using Clever Cloud CLI 🚀
Create a Clever Cloud application
This command creates a new application
- of type sbt for Scala
- named myakka
- in Paris region
- inside my test organisation testorg
Enable a dedicated build instance for faster build (optional pro tip)
By default a newly created application will run an XS instance which are quite small for building Scala applications fast. One way to build faster is to use a dedicated build Instance: In the Clever Cloud console, got to your application -> options, and check the box [] Enable dedicated build instance
This way you can keep your XS instance for running the application, but you can choose an XL for the build time. Or with the command line tool:
Create a PostgreSQL database
This command orders a PostgreSQL add-on instance and link it to myakka
, injecting the right environment variables into the application instance to contact the database.
Database creation and migration is performed using flywaydb tool. Those script may be found in the migration/db directory of the application resources.
Migration will be automatically called once you specify the proper build hook in the environment variables
CC_POST_BUILD_HOOK with value sbt flywayMigrate
Configure basic auth environment variables
Basic authentication login and password can be specified as environment variables using the clever env command. If none is found, basic authentication will default to application.conf file values
Link your local repo with your Clever Cloud application instance
Retrieve your application id with
Then link the local repository to the application (creating a .clever.json file)
Deploy
You are now ready to deploy and run your code, just run
You are now able to follow the deployment process until it completes successfully
Your application is running now!
Try it
It’s time to experiment with it using curl or your favorite GUI
Add a user
Adapt this command in order to insert a new user into the registry:
Get all users
Check that the user has been properly created, by getting the list of users:
It works, Success! 🎉