If you need a free demo account for Control Plane (no CC required), you can contact Justin Gordon, CEO of ShakaCode.
Check how the cpl gem (this project) is used in the Github actions.
Here is a brief video overview.
This simple example shows how to deploy a simple app on Control Plane using the cpl gem.
To maximize simplicity, this example creates Postgres and Redis as workloads in the same GVC as the app. In a real app, you would likely use persistent, external resources, such as AWS RDS and AWS ElastiCache.
You can see the definition of Postgres and Redis in the .controlplane/templates directory.
-
Ensure your Control Plane account is set up. You should have an
organization<your-org>for testing in that account. Set ENV variableCPLN_ORGto<your-org>. Alternatively, you may modify the value foraliases.common.cpln_orgin.controlplane/controlplane.yml. If you need an organization, please contact Shakacode. -
Install Control Plane CLI (and configure access) using
npm install -g @controlplane/cli. You can update thecplncommand line withnpm update -g @controlplane/cli. Then runcpln loginto ensure access. For more informatation check out the docs here. -
Run
cpln image docker-login --org <your-org>to ensure that you have access to the Control Plane Docker registry. -
Install the latest version of
cplgem on your project's Gemfile or globally. For more information check out Heroku to Control Plane. -
This project has a
Dockerfilefor Control Plane in.controlplanedirectory. You can use it as an example for your project. Ensure that you have Docker running.
Do not confuse the cpl CLI with the cpln CLI.
The cpl CLI is the Heroku to Control Plane playbook CLI.
The cpln CLI is the Control Plane CLI.
See the filese in the ./controlplane directory.
/templates: defines the objects created with thecpl setupcommand. These YAML files are the same as used by thecpln applycommand./controlplane.yml: defines your application, including the organization, location, and app name.Dockerfile: defines the Docker image used to run the app on Control Plane.entrypoint.sh: defines the entrypoint script used to run the app on Control Plane.
Check if the Control Plane organization and location are correct in .controlplane/controlplane.yml.
Alternatively, you can use CPLN_ORG environment variable to set the organization name.
You should be able to see this information in the Control Plane UI.
Note: The below commands use cpl which is the Heroku to Control Plane playbook gem,
and not cpln which is the Control Plane CLI.
# Use environment variable to prevent repetition
export APP_NAME=react-webpack-rails-tutorial
# Provision all infrastructure on Control Plane.
# app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml
cpl apply-template gvc postgres redis rails daily-task -a $APP_NAME
# Build and push docker image to Control Plane repository
# Note, may take many minutes. Be patient.
# Check for error messages, such as forgetting to run `cpln image docker-login --org <your-org>`
cpl build-image -a $APP_NAME
# Promote image to app after running `cpl build-image command`
# Note, the UX of images may not show the image for up to 5 minutes.
# However, it's ready.
cpl deploy-image -a $APP_NAME
# See how app is starting up
cpl logs -a $APP_NAME
# Open app in browser (once it has started up)
cpl open -a $APP_NAMEAfter committing code, you will update your deployment of react-webpack-rails-tutorial with the following commands:
# Assuming you have already set APP_NAME env variable to react-webpack-rails-tutorial
# Build and push new image with sequential image tagging, e.g. 'react-webpack-rails-tutorial:1', then 'react-webpack-rails-tutorial:2', etc.
cpl build-image -a $APP_NAME
# Run database migrations (or other release tasks) with latest image,
# while app is still running on previous image.
# This is analogous to the release phase.
cpl runner rails db:migrate -a $APP_NAME --image latest
# Pomote latest image to app after migrations run
cpl deploy-image -a $APP_NAMEIf you needed to push a new image with a specific commit SHA, you can run the following command:
# Build and push with sequential image tagging and commit SHA, e.g. 'react-webpack-rails-tutorial:123_ABCD'
cpl build-image -a $APP_NAME --commit ABCD- waits for Postgres and Redis to be available
- runs
rails db:prepareto create/seed or migrate the database