Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Script not Working in Linux Environment #106

Closed
micaza opened this issue Jul 9, 2021 · 9 comments
Closed

Deploy Script not Working in Linux Environment #106

micaza opened this issue Jul 9, 2021 · 9 comments

Comments

@micaza
Copy link

micaza commented Jul 9, 2021

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?

@Digoss
Copy link

Digoss commented Jul 10, 2021

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?

@metaskills
Copy link
Member

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
Copy link
Member

Is it possible this issue is fixed via this comment? #100 (comment)

@metaskills metaskills changed the title deploy script not working in Linux environment Deploy Script not Working in Linux Environment Aug 1, 2021
@Digoss
Copy link

Digoss commented Aug 1, 2021

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.

@ihouse10
Copy link

ihouse10 commented Aug 5, 2021

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
Copy link

ihouse10 commented Aug 5, 2021

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

@Digoss
Copy link

Digoss commented Aug 5, 2021

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.

@metaskills
Copy link
Member

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:

aws/aws-sam-cli#921 (comment)

@metaskills
Copy link
Member

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants