Dockerized Rails找不到从git源安装的gem

时间:2018-12-07 14:54:53

标签: ruby-on-rails docker bundler

启动容器时,我得到:

$ docker-compose up
Starting shadowcal_postgres_1 ... done
Recreating myapp_app_1    ... done
Attaching to myapp_postgres_1, myapp_app_1
postgres_1  | LOG:  database system was interrupted; last known up at 2018-12-07 14:38:22 UTC
postgres_1  | LOG:  database system was not properly shut down; automatic recovery in progress
postgres_1  | LOG:  invalid record length at 0/17046D0
postgres_1  | LOG:  redo is not required
postgres_1  | LOG:  MultiXact member wraparound protections are now enabled
postgres_1  | LOG:  autovacuum launcher started
postgres_1  | LOG:  database system is ready to accept connections
app_1       | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git/git_proxy.rb:235:in `allowed_in_path': The git source https://github.com/jfeldstein/ruby_outlook is not yet checked out. Please run `bundle install` before trying to start your application (Bundler::GitError)
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git/git_proxy.rb:192:in `find_local_revision'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git/git_proxy.rb:64:in `revision'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git.rb:225:in `revision'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git.rb:93:in `install_path'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/path.rb:126:in `expanded_path'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/path.rb:163:in `load_spec_files'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git.rb:200:in `load_spec_files'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/path.rb:100:in `local_specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/source/git.rb:167:in `specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:754:in `block in converge_locked_specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:740:in `each'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:740:in `converge_locked_specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:248:in `resolve'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:171:in `specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:238:in `specs_for'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/definition.rb:227:in `requested_specs'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/runtime.rb:108:in `block in definition_method'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/runtime.rb:20:in `setup'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler.rb:107:in `setup'
app_1       |   from /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.3/lib/bundler/setup.rb:20:in `<top (required)>'
app_1       |   from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
app_1       |   from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
myapp_app_1 exited with code 1

我尝试过

  • 将ENTRYPOINT设置为["bundle", "exec"]
  • 向CMD本身添加bundle exec
  • docker-compose build --no-cache --force-rm
  • 安装后在Dockerfile中添加RUN bundle package --all --app-dir=vendor/cache

不高兴。

docker-compose.yml

version: '3'

volumes:
  app:

services:
  postgres:
    image: postgres:9.5
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
    ports:
      - '5432:5432'
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
      - ".:${APP_PATH}"

  app:
    build: 
      context: .
      args:
        - 'PORT=$PORT'
        - 'RACK_ENV=$RACK_ENV'
        - 'APP_PATH=$APP_PATH'
    links:
      - postgres
    volumes:
      - ".:${APP_PATH}"
    ports:
      - "${PORT}:${PORT}"
    env_file: .env

Gemfile

# frozen_string_literal: true

ruby "2.5.1"

source "https://rubygems.org"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "4.2.10"

group :development do
  gem "rb-readline"
end

gem "pg", '~>0.20.0'

gem "rails_12factor", group: :production

# Use SCSS for stylesheets
gem "sass-rails"

# Use Uglifier as compressor for JavaScript assets
gem "uglifier", ">= 1.3.0"

# Use CoffeeScript for .js.coffee assets and views
gem "coffee-rails", "~> 4.0.0"

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem "jquery-rails"
# With Underscore support
gem "underscore-rails"

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem "turbolinks"

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 1.2"
gem "json", "~> 2.1"

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem "sdoc", require: false
end

group :test do
  gem "mocha"
end

group :development, :test do
  gem "factory_bot_rails", "~> 4.0"

  gem "capybara"
  gem "capybara-screenshot"
  gem "database_cleaner"
  gem "rspec-rails"

  gem "better_errors"
  gem "binding_of_caller"
  gem "faker"

  gem "rspec_junit_formatter"

  gem "webmock"

  gem 'guard-rspec', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

gem "delayed_job_active_record"

gem "devise"
gem "omniauth"
gem "omniauth-google-oauth2"
gem "omniauth-microsoft-office365"
gem "ruby_outlook", git: 'https://github.com/jfeldstein/ruby_outlook', branch: :master

gem "execjs"
gem "haml-rails"
gem "haml_coffee_assets"

gem "bootstrap", "~> 4.1.2"
gem "sprockets-rails", ">= 2.3.2"
gem 'sprockets', '~> 3.7.2'

gem "make_resourceful"

gem "has-bit-field"

gem "rollbar"

gem "oj"
gem "rabl"

# Paperclip with the aws sdk
gem "aws-sdk"
gem "paperclip", "~> 5.2.0"

gem "backbone-rails"
gem "chosen-rails"
gem "fancybox2-rails", "~> 0.2.4"
gem "font-awesome-rails"
gem "rails_config"

gem "rqrcode"

gem "quiet_assets"

gem "google-api-client", require: "google/apis/calendar_v3"

gem "rubocop", require: false

Dockerfile

# Use the barebones version of Ruby 2.2.3.
FROM starefossen/ruby-node:2-8-slim

# Optionally set a maintainer name to let people know who made this image.
MAINTAINER Jordan Feldstein <jfeldstein@gmail.com>

# Install binary dependencies:
# - build-essential: To ensure certain gems can be compiled
# - nodejs: Compile assets
# - libpq-dev: Communicate with postgres through the postgres gem
# - postgresql-client-9.4: In case you want to talk directly to postgres
RUN apt-get update && apt-get install -qq -y \
    build-essential \
    curl \
    libpq-dev \
    git \
    tzdata \
    --fix-missing

# CONFIG
ARG PORT
ARG RACK_ENV
ARG APP_PATH

# App
RUN mkdir -p $APP_PATH
COPY ./Gemfile $APP_PATH
WORKDIR $APP_PATH
RUN bundle install

COPY . .
# VOLUME ["$APP_PATH/public"]

ENTRYPOINT ["bundle", "exec"]

RUN bundle exec rake RAILS_ENV=$RACK_ENV DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=f098CY897WS4FT9J8A0VW378AIOCUWRSYFWBO39N8Y assets:precompile
CMD bundle exec rails server -p $PORT -e $RACK_ENV

0 个答案:

没有答案