Speedyrails can install Dokku, an open source PaaS, to your Speedyrails servers. Dokku provides the ability to run more than one container on a single server, allocating resources as needed.
- Dokku Commands
- Dokku Plugins
- Deploying a Rails Application With Dokku
- Adding a custom domain to your Dokku application
- Adding a SSL Certificate to your Dokku Application
- Viewing Application Logs
- Backing up Dokku Servers and Databases
For a list of your Dokku server's available commands, use
ssh -t to connect to your Dokku user at your server:
$ ssh -t firstname.lastname@example.org
Run commands on your Dokku server using
ssh -t email@example.com and a command:
$ ssh -t firstname.lastname@example.org <command>
For example, to check the version of Dokku running on your server, use the
$ ssh -t email@example.com version
For detailed information about a command, use the
$ ssh -t firstname.lastname@example.org <command>:help
Dokku supports plugins that extend the functionality of your Dokku platform.
Speedyrails manages plugin installation and can add plugins to your Dokku server by request.
Speedyrails installs plugins for MySQL and Let's Encrypt by default.
You can find a list of current Dokku plugins in the Dokku Community Documentation.
Deploying a Rails Application With Dokku
To configure Dokku to work with a Rails application, you must create a container for the application, create its database container, configure the application for the database, and link the database to your application.
Create an application container for your application:
$ ssh -t email@example.com apps:create your-app-name
Add a database container using a database plugin:
$ ssh -t firstname.lastname@example.org mysql:create your-app-name-db
To link your Rails application to your database, set the database scheme on your application using the
$ ssh -t email@example.com config:set your-app-name MYSQL_DATABASE_SCHEME=mysql2
Link the database container to your application container:
$ ssh -t firstname.lastname@example.org mysql:link your-app-name-db your-app-name
Add your Dokku application container as a git remote:
$ git remote add dokku email@example.com:your-app-name
In your application's
/config/database.yml, add the URL for the Dokku database container to your production environment:
url: <%= ENV["mysql2://mysql:aaa111bbb222cc33@dokku-mysql-your-app-name-db:3306/your-app-name-db"] %>
Procfileand set the application server:
web: bundle exec puma -C config/puma.rb
In your application's
Gemfile, add your application's Ruby version,
rails_12factorto your production group, and your database gem:
ruby '2.2.3' # Or your application's ruby version gem 'rails_12factor', group: :production gem 'mysql2'
Dokku uses the
rails_12factor gem to send logs to stdout and serve assets in production.
Push your application up to your Dokku server with git:
$ git push dokku master
Use your browser to view your Dokku server to verify the deploy.
git push dokku :master
Adding a custom domain to your Dokku application
After deploying your application, you can use a custom domain to point to your Dokku server:
Log in to your domain host and create DNS records to point to your Dokku server. For example, you can create an A record pointing to your application IP or a CNAME record pointing to abcde.speedy.cloud.
Using the command line, assign your application the domain:
$ ssh -t firstname.lastname@example.org domains your-app-name yourdomain.com
Adding a SSL Certificate to your Dokku Application
Speedyrails automatically installs Dokku's Let's Encrypt plugin to allow you to add SSL certificates to secure your application.
To add SSL certification to your application:
Add a valid email address to your application's Dokku configuration:
$ ssh -t email@example.com config:set --no-restart your-app-name DOKKU_LETSENCRYPT_EMAILfirstname.lastname@example.org
Use the Let's Encrypt plugin to add your SSL certificate:
$ ssh -t email@example.com letsencrypt your-app-name
Certificate Expiry and Revocation
Let's Encrypt SSL certificates are valid for 90 days, and are due for renewal after 60 days.
To check your certificate expiry status for all applications on your Dokku server, use the
$ ssh -t firstname.lastname@example.org letsencrypt:ls
To automatically renew the SSL certificates on your Dokku server during the renewal period, use the
$ ssh -t email@example.com letsencrypt:auto-renew
To revoke your application's SSL certificate, use the
$ ssh -t firstname.lastname@example.org letsencrypt:revoke your-app-name
Viewing Application Logs
Dokku provides logs to view activity on your Dokku server using the
$ ssh -t email@example.com logs
To view a continuous stream of your application logs, use the
$ ssh -t firstname.lastname@example.org logs -t
Backing up Dokku Servers and Databases
Full Server Backups
To back up your entire Dokku server, use the Cloud control panel to create a server backup.
Most Dokku database plugins allow you to backup your application database to an Amazon S3 account using Dokku commands. To backup your database you must first authorize the Dokku plugin to use your S3 account with your credentials before creating a backup.
:helpfunction for more information.
To backup your database to S3 using the MySQL plugin:
- Get an AWS access key ID and AWS secret access key from your AWS S3 account.
Use the terminal to authorize the plugin to use your S3 credentials:
$ ssh -t email@example.com mysql:backup-auth your-app-name AWS_ACCESS_KEY AWS_SECRET_KEY
Backup the application database using the
$ ssh -t firstname.lastname@example.org mysql:backup your-app-name AWS_BUCKET_NAME
After authorizing the database plugin to backup to an S3 bucket, you can also schedule regular backups using the MySQL plugin using the
To schedule a backup of your application database:
$ ssh -t email@example.com mysql:backup-schedule your-app-name CRON_SCHEDULE AWS_BUCKET_NAME
backup-schedule command uses crontab expressions to set a schedule. For example, to schedule a backup every day at 4:30 AM:
$ ssh -t firstname.lastname@example.org mysql:backup-schedule your-app-name "30 4 * * *" AWS_BUCKET_NAME