kamal icon indicating copy to clipboard operation
kamal copied to clipboard

kamal deploy failed

Open dashingspidy opened this issue 1 year ago • 1 comments

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

dashingspidy avatar Aug 08 '24 02:08 dashingspidy

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

kobaltz avatar Aug 10 '24 13:08 kobaltz

I and others have found that deploy doesn't work with Ruby 3.3. Try downgrading to 3.2.4.

srbaker avatar Sep 05 '24 18:09 srbaker

Haven't had any issues with 3.3, the speed and memory improvements are very worth it.

What issues were you having?

Cluster444 avatar Sep 11 '24 20:09 Cluster444

I was wrong. Different error than this one, sorry. It hangs indefinitely without any output when I upgrade to 3.3

srbaker avatar Sep 12 '24 10:09 srbaker

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

byellokore avatar Oct 01 '24 04:10 byellokore

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.

dhh avatar Oct 01 '24 04:10 dhh

It was late, and I forgot to post a complete message. Sorry. @dhh

The directories are there.

Screenshot 2024-10-01 at 08 11 45
  • 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.

byellokore avatar Oct 01 '24 12:10 byellokore

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.

dhh avatar Oct 01 '24 16:10 dhh

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.

Cluster444 avatar Oct 01 '24 17:10 Cluster444

@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.

jespr avatar Oct 10 '24 03:10 jespr

@dashingspidy Something is up with kamal here. I fixed it by : rm -rf storage git add . git commit -m "remove storage"

git add . git commit -m "adding folder back"

santy18 avatar Nov 25 '24 03:11 santy18

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.

eric-eye avatar Dec 09 '24 19:12 eric-eye