kamal deploy failed
Ruby: 3.3.4 Rails: 7.1.3.4 Kamal: 1.8.1
I'm able to build using docker build command on local machine. only deploying using kamal gets error. I did test using newly generated app. By removing "log" and "storage" from dockerfile, i can deploy sucessfully.
#19 [stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash && chown -R rails:rails db log storage tmp
#19 0.215 chown: cannot access 'log': No such file or directory
#19 0.215 chown: cannot access 'storage': No such file or directory
#19 ERROR: process "/bin/sh -c useradd rails --create-home --shell /bin/bash && chown -R rails:rails db log storage tmp" did not complete successfully: exit code: 1
------
> [stage-2 4/4] RUN useradd rails --create-home --shell /bin/bash && chown -R rails:rails db log storage tmp:
0.215 chown: cannot access 'log': No such file or directory
0.215 chown: cannot access 'storage': No such file or directory
------
if anyone have temporary fix for it, please let me know. Thanks
add log/ and storage/ folders in your app. Make sure that the .dockerignore doesn't exclude those folders, but just their content.
For example, your .dockerignore should have something like
# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/.keep
# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/.keep
I and others have found that deploy doesn't work with Ruby 3.3. Try downgrading to 3.2.4.
Haven't had any issues with 3.3, the speed and memory improvements are very worth it.
What issues were you having?
I was wrong. Different error than this one, sorry. It hangs indefinitely without any output when I upgrade to 3.3
main branch, new app. Same error:
[stage-2 4/4] RUN groupadd --system --gid 1000 rails && useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && mkdir /data && chown -R 1000:1000 db log storage tmp /data: cannot access 'log': No such file or directory 0.139 chown: cannot access 'storage': No such file or directory
All the information is in the message! You don't have a log or a storage directory. Probably because you removed the .keep files. Add them back and you should be good to go. Or, if you know what you're doing, remove those directories from the command.
It was late, and I forgot to post a complete message. Sorry. @dhh
The directories are there.
- Directories are there.
It looks like even if I try to remove this line from the Dockerfile, I'm still getting the error, so I will suppose that this is probably related to some kind of cache somewhere. I tried to build the image locally, like the other comment here, and the image built correctly without any errors.
# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
- Rails main
- Ruby 3.3.0
I will keep trying. This is the first time that I am trying to use Kamal. Thanks in advance.
Directories are there locally, but maybe they're not there in your Dockerfile, because they're not there in git, because they're empty. That sounds most likely. You can also build the docker container locally and then inspect it to see if it matches what you think it should.
Dive is a good tool for seeing precisely what is happening in your image.
https://github.com/wagoodman/dive
Make sure they're not .dockerignore'd either.
@dashingspidy @byellokore I ran into this issue too, and took me a little to debug.
First of all, make sure that log/ is committed to git as DHH said. If it's not, it's probably because you have a global .gitignore file with log/ in it. That turned out to be my issue.
In my ~/.gitconfig I had:
[core]
excludesfile = /Users/jespr/.gitignore
and that .gitignore excluded the log/ directory and that appears to win over whatever you have in your rails app directory.
@dashingspidy Something is up with kamal here. I fixed it by :
I ran into this, and all .keep files were not included even though they were not gitignored anywhere on my machine, so somehow my repo entered this state without me realizing. But I confirmed this works as expected when committing after rails new, so I don't think there's an issue to report here.
If you find yourself in this situation, you could fix the individual .keep files with git add -f
The local builder will git clone the repo locally and build from that location. If you want to inspect the exact filesystem used to build, check that folder (may be generated in /var by default) -- since this is git cloned over, it might be different than the filesystem you'd get if you built the docker image from your project folder.