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
For a list of your Dokku server's available commands, use ssh -t
to connect to your Dokku user at your server:
$ ssh -t dokku@abcde.speedy.cloud
Run commands on your Dokku server using ssh -t dokku@abcde.speedy.cloud
and a command:
$ ssh -t dokku@abcde.speedy.cloud <command>
For example, to check the version of Dokku running on your server, use the version
command:
$ ssh -t dokku@abcde.speedy.cloud version
For detailed information about a command, use the :help
option.
$ ssh -t dokku@abcde.speedy.cloud <command>:help
Dokku Plugins
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 dokku@abcde.speedy.cloud apps:create your-app-name
Add a database container using a database plugin:
$ ssh -t dokku@abcde.speedy.cloud mysql:create your-app-name-db
To link your Rails application to your database, set the database scheme on your application using the
config:set
command:$ ssh -t dokku@abcde.speedy.cloud config:set your-app-name MYSQL_DATABASE_SCHEME=mysql2
Link the database container to your application container:
$ ssh -t dokku@abcde.speedy.cloud mysql:link your-app-name-db your-app-name
Add your Dokku application container as a git remote:
$ git remote add dokku dokku@abcde.speedy.cloud: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"] %>
Create a
Procfile
and set the application server:web: bundle exec puma -C config/puma.rb
In your application's
Gemfile
, add your application's Ruby version,rails_12factor
to 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 dokku@abcde.speedy.cloud 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 dokku@abcde.speedy.cloud config:set --no-restart your-app-name DOKKU_LETSENCRYPT_EMAIL=yourname@email.com
Use the Let's Encrypt plugin to add your SSL certificate:
$ ssh -t dokku@abcde.speedy.cloud 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 letsencrypt:ls
command:
$ ssh -t dokku@abcde.speedy.cloud letsencrypt:ls
To automatically renew the SSL certificates on your Dokku server during the renewal period, use the letsencrypt:auto-renew
command:
$ ssh -t dokku@abcde.speedy.cloud letsencrypt:auto-renew
To revoke your application's SSL certificate, use the letsencrypt:revoke
command:
$ ssh -t dokku@abcde.speedy.cloud letsencrypt:revoke your-app-name
Viewing Application Logs
Dokku provides logs to view activity on your Dokku server using the logs
command:
$ ssh -t dokku@abcde.speedy.cloud logs
To view a continuous stream of your application logs, use the -t
modifier:
$ ssh -t dokku@abcde.speedy.cloud 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.
Database Backups
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.
:help
function 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 dokku@abcde.speedy.cloud mysql:backup-auth your-app-name AWS_ACCESS_KEY AWS_SECRET_KEY
Backup the application database using the
backup
command:$ ssh -t dokku@abcde.speedy.cloud 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 backup-schedule
command.
To schedule a backup of your application database:
$ ssh -t dokku@abcde.speedy.cloud mysql:backup-schedule your-app-name CRON_SCHEDULE AWS_BUCKET_NAME
The backup-schedule
command uses crontab expressions to set a schedule. For example, to schedule a backup every day at 4:30 AM:
$ ssh -t dokku@abcde.speedy.cloud mysql:backup-schedule your-app-name "30 4 * * *" AWS_BUCKET_NAME
Comments
0 comments
Please sign in to leave a comment.