Kamal2 deploy of v8.0.0 app with SQlite to Hetzner resets volume on every deploy

Hi everyone :wave:

I’ve followed the Rails 8 The Demo video to spin up a fresh rails app, and tried deploying it to Hetzner using Kamal2 with the following config/deploy.yml

Everything works fine, it connects via ssh to my Hetzner server and deploys the current commit tag.

Also, it successfully persists on DB (using sqlite3). For instance, when I create a Post.

However despite the fact that I’ve configured a separate volume there (I bought a volume on the same zone and mounted it in my server), every time I deploy it, the storage uses a brand new sqlite file.

I tried redeploying an old version, and voilá, the data is there. I’m confused about this behavior and I’d much appreciate some thoughts on what’s happening and how should I fix my mistakes.

Thank you :cowboy_hat_face:

service: blog
image: caioabe/blog
servers:
  web:
    - 5.161.243.148
proxy:
  false
registry:
  username: caioabe
  password:
    - KAMAL_REGISTRY_PASSWORD
env:
  secret:
    - RAILS_MASTER_KEY
  clear:
    SOLID_QUEUE_IN_PUMA: true
    RAILS_LOG_LEVEL: debug
aliases:
  console: app exec --interactive --reuse "bin/rails console"
  shell: app exec --interactive --reuse "bash"
  logs: app logs -f
  dbc: app exec --interactive --reuse "bin/rails dbconsole"
volumes:
  - "blog_storage:/mnt/volume-ash-1"
asset_path: /rails/public/assets
builder:
  arch: amd64
1 Like

Hey @caioabe I might be wrong but you could give it a shot. I think the volume directive could be the other way around

volumes:
  - "/mnt/volume-ash-1:blog_storage"

Where blog_storage is the directory in your container where the data is being stored. I’m just thinking about how it works in Docker Compose

1 Like

Tysm @XSkinner , that makes sense. I could successfully make it work with your tip.

The only missing part is that I had to ssh into my server like this:

ssh root@5.161.243.148

Then I had to grant permissions for the mounted volume to the rails user of id 1000 and write permissions.

chown 1000 /mnt/volume-ash-1
chmod u+w /mnt/volume-ash-1
1 Like

BTW, if anyone interested, here’s the working repo:

2 Likes