Deploying with Kamal 2.0 | Rails 8 Unpacked
Ruby on Rails・3 minutes read
Deploying a Rails 8 app involves provisioning a DigitalOcean droplet with sufficient RAM and storage, configuring a deployment tool named Kamal for seamless integration of Docker, and securely managing sensitive information using 1Password. Key steps include setting up a configuration file, integrating SSL, and ensuring the application connects to a managed database cluster before running the deployment command to bring the app live.
Insights
- Deploying a Rails 8 application involves setting up a DigitalOcean droplet with specific configurations, including a 2 GB RAM droplet and a database cluster with 1 GB RAM and 10 GB disk space, while also recommending additional storage through a 100 GB volume for data management, ensuring the app has sufficient resources for initial needs.
- Kamal streamlines the deployment process by allowing users to configure the application with a `deploy.yaml` file, manage sensitive credentials securely through a password manager like 1Password, and automate SSL certification, thus simplifying the integration of Docker and enhancing security during the deployment of applications to various servers, including cloud platforms.
Get key ideas from YouTube videos. It’s free
Recent questions
What is a DigitalOcean droplet?
A DigitalOcean droplet is a virtual private server (VPS) that allows users to host applications and websites. It provides a scalable and flexible environment for developers to deploy their projects. Each droplet can be customized with different amounts of CPU, RAM, and storage, depending on the needs of the application. DigitalOcean droplets are popular for their simplicity and cost-effectiveness, making them an ideal choice for developers looking to manage their own server infrastructure without the complexities of traditional hosting solutions.
How do I enable SSL for my website?
Enabling SSL for your website involves obtaining an SSL certificate and configuring your web server to use it. The process typically starts with generating a Certificate Signing Request (CSR) and submitting it to a Certificate Authority (CA) to obtain the certificate. Once you have the certificate, you need to install it on your server and configure your web server settings to enforce HTTPS. Many hosting providers offer automated SSL solutions, which simplify this process. Additionally, you can set SSL to true in your deployment configuration to ensure secure connections for your application.
What is Docker Hub used for?
Docker Hub is a cloud-based registry service that allows developers to store, share, and manage Docker images. It serves as a central repository where users can upload their images and pull them for deployment on various platforms. Docker Hub supports versioning, making it easy to manage different iterations of an image. It also provides features like automated builds and webhooks, which can streamline the development workflow. By using Docker Hub, developers can ensure that their applications are easily accessible and can be deployed consistently across different environments.
How do I store sensitive information securely?
Storing sensitive information securely is crucial for protecting your application and its users. One effective method is to use a password manager, such as 1Password, which allows you to store and manage sensitive credentials like API keys, passwords, and encryption keys in a secure environment. These tools often provide features like encryption and secure sharing, ensuring that your data is protected from unauthorized access. Additionally, you can integrate these password managers with your deployment tools to fetch sensitive information dynamically, avoiding hardcoding credentials in your application code.
What is Kamal in application deployment?
Kamal is a deployment tool designed to simplify the process of deploying applications using Docker. It allows developers to easily configure and manage their deployment environments, making it possible to deploy applications to various servers, including cloud services like DigitalOcean. With Kamal, users can create a configuration file that specifies essential details such as service names and Docker images. The tool automates many deployment tasks, such as setting up the server environment, managing Docker containers, and ensuring that applications are live and accessible. This streamlining of the deployment process helps developers focus more on building their applications rather than managing infrastructure.
Related videos
Summary
00:00
Deploying Rails 8 with Kamal on DigitalOcean
- Deploying a Rails 8 app requires provisioning a server, with DigitalOcean droplets being a recommended option for hosting without using platform as a service (PaaS) solutions.
- A typical DigitalOcean droplet for deployment can have 2 GB of RAM, which is sufficient since the app does not utilize Redis or caching mechanisms.
- The database cluster attached to the droplet should have 1 GB of RAM and 10 GB of disk space, adequate for initial deployment needs.
- An additional volume named "volume-nyc1-02" with 100 GB is recommended for data storage, ensuring ample space for the application’s database.
- Kamal is a deployment tool that simplifies deploying applications using Docker, allowing deployment to any server, including cloud services like DigitalOcean.
- To configure Kamal, create a `config/deploy.yaml` file, specifying the service name, Docker image name, and the server's IP address (e.g., 64-227-1633).
- Enable SSL certification automatically by setting SSL to true in the configuration and specifying a DNS host, such as `life-planner.typecraft.dev`.
- Use Docker Hub as the default registry for images, requiring a personal access token for authentication, which can be managed in Docker Hub account settings.
- Store sensitive information like the Kamal Registry password and RAILS_MASTER_KEY in a secure password manager, such as 1Password, to maintain security during deployment.
- Kamal can fetch passwords from 1Password using its CLI, allowing seamless integration of sensitive credentials into the deployment process without hardcoding them in the configuration files.
10:52
Deploying Rails Application with Kamal and 1Password
- Set the Kamal Registry Password using 1Password for secure storage and management of credentials during deployment.
- Create a new RAILS_MASTER_KEY for production by running `rails credentials:edit --environment=production`, which generates a credentials file and stores the key in `config/credentials/production.key`.
- Store the RAILS_MASTER_KEY in 1Password and update the Kamal Secrets file to extract this key for the production environment.
- For DigitalOcean, uncomment the DB_host line in the configuration and set it to a new environment variable called db_host, using the connection string from the DigitalOcean database cluster.
- Copy the database connection string from DigitalOcean, save it in 1Password as DB_host, and inject it into Kamal by adding a new line in the Kamal Secrets file.
- Attach a volume named `volume-nyc1-02` to the DigitalOcean droplet, ensuring to replace dashes with underscores for compatibility when mounting to the Rails storage folder.
- Update the `database.yaml` file for production to use SQLite, changing the database name from development to production, and ensure it points to `storage/life_task_planner_production.sqlite3`.
- Edit the production credentials file to include a DB URL key, using the database URL from DigitalOcean, ensuring the application can connect to the managed database cluster.
- Run `Kamal setup` to deploy the application, which installs Docker, clones the repository, builds the image, pushes it to Docker Hub, and runs the container, making the app live at `life-planner.typecraft.dev`.




