Frederic Henri
Frederic Henri

Reputation: 53783

Rails engine apps deployed with docker

We have a rails app developed with a few rails engine so it looks like

app/              <-- main app
app.json
Gemfile -> config/Gemfile
Gemfile.lock
api/              <-- this is an engine app
integrations/     <-- this is an engine app
other_engine_app/

everything works fine but now I am looking to deployed on docker using docker-compose

I created a simple Dockerfile

FROM ruby:2.3.1

RUN apt-get update -qq && apt-get install -y apt-utils build-essential nodejs 

ENV APP_HOME /myapp
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile Gemfile.lock $APP_HOME/

RUN gem install bundler
RUN bundle install

ADD . $APP_HOME

The docker-compose.yml file is looking like

app:
  build: .
  volumes:
    - .:/myapp
  ports:
    - "3000:3000"
  links:
    - db
    - redis

db:
  image: mysql:5.6

redis:
  image: redis

At this stage when I run docker-compose up I get

$ docker-compose up
Building app
Step 1/10 : FROM ruby:2.3.1
.....
Step 9/10 : RUN bundle install
 ---> Running in 3748ba73eb9b
The path `/myapp/api` does not exist.
ERROR: Service 'app' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 13

I can bypass this error by adding the Gemfile into each engine app from my Dockerfile as

FROM ruby:2.3.1

RUN apt-get update -qq && apt-get install -y apt-utils build-essential nodejs

ENV APP_HOME /myapp
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile Gemfile.lock $APP_HOME/
ADD Gemfile Gemfile.lock $APP_HOME/api/
ADD Gemfile Gemfile.lock $APP_HOME/integrations/
ADD Gemfile Gemfile.lock $APP_HOME/other_engine_app/

RUN gem install bundler
RUN bundle install

ADD . $APP_HOME

but now I get the following error

$ docker-compose up
Building app
Step 1/10 : FROM ruby:2.3.1
.......
Step 12/13 : RUN bundle install
 ---> Running in 3928848ed6e5
Fetching https://github.com/rails-api/active_model_serializers
Fetching https://github.com/activeadmin/activeadmin
Fetching gem metadata from https://rails-assets.org/..
Fetching version metadata from https://rails-assets.org/.
Fetching gem metadata from https://rails-assets.org/..
Fetching gem metadata from http://rubygems.org/..........
Fetching version metadata from https://rails-assets.org/..
Fetching version metadata from http://rubygems.org/...
Fetching dependency metadata from https://rails-assets.org/..
Fetching dependency metadata from http://rubygems.org/..
Could not find gem 'api' in source at `api`.
Source does not contain any versions of 'api'
ERROR: Service 'app' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 7

EDIT :

Thanks to gwcodes, I can move forward but still hit an issue

The main Gemfile has dependency defined on the rails engine as

source 'http://rubygems.org'

ruby '2.3.1'

gem 'dotenv-rails', require: 'dotenv/rails-now'

# Engines.
gem 'api', path: 'api/'
gem 'integrations', path: 'integrations'
gem 'other_engine_app', path: 'other_engine_app'

....

in api/ folder we have gemspec defined as `api.gemspec``

$:.push File.expand_path('../lib', __FILE__)

require 'api/version'

Gem::Specification.new do |s|
  s.name        = 'api'
  s.version     = Api::VERSION
  s.authors     = ...
  s.email       = ...
  s.homepage    = ...
  s.summary     = ...

  s.files = Dir['{app,config,lib}/**/*'] + ['Rakefile']

  s.add_dependency 'rails'
  s.add_dependency 'workflow'
  s.add_dependency 'will_paginate'
  s.add_dependency 'analytics-ruby'
end

I have added the gemspec file from the Dockerfile as

FROM ruby:2.3.1

RUN apt-get update -qq && apt-get install -y apt-utils build-essential nodejs

ENV APP_HOME /myapp
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile Gemfile.lock $APP_HOME/
ADD Gemfile Gemfile.lock $APP_HOME/api/
ADD api/api.gemspec $APP_HOME/api/
ADD Gemfile Gemfile.lock $APP_HOME/integrations/
ADD Gemfile Gemfile.lock $APP_HOME/other_engine_app/

RUN gem install bundler
RUN bundle install

ADD . $APP_HOME

and so I get the following error

Step 13/14 : RUN bundle install
 ---> Running in c7fce6cd25d8

[!] There was an error while loading `api.gemspec`: cannot load such file -- api/version
Does it try to require a relative path? That's been removed in Ruby 1.9. Bundler cannot continue.

 #  from /myapp/api/api.gemspec:3
 #  -------------------------------------------
 #
 >  require 'api/version'
 #
 #  -------------------------------------------
ERROR: Service 'app' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 14

Upvotes: 1

Views: 1505

Answers (1)

gwcodes
gwcodes

Reputation: 5690

How are the engines loaded? Do you have a line that looks like this in the Gemfile of the main application:

gem 'api', path: '/api'

If so, you may also need to copy across the .gemspec files.

Upvotes: 2

Related Questions