On Monday, February 3, 2020 at 1:41:45 PM UTC+13, Simon Russell wrote:
>
> How often is your gemfile changing?
>
>
It's not that the gemfile is changing it's that Gemfile.lock is changing
because we have gems we are pulling from git.
> One approach I've used in the past is copying just the gemfile (and
> related stuff) in and creating that as a layer. Then copy the rest of the
> project in later.
>
That's what I am doing but I am doing it in two phases like this.
COPY package.json yarn.lock /app/
RUN yarn install
# This is done to speed up CI builds. The base gem file should not be changing
a lot so this will cache the whole thing
COPY Gemfile_base.rb /app/
#
## Install the builder gems, don't clean out the cache and delete the gemfile
for the next step.
RUN bundle config path \
&& bundle install --gemfile Gemfile_base.rb
# Install gems
COPY Gemfile /app/
COPY Gemfile.lock /app/
RUN bundle config path \
&& bundle config --global frozen 1 \
&& bundle install --gemfile Gemfile \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf $BUNDLE_PATH/cache/ \
&& find $BUNDLE_PATH/gems/ -name "*.c" -delete \
&& find $BUNDLE_PATH/gems/ -name "*.o" -delete
The Gemfile has this in it
#The last argument to eval makes exceptions in Gemfile.devel show up with the
correct filename.
eval File.read('Gemfile_base.rb'), nil, 'Gemfile_base'
This allows me add the base gems as one layer and the second bundle install
uses the already installed gems from the base layer so it goes faster.
This allows all my gems to be defined in the same project (no base layer to
pull from) but it's split into two files so that's not ideal.
> Also I use dockerignore basically in reverse to whitelist just the stuff
> that I want in there; not for size purposes (mainly) but so that it doesn't
> recreate layers when nothing important has changed.
>
I have a pretty robust dockerignore (I can post it if you want) but the
build still take a long time and as I said the docker image is HUGE 1.2
gigs. I did a three stage docker build once and got the image to just a
hair under 600 megs but that still seems insanely large for a rails app.
What about the asset precompilation? Can I skip that if I have done a yarn
install? how about visa versa? Can I skip the yarn install if I do a asset
precompile? Is there another way to avoid a database connection when I am
doing asset precompile than using the nulldb adapter?
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rails-oceania/8199ccee-47d9-4d31-b48d-2827e6b9fc21%40googlegroups.com.