使用docker部署的Rails引擎应用程序

我们有一个轨道应用程序与几个轨道引擎开发,所以它看起来像

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/ 

一切工作正常,但现在我正在寻找部署在docker上使用docker组成

我创build了一个简单的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 

docker-compose.yml文件看起来像

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

在这个阶段,当我运行docker-compose up我得到了

 $ 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 

我可以通过从我的Dockerfile中将每个引擎应用程序添加Gemfile来绕过这个错误

 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 

但现在我得到以下错误

 $ 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 

编辑:

由于gwcodes,我可以前进,但仍然遇到一个问题

主要的Gemfile在rails引擎上具有依赖性

 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' .... 

api/文件夹中,我们将gemspec定义为`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 

我已经从Dockerfile添加了gemspec文件

 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 

所以我得到以下错误

 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 

引擎是如何加载的? 在主应用程序的Gemfile中是否有如下所示的行:

 gem 'api', path: '/api' 

如果是这样,您可能还需要复制.gemspec文件。