slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)
Apache License 2.0
19.5k stars 732 forks source link

Ruby app CMD cannot find bundler #112

Open axcdnt opened 4 years ago

axcdnt commented 4 years ago

I have a Ruby app based on ruby:2.5.3-alpine with a CMD that cannot find bundler.

It's being built as:

docker-slim build --http-probe --include-shell --include-exe sleep --include-exe grep --include-exe jq --include-exe /usr/local/bin/bundle myapp

CMD:

CMD ["./scripts/server.sh"]

server.sh:

#!/bin/sh

# Starting puma server
bundle exec puma -C config/puma.rb

I'm not sure if --include-exe pointing to bundler's absolute path is correct. I also tried --include-bin without success.

When running docker-compose pointing to my-app.slim, it raises the following error:

my-app | ./scripts/server.sh: line 4: bundle: not found

Client: Docker Engine - Community
 Version:           19.03.4
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        9013bf5
 Built:             Thu Oct 17 23:44:48 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Let me know if you have any idea. Thanks in advance!

kcq commented 4 years ago

Sorry for the headaches @axcdnt ! You shouldn't need to explicitly include the bundle binary using the --include-exe flag. Is there a difference if you try to use the standard (non-alpine base image for ruby (like in this example: https://github.com/docker-slim/examples/tree/master/ruby2_rails5_standard )?

Let me try to repro the condition to see what's going on...

sergey-koba-mobidev commented 4 years ago

You can do --include-path=/usr/local/bin/bundle, but then you will have a bunch of other problems with alpine. I gave up on

docker-slim build --include-shell --include-path=/usr/local/bin/bundle --include-path=/usr/local/lib/ruby --include-path=/usr/lib api_api:latest

It seems docker-slim and alpine are not working together well, right?

kcq commented 4 years ago

@sergey-koba-mobidev it should be working... are you experiencing a similar problem?

sergey-koba-mobidev commented 4 years ago

Yes, I am trying to docker-slim FROM ruby:2.6-alpine3.11 image and have the same problem

kcq commented 4 years ago

@sergey-koba-mobidev how does your Dockerfile look like? Does it look like this https://github.com/docker-slim/examples/blob/master/ruby2_rails5_standard/Dockerfile or do you have something special for the entrypoint/cmd?

sergey-koba-mobidev commented 4 years ago

Here it is:

FROM ruby:2.6-alpine3.11

ENV LANG C.UTF-8
ENV MAXMIND_DB_LOCATION /tmp/GeoLite2-City.mmdb

RUN mkdir -p /var/log/unicorn

RUN mkdir -p /usr/src/api
WORKDIR /usr/src/api

RUN apk add --update --upgrade gcc less postgresql-dev libsass imagemagick \
    git build-base xz-dev libc6-compat nodejs python python-dev \
    postgresql-client curl unzip linux-headers && \
    gem install libv8 -v '3.16.14.3' -- --with-system-v8 && \
    rm -rf /var/cache/apk/*

RUN apk add --no-cache gmp-dev

COPY . /usr/src/api

RUN bundle install --jobs 20

COPY assets/GeoLite2-City.mmdb /tmp/GeoLite2-City.mmdb

EXPOSE 3000
CMD ["unicorn_rails", "-c", "config/unicorn.conf.rb"]
kcq commented 4 years ago

@sergey-koba-mobidev thanks for sharing your Dockerfile! Working on a repro... I'll share my updates soon :)

kcq commented 4 years ago

a number of new Rails/Alpine examples:

still working on a rails/unicorn repro...

sergey-koba-mobidev commented 4 years ago

Thank you @kcq !

kcq commented 4 years ago

@sergey-koba-mobidev here's the latest rails/alpine example and it uses unicorn_rails to start the app: https://github.com/docker-slim/examples/blob/master/ruby2_rails5_alpine_unicorn_rails/Dockerfile

It looks like there's something else going on... I noticed that you install the libv8 gem and also nodejs. What do you have in your Gemfile and what are you doing with libv8 and nodejs there? Wonder if you use the execjs gem somehow too...