On this page

Ruby

Create a Clever Cloud account

The API of Clever Cloud uses OAuth 1 to perform authentication actions. There are two ways to signup to Clever Cloud: email or GitHub login.

Go to the Clever Cloud Console and select the method you prefer.

Email Authentication

This kind of auth requires a valid and non-temporary disposable e-mail, and a password having at least 6 characters. Do not forget to validate your email by clicking the link you will receive.

GitHub Authentication

The GitHub signup allows you to create an account or link your existing one to GitHub, in one click. This process asks the following permsissions: 

  • Read your Public Key
  • Read User Repositories

The “repository permission” is used to deploy your GitHub apps directly to Clever Cloud, with a simple step.

If you need to give access to Clever Cloud’s API to a specific GitHub organization, you can do it here.

Two Factor Authentication (2FA)

Clever Cloud supports 2FA. You can enable it here: https://console.clever-cloud.com/users/me/authentication

Please, backup your recovery codes, we won’t be able to restore access to your account if you lose access to your regular codes.

You need to add a SSH key to your Clever Cloud’s account to deploy via Git. SSH keys are used to establish a secure connection between your computer and Clever Cloud. A user can have multiple SSH keys.

I need to create my SSH key

  1. In your Terminal, enter the following bash line:

    ssh-keygen -t ed25519 -C "your_email@youremail.com"
    

    This command creates a new ssh key using the provided email, so that the owner of the key can be identified.

  2. When prompted in which file you want to save the key, just press entrer. If it says that the file already exists, enter n for no. Type ls, constat the presence of the file and jump to Add your SSH key on Clever Cloud.

  3. When asked, enter a passphrase:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_ed25519):
# Now you should enter a passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

Which should give you something like this:

Your identification has been saved in /your_home_path/.ssh/id_ed25519.
Your public key has been saved in /your_home_path/.ssh/id_ed25519.pub.
The key fingerprint is:
01:0e:e5:2d:ab:98:d6:17:a1:6d:f0:68:9f:d0:a2:db your_email@youremail.com

I created my account with GitHub

If your account is linked to GitHub, a panel with your GitHub SSH keys will appear in the “SSH Keys” tab. You can add any key already present in your GitHub account by clicking on the import button next to it.

Add your SSH key on Clever Cloud

Public SSH Key

To declare your public SSH Key on Clever Cloud, in the left navigation bar, go in “Profile” and in the “SSH Keys” tab, add the key by entering a name and the public SSH key. The key is the entire content of the **id_[ed25519/rsa].pub** file including the id_ed25519/ssh-rsa part and your email.

Private SSH Key

If you want to clone a repository from a private repository, you can add a Private SSH Key to an application by creating a folder clevercloud at the root of your application and creating the file clevercloud/ssh.json with the following content:

{
    "privateKeyFile": "path/to/file"
}

Of course you need to provide a valid path to a file that contains a valid key and that you will push on the Clever Cloud git remote.

If you have trouble configuring this key you can refer to this extended documentation

Create an application on Clever Cloud

via the web console

  1. Create a new app by clicking on the Add an Application button, in the sidebar.
  2. Select a brand new instance (or a repository from GitHub if your account is linked).
  3. Then select Ruby in the platform list.
  4. Configure your scaling options.
  5. Enter your application’s name and description and click “Next”. You can also select the region you want (North America or Europe).

Refer to https://www.clever-cloud.com/doc/getting-started/ for more details on application creation via the console.

via the Clever Tools CLI

  1. Make sure you have clever-tools installed locally. Report to https://www.clever-cloud.com/doc/reference/clever-tools/getting_started/
  2. In your code folder, do clever create --type <type> <app-name> --region <zone> --org <org> where type is the type of technology you rely on, app-name the name you want for your application, zone deloyment zone (par for Paris and mtl for Montreal), and org the organization ID the application will be created under.

Refer to https://www.clever-cloud.com/doc/reference/clever-tools/create/ for more details on application creation with Clever Tools.

Setting up environment variables on Clever Cloud

With the Clever Cloud console

  1. Go to the Clever Cloud console, and find the app you want to fine tune under it’s organization.
  2. Find the Environment variables menu and select it.
  3. In this menu, you will see a form with VARIABLE_NAME and variable value fields. Fill them with the desired values then select Create.

With the Clever Tools CLI

  1. Make sure you have clever-tools installed locally. Report to https://www.clever-cloud.com/doc/reference/clever-tools/getting_started/
  2. In your code folder, do clever env set <variable-name> <variable-value>

Refer to https://www.clever-cloud.com/doc/reference/reference-environment-variables/ 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 Ruby on Rails application

Mandatory configuration

Be sure that:

  • you push to the master branch
  • you commit your gems.locked or Gemfile.lock file
  • you have a config.ru file (this one is most of the time generated by rails)
  • you have gem puma in your Gemfile (puma is the default application server from rails, when creating a new ruby application, an environment variable is automatically added: CC_RACKUP_SERVER=puma)

You need to provide a gems.locked or Gemfile.lock file. To do that ensure you have at least once run bundle install in your terminal at the root of your rails project.

Choose ruby version

If you specify a ruby version in your gems.rb of Gemfile, we’ll use it, otherwise; keep reading.

On your Clever Cloud application create an environment variable RUBY_VERSION=rubyversion where rubyversion represents:

  • “2” will select the greatest “2.X.Y” version available.
  • “2.5” will select the greatest “2.5.Y” version available.
  • “2.5.3” will select the “2.5.3” version.

Due to current landscape in ruby applications, the default version is the greatest 2.5.Y. We provide also the 2.4.Y and 2.3.Y version.

If given rubyversion does not match any available version, your deployment will fail.

Choose your environment

You can set the RUBY_ENV environment variable to the value you want. By default it is set to production. Most used values are production and development but you can use any custom one as long as you have setted up of the required variables for this environment in your ./config/ folder files.

Secure configuration of secret key

There are many way to add secret key to your env and each one is valid. Clever Cloud provides you a secure way so you don’t have to commit any file containing it.

  1. generate the secret key locally with rake secret
  2. add it to your environment in ./config/secret.yml with:
production:
    secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Optional env and rake goals configuration with clevercloud/ruby.json

You can configure your deployment via the ./clevercloud/ruby.json file using the following syntax:

{
  "deploy" : {
    "env": "<string>",
    "rakegoals": [<string>],
    "sidekiq": true
  }
}

The following table describes each field:

UsageFieldDescription
Optionaldeploy.envThis field is only used for overriding the default "production" RAILS_ENV value.
Optionaldeploy.rakegoalsSpecify a list of rake goals to execute. They will be executed in the order of the list:
bundle exec rake "goal1"

bundle exec rake "goal2"

We do not execute any rake goals by default.
Optionaldeploy.sidekiqRun a sidekiq process in background. Please note you will need a redis instance to use this feature.

Sidekiq specific configuration

The sidekiq field can also be an array of strings instead of a boolean, like this:

"sidekiq":  [
   "./config/sidekiq_1.yml",
   "./config/sidekiq_2.yml",
   "./config/sidekiq_3.yml"
]

Each string is the path from the root of the repository to a sidekiq configuration file. Each file might contain something like this standard sidekiq.yml file:

---
:concurrency: 4
:pidfile:     tmp/pids/sidekiq_1.pid
:queues:
  - [critical, 2]
  - default

production:
  :logfile: ./log/sidekiq.log
---

Manage your static files and assets

Static files are configured with environment variabless:

STATIC_FILES_PATH: should point to a directory where your static files are stored.

STATIC_URL_PREFIX: the URL path under which you want to serve static files (e.g. /public/)

Note: the path of your folder must be absolute regarding the root of your application.

Note: setting the STATIC_URL_PREFIX to / will make the deployment to fail.

If you use the asset pipeline, make sure to include the assets:precompile task in the rakegoals field of clevercloud/ruby.json.

{
    "deploy": {
        "rakegoals": ["db:migrate", "assets:precompile"]
    }
}

Note: if your project uses webpacker, make sure to enable the dedicated build instance option in the Information menu of your application in the Clever Cloud console because webpacker needs a lot a ressources when starting.

Using Active Storage and Cellar S3

Only for Rails >= 5.2.

  • Enable Active Storage for your application: $ rails active_storage:install then $ rake db:migrate
  • Add gem "aws-sdk-s3", require: false to your Gemfile, run $ bundle install
  • Add config.active_storage.service = :clevercloud in config/environments/production.yml
  • Add in config/storage.yml:
clevercloud:
  service: S3
  access_key_id: <%= ENV['CELLAR_ADDON_KEY_ID'] %>
  secret_access_key: <%= ENV['CELLAR_ADDON_KEY_SECRET'] %>
  region: us-east-1
  bucket: <%= ENV['CELLAR_ADDON_BUCKET_NAME'] %>
  endpoint: <%= ENV['CELLAR_ADDON_ENDPOINT'] %>
  force_path_style: true
  • In the clever cloud console create a Cellar S3 storage add-on, name it, link it to your rails application and create a bucket.
  • In the environment variables section of your Ruby on Rails application on Clever Cloud add the following environment variables:
CELLAR_ADDON_BUCKET_NAME=<your bucket name>
CELLAR_ADDON_ENDPOINT=https://cellar-c2.services.clever-cloud.com

You can now commit and push your changes.

Also, you are able to use a Filesystem Bucket to store your static files. Please refer to the File System Buckets section.

nginx configuration

nginx settings can be configured with environment variables:

  • NGINX_READ_TIMEOUT: the response timeout in seconds. (Defaut: 300)

Nginx settings can be configured further in clevercloud/http.json. All its fields are optional.

  • languages: configure a default language and redirections
  • error_pages: configure custom files for error pages
  • force_https: automatically redirect HTTP traffic to HTTPS
  • aliases: set up redirections
  • charset: force a specific charset
{
    "languages": {
        "default": {"rewrite": "en"},
        "fr": {"rewrite": "en"}
    },
    "error_pages": {
        "404": "path/to/page"
    },
    "force_https": true,
    "aliases": {
        "/path""redirection"
    },
    "charset": "latin-1"
}

Puma configuration

Puma reads its configuration from the config/puma.rb file. See the puma documentation for more information.

You can override this configuration with environment variables. Each of them, when specified, will be be preferred over the setting from config/puma.rb.

  • CC_PUMA_WORKERS overrides the number of workers (e.g. CC_PUMA_WORKERS=2)
  • CC_PUMA_THREADS overrides the number of threads per worker, can be a raw number or a range (e.g. CC_PUMA_THREADS=6 or CC_PUMA_THREADS=4:8)

If they are not defined in the environment nor in config/puma.rb we will setup the values depending on the size of the scaler your application is running on. We also fill the WEB_CONCURRENCY and RAILS_MAX_THREADS environment variable if they are not present as they may be used by rails' puma configuration.

Overridding rackup application server

You can override the puma default server by setting an environment variable CC_RACKUP_SERVER=yourserver. We do not recommend you do it.

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

  1. 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.

  2. Locally, under your code folder, type in git init to set up a new git repository or skip this step if you already have one.

  3. Add the deploy URL with git remote add <name> <your-git-deployment-url>.

  4. Add your files via git add <files path> and commit them via git commit -m <your commit message>.

  5. Now push your application on Clever Cloud with git push <name> master

Refer to https://www.clever-cloud.com/doc/getting-started/quickstart/ for more details on git deployments.

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, please refer to the full list and check add-ons dedicated pages for full instructions.

During add-on creation, you will see Applications screen, 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 will automatically be 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 addons 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 Common configuration page.

You may want to have an advanced usage of your application, in which case we recommend you to read the Administrate documentation 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.