Deploy using Kamal
Deploying with Kamal is the prefer approach when deploying TinyPixel.
# Prerequisites
- You have Ruby and Kamal installed.
- You have a Linux server available that you can SSH into, possibly using DigitalOcean.
- A domain name, or subdomain, with an
Arecord set with your server’s IP. -
A GitHub login and personal access token for authenticating with the container registry.
This is currently a requirement of Kamal, which is mainly intended for deploying proprietary applications. The TinyPixel container image is publicly available, and we’re hoping Kamal will soon support deploying public images so end users do not need to log in to the registry.
# Deployment Steps
- On your server, we’ll need to need to create a user with UID
1000, if one does not already exist:adduser --uid 1000 rails --disabled-password - Create a directory owned by UID
1000for storing the SQLite database filesmkdir /home/rails/tiny_pixel chown rails:rails /home/rails/tiny_pixel -
On your local machine, create a Kamal
config.ymlto use for deplyoing:service: tiny_pixel image: ghcr.io/mjc-gh/tiny_pixel servers: web: hosts: - __REPLACE_WITH_SERVER_IP__ workers: hosts: - __REPLACE_WITH_SERVER_IP__ cmd: ./bin/jobs registry: server: ghcr.io username: - KAMAL_REGISTRY_USERNAME password: - KAMAL_REGISTRY_PASSWORD volumes: - "/home/rails/tiny_pixel:/rails/storage" builder: arch: amd64 env: clear: TP_DOMAIN_NAME: __REPLACE_WITH_DOMAIN_NAME__ secret: - RAILS_SECRET_KEY_BASE proxy: hosts: - __REPLACE_WITH_DOMAIN_NAME__ ssl: trueThere are two locations in the
serverssection where you will need to fill in the IP address of your server. You will also need to change the domain in theenv.clearandproxysections.If you are using a different location for storing SQLite database files other than
/home/rails/tiny_pixel, you will need to edit thevolumessection. - Create a
.kamal/secretsfile using the following template and fill in the values:KAMAL_REGISTRY_USERNAME= KAMAL_REGISTRY_PASSWORD= RAILS_SECRET_KEY_BASE=For the
RAILS_SECRET_KEY_BASE, we will need a random value that is sufficiently secure. The simplest way to generate a value is to run:openssl rand -hex 64 - Run Kamal to setup your server and deploy TinyPixel
kamal setup --config-file config.yml --skip-push --version v0.0.1 kamal deploy --config-file config.yml --skip-push --version v0.0.1 - Login to the system admin using the link
generated from running:
kamal app exec --config-file config.yml -i --reuse --version v0.0.1 "bin/rails tiny_pixel:system_admin_password"
Within the system admin, you can create a new login for your TinyPixel instance. Once logged in to the application, you can create new sites, configure them, and add teammates.
# Tips
- Use block storage on your cloud provider to make backups easy. With Digital Ocean, you can attach a small volume block storage and store SQLite data there.