This article demonstrates how to deploy a Ruby on Rails application with EYK. The process involves creating a Cluster, configuring the Dockerfile and Procfile in your project, and pushing your code from your repository to the remote EYK target. Your application will be available immediately and can be managed and scaled with the EYK Web Console.
- Prior to pushing your code, you need to have the following items in place:
- Cluster: To deploy an application, you need to have a Cluster to deploy it on. You can create multiple Clusters and each Cluster can run multiple applications. The steps for creating a Cluster are part of the solution below and can be skipped if you already have a Cluster configured.
- Dockerfile: Your Dockerfile is a text file in the root of your project that contains the commands executed to assemble your image. EYK builds the container image for you when you push your code to the eyk remote target. You can create this file yourself, or generate it using the CLI 'eyk init' command.
- Procfile: Your Procfile is a text file in the root of your project that declares named processes, or process types. Each line in the Procfile specifies the name of the process type followed by the specific command to run. EYK creates a group of containers for each process type which can be individually scaled and configured based on their role and requirements. The process type is an alphanumeric string. The ‘web’ process type is special as it is the only process type that will receive HTTP traffic from the EYK router. Other process types can be named arbitrarily. The ‘web’ process is used to run web applications such as a Ruby on Rails server. The ‘cmd’ process is used to execute non-web related processes, such as calling an asynchronous process. Each process will use the same container image defined in the Dockerfile of the project. You can create this file yourself, or generate it using the CLI 'eyk init' command.
Deploy an Application Step-by-Step
- Access the EYK Web Console with your Engine Yard account:
- Navigate to: eyk.ey.io to login and access the EYK Web Console
- Create a Cluster for your Application:
- Click Clusters from the menu bar at the top
- Click the '+ Add Cluster' button to create a new Cluster
- Cluster Name: Assign a name to your cluster which will become part of the default application URL
- Region: Select the AWS Region where you want your Cluster to reside
- Organization: Most EYK users will have just one selection here. However, if you are a consultant who has done work for multiple Engine Yard customers, you may have more than one selection here and will need to select the appropriate Organization to associate the cluster with.
Click the Create Cluster button to create your new Cluster
You will be returned to the Applications page after creating your Cluster
- Click Clusters from the menu bar at the top
- Login to EYK:
eyk ssologin eyk.<cluster-name>.<organization-name>.ey.io
- Prepare your code for the push to EYK:
git clone <URL>
- Prepare your Dockerfile and Procfile: You can provide your own Dockerfile and Procfile, or follow these steps for the EYK CLI Tool to create them for you:
eyk apps:init [-a --app=<app>] ruby-<Version>, for example, to deploy a Ruby 2.7 application,
eyk apps:init ruby-2.7
EYK supports Ruby versions
2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, and 2.7
The expected response is:
The following files have been created, run git add to have them under version control: Dockerfile Procfile .eyk/sparkplug.sh .eyk/cronenberg/cron-jobs.yml
.eyk/config/secrets.yml.erb .eyk/migrations/db-migrate.sh Also, relevant entries to run web, sidekiq, cronjobs, and db:migrate have been added to Procfile in a disabled form. In order to enable any of them, do uncomment the relevant line. And don't forget to commit files to version control!!!
Structure your code: In addition to your typical Rails application structure, you will place the Dockerfile and Procfile in the root of your application, as in this example:
. ├── app ├── bin ├── config ├── config.ru ├── db ├── doc ├── Dockerfile ├── Gemfile ├── lib ├── log ├── Procfile ├── public ├── Rakefile ├── README.md ├── script ├── test └── vendor
- Create your application in EYK:
eyk create <your-app-name>
- Use a git push to deploy your application to EYK:.
git push eyk <branch_name>
- Test your application: Validate that your application is up and running by connecting to your application’s URL. This command opens the application in your default browser.
Adding Environment Variables with the EYK CLI Tool
You can set any environment variables that need to be engaged for your application’s runtime environment one of two ways, using the
config:set command or by using the
config:push command, which uses your local config file to build all environment variables into the instance at once. Environment Variables can also be configured in the EYK Web Console. For details, see the Configure Environment Variables with the Kontainers Web Console article.
- Configure individual Environment Variables
eyk config:set <var_1_name>=<var_1_value> <var_2_name>=<var_2_value>--app=<app_name>
- In the EYK CLI Use
config:setDo this for each environment variable you need to set for your application.
Create your configuration file as a text file with the extension .env, following this example:
RACK_ENV=staging RAILS_ENV=staging MY_CUSTOM_VAR=hello_world
eyk config:push --app=<app_name> --path=<my_custom_path>
eyk config:list --app=<app_name>
In the EYK CLI Use
config:pushUse this method when your environment variables contain sensitive information, such as passwords, or in cases where you have several environment variables that need to be set.
- In the EYK CLI Check your Environment Variables: In order to verify all of the environment variables in your application’s environment, use the
- Getting Started with Engine Yard Kontainers
- Configure Environment Variables with the Kontainers Web Console
- Using Databases with Your Engine Yard Kontainers Application