KhiemNS KhiemNS - 2 months ago 6x
Ruby Question

prevent google app engine reinstall lib

I'm deploying a rails application using Google App Engine and it takes a lot of time to reinstall libraries like rbenv, ruby,...

Is there anyway to prevent this, I just want to install new library only


Yeah... we're actively working on making this faster. In the interim, here's how you can make it faster. At the end of the day - all we're really doing with App Engine Flex is creating a Dockerfile for you, and then doing a docker build. With Ruby, we try to play some fancy tricks like letting you tell us what version of rbenv or ruby you want to run. If you're fine hard coding all of that, you can just use our base image.

To do that, first open the terminal and cd into the dir with your code. Then run:

gcloud beta app gen-config --custom

Follow along with the prompts. This is going to create a Dockerfile in your CWD. Go ahead and edit that file, and check out what it's doing. In the simplest form, you can delete most of it and end up with something like this:

COPY . /app/
RUN  bundle install --deployment && rbenv rehash;
ENV RACK_ENV=production \
    RAILS_ENV=production \
RUN if test -d app/assets -a -f config/application.rb; then \
    bundle exec rake assets:precompile; \
CMD bundle exec rackup -p $PORT

Most of the heavy lifting is already done in, so you can just essentially add your code, perform any gem installs you need, and then set the entrypoint. You could also fork our base docker image and create your own. After you have this file, you should do a build to test it:

docker build -t myapp .

Now go ahead and run it, just to make sure:

docker run -it -p 8080:8080 myapp

Visit http://localhost:8080 to make sure it's all looking good. Now when you run glcoud app deploy the next time, we're going to use this Dockerfile. Should be much, much faster.

Hope this helps!