Our example Rails app can be found here. You can clone this locally to run and experiment with.
The following is a step-by-step walkthrough of how the app was configured and why. The sample app is a fresh new Rails app, Dockerised, configured and a
convox.yml added. See the
README.md in the repo for the changes made.
A few steps to get started:
- Make sure you have Docker installed on your local machine.
- Signup for a Convox account It’s free!
- Install the Convox CLI.
- Install the Convox local Rack
Once you are all setup you can switch to your local rack with
convox switch local and start your local application with
convox start (make sure you are in the root directory).
You should now be able to access your application by going to https://web.rails.convox. If you renamed anything you may need to modify your local URL. The format is https://[service name].[app name].convox
Custom Application Components
Starting from the ruby:2.6.4 image, the Dockerfile executes the remaining build steps that your Rails app needs. There are basically 3 steps in this process, and they are executed in a particular order to take advantage of Docker’s build caching behavior.
yarn installare run to bring in any dependencies that are required by the app.
The application source is copied over. These files will change frequently, so this step of the build will very rarely be cached.
Finally, after setting the appropriate environment variables, the assets are precompiled.
The convox.yml file explains how to run the application. This file has two sections.
Resources: These are network-attached dependencies of your application. In this case we have a single resource which is a postgres database. When running locally Convox will automatically startup up a container running Postgres and will inject a
DATABASE_URLenvironment variable into your application container that points to the Postgres database. When your application is deployed to production Convox will startup an RDS postgres database for your application to use.
Services: This is where we define our application(s). In this case we have a single application called
webwhich is built from our dockerfile, and uses the postgres resource for a database. In a production application you may have additional services defined for things like Sidekiq task workers.
Deploying to production
In order to deploy to production we have to ensure we have completed the following steps:
- Signup for a Convox account
- Connect an AWS account
- Install an AWS Rack
- Make sure your CLI is logged in to your Convox account using
convox loginand your CLI Key
Once you are all set here you can see the name of your production rack
And switch your CLI to your production rack
convox switch [rack name]
Now you can create an empty application in your production rack
convox apps create --wait
And you can deploy your application to production (the first time you do this it may take up to 15 minutes to create the necessary resources)
convox deploy --wait
Finally you can retrieve the URL from your production application with