Be sure that:
- you push to the master branch
- you commit your
gems.locked
orGemfile.lock
file - you have a
config.ru
file (this one is most of the time generated by rails) - you have
gem puma
in yourGemfile
(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.
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 CC_RUBY_VERSION=rubyversion
where rubyversion
represents:
- "3" will select the greatest "3.X.Y" version available.
- "3.3" will select the greatest "3.3.Y" version available.
- "3.3.1" will select the "3.3.1" version.
Due to current landscape in ruby applications, the default version is the greatest 3.3.Y. We also provide versions 2.3.Y, 2.4.Y, 2.5.Y, 2.6.Y and 2.7.Y.
If given rubyversion
does not match any available version, your deployment will fail.
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 set up of the required variables for this environment in your ./config/
folder files.
There are many way to add secret key to your environment and each one is valid. Clever Cloud provides you a secure way so you don't have to commit any file containing it.
- generate the secret key locally with
rake secret
- add it to your environment in
./config/secret.yml
with:
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
You can specify a list of rake goals to execute before the deployment of your application by using the CC_RAKEGOALS
environment variable.
The value of this variable must be a comma-separated list of goals, for instance:
CC_RAKEGOALS="db:migrate, assets:precompile"
We do not execute any rake goals by default.
To run a Sidekiq process in background you will need to enable it with the CC_ENABLE_SIDEKIQ=true
environment variable.
Please note you will need a Redis instance to use this feature.
You can specify multiple Sidekiq configuration files with the CC_SIDEKIQ_FILES
environment variable.
The value of this variable must be a comma-separated list of files:
CC_SIDEKIQ_FILES="./config/sidekiq_1.yml,./config/sidekiq_2.yml,./config/sidekiq_3.yml"
Note: CC_SIDEKIQ_FILES
have precedence over CC_ENABLE_SIDEKIQ
which means that even if CC_SIDEKIQ_FILES
is defined and CC_ENABLE_SIDEKIQ
is set to false
, Sidekiq will still be enabled.
Each path 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
---
Static files are configured with environment variables:
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 (for example /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 CC_RAKEGOALS
environment variable value.
CC_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 resources when starting.
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
inconfig/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 settings can be configured with environment variables:
NGINX_READ_TIMEOUT
: the response timeout in seconds. (Default: 300)
If you need basic authentication, you can enable it using environment variables. You will need to set CC_HTTP_BASIC_AUTH
variable to your own login:password
pair. If you need to allow access to multiple users, you can create additional environment CC_HTTP_BASIC_AUTH_n
(where n
is a number) variables.
NGINX settings can be configured further in clevercloud/http.json
. All its fields are optional.
languages
: configure a default language and redirectionserror_pages
: configure custom files for error pagesforce_https
: automatically redirect HTTP traffic to HTTPSaliases
: set up redirectionscharset
: 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 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 preferred over the setting from config/puma.rb
.
CC_PUMA_WORKERS
overrides the number of workers (for example,CC_PUMA_WORKERS=2
)CC_PUMA_THREADS
overrides the number of threads per worker, can be a raw number or a range (for example,CC_PUMA_THREADS=6
orCC_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.
You can override the puma default server by setting an environment variable CC_RACKUP_SERVER=yourserver
. We do not recommend you do it.