My rails 5 build for the past day started to run slow inside the docker build. This only happens on TravisCI.
Here are the steps:
- Install latest Ruby with RVM
- Update gem and install bundler
- Bundle install (takes less than a minute)
- Run the tests
- If they pass, build the docker image to send to AWS
- Docker image tries to bundle install (takes 15 minutes or so)
I keep seeing this message when the bundle install
is running inside the container:
Retrying download gem from https://rubygems.org/ due to error (2/4): Gem::RemoteFetcher::UnknownHostError timed out (https://rubygems.org/gems/crass-1.0.4.gem)
Here’s my .travis.yml
file:
sudo: required
language: ruby
rvm: 2.6.3
services:
- postgresql
- docker
branches:
only:
- master
before_install:
- sudo /etc/init.d/postgresql stop
- sudo apt-get install postgresql-contrib-9.6
- gem update --system
- gem install bundler
before_script:
- RAILS_ENV=test bundle exec rake db:create
- RAILS_ENV=test bundle exec rake db:migrate
script:
- bundle exec rspec
after_success:
- pip install --user awscli
- export PATH=$PATH:/$HOME/.local/bin
- aws ecr create-repository --repository-name $REPO --region $AWS_REGION
- eval $(aws ecr get-login --region $AWS_REGION --no-include-email)
- docker build -t $REPO .
- docker tag $REPO:latest $AWS_ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
- docker push $AWS_ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO:latest
And here is my Dockerfile:
FROM ruby:2.6.3-alpine3.9
# Install required libraries and dependencies
RUN apk add --update --no-cache \
build-base \
git \
xz \
tzdata \
gcc \
libxml2-dev \
libxslt-dev \
imagemagick \
bash \
ca-certificates \
postgresql-dev
RUN cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime
RUN echo "America/Sao_Paulo" > /etc/timezone
RUN update-ca-certificates
ARG bundle_options_var='--without development test'
ENV APP_ROOT /app
RUN mkdir $APP_ROOT
WORKDIR $APP_ROOT
COPY Gemfile $APP_ROOT/Gemfile
COPY Gemfile.lock $APP_ROOT/Gemfile.lock
RUN gem install bundler
RUN bundle config --global frozen 1
RUN bundle install $bundle_options_var
COPY . $APP_ROOT
ENTRYPOINT ["bundle", "exec"]
CMD ["puma", "-C", "config/puma.rb"]