lamby icon indicating copy to clipboard operation
lamby copied to clipboard

Deploy Script not Working in Linux Environment

Open micaza opened this issue 4 years ago • 8 comments

I've been having success deploying just fine with the ./bin/deploy script in my Mac with docker and SAM Cli installed. However, I wanted to create a development environment in AWS Cloud 9 and all the scripts run fine for the exception of the deploy script. I started with the ./bin/bootstrap, then I did ./bin/setup and finally ./bin/deploy. The error that shows up is asking if docker is running when the step of running SAM build. I first try running this in an Ubuntu instance, but after a few failed tries I tried using Amazon Linux 2 instance on my cloud 9. Both OS failed the same way with the same error. I think the issue is that the deploy script runs SAM build that creates a docker image, but cannot find docker. I do not understand why is it working fine in the MacBook and I also had a coworker test these applications deploy in his Macbook and it works also (both computers are running different version of MacOS), but it only fails on a Linux instance (I did not try on a Windows).

I tried deleting the container by running docker system prune -a and running the ./bin/bootstrap script again and the same errors show.

Have you guys tested the Lamby cookie cutter applications in a Linux environment? Any ideas on what might be happening?

micaza avatar Jul 09 '21 02:07 micaza

I have the same issue and my brainless solution was to change the user in docker-compose.yml from lamby to root

The short version: the containers user doesn't have permission to access /var/run/docker.sock.

Long version: I have a default Ubuntu install. User and group share the same names and ids (uid and gid). e.g. x:x (1000:1000) I followed the Post-installation steps for Linux and I created a new group called docker and added my user into it. The Lamby docker image build uses my user and group IDs to create its own user/group. e.g. lamby:lamby When docker-compose mounts /var/run/docker.sock it uses the docker group ID that the lamby container user doesn't belong to. It causes the permission fault / Error: Building image for RailsLambda requires Docker. is Docker running?

Digoss avatar Jul 10 '21 00:07 Digoss

This is not expected. The cookiecutter is written to work on Linux as far as I can tell... mostly because we encourage GitHub Actions which is a Linux host. I just did a test with the latest and it all worked. See here for details.

https://github.com/metaskills/lambytest42/actions/runs/1020165380

Since this issue was created I did do a small change to the cookiecutter. Basically leveraging the SAM docker tag on the development/test/build image. This should not make a difference, but I did want to share. https://github.com/metaskills/lambytest42/actions/runs/1020165380

Can you create a test project from the latest cookiecutter and verify it works or does not? If it does not, what could be happening that deploy works for GitHub Ubuntu latest Linux vs others?

metaskills avatar Jul 11 '21 14:07 metaskills

Is it possible this issue is fixed via this comment? https://github.com/customink/lamby/issues/100#issuecomment-852242202

metaskills avatar Jul 17 '21 11:07 metaskills

I managed the issue changing the HOST_GID in the bootstrap script to store my system's Docker group identifier. Now I can to use the socket /var/run/docker.sock inside the container and run deploy script from my local environment.

Digoss avatar Aug 01 '21 23:08 Digoss

I also had success with changing the HOST_GID and HOST_UID. I changed the bootstrap script to also include to check for "Linux" in the if statement that sets HOST_GID and HOST_UID to 0.

if [ "$(uname -s)" = "Darwin" ] || [ "$(uname -s)" = "Linux" ]; then
  HOST_UID="0"
  HOST_GID="0"
fi

@metaskills This makes me wonder if we should change this indefinite without the if statement. Darwin is the MacOS I'm running it is working, and could this work for all other OS? Will this break in Github's Linux or Windows?

ihouse10 avatar Aug 05 '21 20:08 ihouse10

@Digoss Could you share your bootstrap script file? I would like to know how are you setting your system's Docker group identifier

ihouse10 avatar Aug 05 '21 23:08 ihouse10

I got the GID using the command getent group docker | cut -d: -f3

The build command looks like this:

docker-compose build \
  --build-arg HOST_UID="${HOST_UID:=$(id -u)}" \
  --build-arg HOST_GID="${HOST_GID:=$(getent group docker | cut -d: -f3)}"

Currently the image public.ecr.aws/sam/build-ruby2.7:1.27 contains a group named "input" that matches the "docker" group on my system.

Digoss avatar Aug 05 '21 23:08 Digoss

Getting kind of hard to write good cross compatible Docker code. I've been playing a lot with GitHub Codespaces and think I may have found an easier pattern for the dev container stuff we have been pushing. Some details here:

https://github.com/aws/aws-sam-cli/issues/921#issuecomment-907859353

metaskills avatar Sep 21 '21 19:09 metaskills

I recently refactored the Lamby Cookiecutter to simplify a great many things. Should help, especially the devcontainer stuff. Review here:

  • https://github.com/customink/lamby-cookiecutter/pull/21
  • https://github.com/customink/lamby-cookiecutter/commit/4945ed2ef3ccc276763aa43c32714bc4bb9251bc

Let me know if you have any questions. Docs coming soon on the new site.

metaskills avatar Dec 05 '22 12:12 metaskills