Kamal Setup
-
Initiate a Linux instance & Get it's
- Public IP address
- SSH credentials
-
Edit the IP address & SSH config in Kamal
deploy.ymlfile. -
Test you SSH status with:
kamal lock status -
If the above returns a non-zero error code, run the below:
eval `ssh-agent -s` ssh-add <path-to-your-key>.pem -
Now test the SSH status again:
kamal lock statusThis should now run successfully & exit with 0.
-
Generate a Classic Personal Access Token for
container:write&container:readfor your Image Registry (DockerHub, GHCR, etc.) & add it to your environment variables (.env file). Also update the Registry details in thedeploy.yml. -
If your SSH user is a non-root user, run the below command to add the user to the docker group:
sudo usermod -aG docker ${USER}Note: The above needs to be ran on the Cloud VM. There is an open Issue on Kamal for the same here
Run the below for SSL config the first time
sudo mkdir -p /letsencrypt && sudo touch /letsencrypt/acme.json && sudo chmod 600 /letsencrypt/acme.json
-
Make sure you have docker buildx locally on your machine where you run the kamal CLI from!
-
Voila! You are all set to deploy your application to the cloud with Kamal! 🚀
kamal setup -c kamal/deploy.ymlThis will setup the cloud VM with all the necessary tools & dependencies to run your application.
Make sure to run
kamal env pushbefore akamal deployto push the latest environment variables to the cloud VM.
Debugging for Kamal
-
If you run into an error such as:
failed to solve: cannot copy to non-directory:Then simply run
pnpm clean& try again. -
Make sure your Database accepts connection from the cloud VM. You can do this by adding the VM's IP address to the
Allowed Hostsin your Database settings. -
If you get an error such as:
Lock failed: failed to acquire lock: lockfile already existsThen simply run
kamal lock release -c kamal/deploy.yml& try again. -
If you run into:
No config foundThen simply add the following at the end of the command:
-c kamal/deploy.yml
For further details, refer to the Kamal Documentation or reach out to us on our Discord
Rollback to a Previous Version
kamal rollback [git_commit_hash_to_rollback_to] -c kamal/deploy.yml
View Formbricks Server logs with Kamal
kamal app logs -c kamal/deploy.yml
Configure Memory Metrics on AWS using CW Agent
- Install the CloudWatch Agent on the EC2 instance
wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
-
Attach the IAM role of
CloudWatchFullAccessv2to the EC2 instance -
Edit the CloudWatch Agent config file
sudo nano /opt/aws/amazon-cloudwatch-agent/bin/config.json
- Add the below config to the
config.jsonfile
{
"metrics": {
"metrics_collected": {
"mem": {
"measurement": ["mem_used_percent"],
"metrics_collection_interval": 60
}
},
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
}
}
}
- Fetch the config & start the CloudWatch Agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s
- Now go to Cloudwatch > Metrics > All Metrics > Custom Namespaces > CWAgent > InstanceId > {InstanceId} > Tick the Checkbox next to it > Graph above will be updated