Ruby on Rails has always been a leader in developer productivity, making it easier than ever to build robust and interactive web applications. However, deploying and publishing these applications has often been an afterthought for developers. That’s where Kamal comes in. Kamal, created by the team at 37Signals, is a new deployment tool that completes the end-to-end process from development to deployment. With Kamal, a single developer can do more with fewer resources.
Kamal runs your web application in a Docker container on a server and uses a web server called Traefik to handle network traffic. When you deploy a new version of your application, Kamal will build a new Docker image, start a new container, ensure its health, direct traffic to it, and stop the old container. This allows for zero downtime and blue/green deploys.
To set up Kamal, you need to install the Kamal gem and initialize the setup in your Rails application. This will create two files: config/deploy.yml, which contains deployment configuration, and .env, which contains secret environment variables.
Before configuring Kamal, you’ll need to acquire a Virtual Private Server (VPS) to host your web app. You’ll also need a domain name and a Docker image registry, such as DockerHub or GitHub, to upload your Docker image.
To configure the deployment, you’ll need to fill in the required values in the config/deploy.yml file, including your registry credentials and environment variables. The .env file should contain the values for KAMAL_REGISTRY_PASSWORD and RAILS_MASTER_KEY.
Once configured, you can run the server bootstrap command to set up and install everything necessary for Kamal. Then, you can start the deploy command to build and push the Docker image, start the Traefik container, and ensure the health of the containers.
For TLS/SSL, you can modify the config/deploy.yml file to enable Traefik to acquire an SSL certificate from LetsEncrypt. You’ll also need to modify the servers part of the file to direct SSL traffic to your application.
With Kamal, you can easily deploy and publish your Ruby on Rails applications with minimal downtime and SSL protection. There are many more features and possibilities with Kamal, so stay tuned for future blog posts about it.
Source link