rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.13k stars 552 forks source link

Dockerize rails 6 #738

Closed tke578 closed 4 years ago

tke578 commented 4 years ago

Hi all,

I've been trying to Dockerize a rails 6 app and for some reason, when I run docker-compose up I get a error about a missing port from the Thor gem which I already specified. I'm curious if anybody ran into this issue. It runs successfully without docker.

db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | LOG:  database system was shut down at 2020-09-09 07:27:22 UTC
db_1   | LOG:  MultiXact member wraparound protections are now enabled
db_1   | LOG:  database system is ready to accept connections
db_1   | LOG:  autovacuum launcher started
web_1  | /usr/local/bundle/gems/thor-1.0.1/lib/thor/parser/options.rb:228:in `parse_peek': No value provided for option '--port' (Thor::MalformattedArgumentError)
from /usr/local/bundle/gems/thor-1.0.1/lib/thor/parser/options.rb:100:in `parse'
web_1  |    from /usr/local/bundle/gems/thor-1.0.1/lib/thor/base.rb:79:in `initialize'
web_1  |    from /usr/local/bundle/gems/thor-1.0.1/lib/thor/invocation.rb:26:in `initialize'
web_1  |    from /usr/local/bundle/gems/thor-1.0.1/lib/thor/shell.rb:45:in `initialize'
web_1  |    from /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:127:in `initialize'
web_1  |    from /usr/local/bundle/gems/thor-1.0.1/lib/thor.rb:388:in `new'
web_1  |    from /usr/local/bundle/gems/thor-1.0.1/lib/thor.rb:388:in `dispatch'
web_1  |    from /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/command/base.rb:69:in `perform'
web_1  |    from /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/command.rb:46:in `invoke'
web_1  |    from /usr/local/bundle/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |    from /usr/local/bundle/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
web_1  |    from /usr/local/bundle/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
web_1  |    from /usr/local/bundle/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
web_1  |    from /market-insights/bin/rails:9:in `<top (required)>'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
web_1  |    from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
web_1  |    from /market-insights/bin/spring:15:in `require'
web_1  |    from /market-insights/bin/spring:15:in `<top (required)>'
web_1  |    from bin/rails:3:in `load'
web_1  |    from bin/rails:3:in `<main>'

Dockerfile

FROM ruby:2.6.3

RUN bundle config --global frozen 1
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y build-essential nodejs yarn postgresql-client

RUN mkdir /market-insights

WORKDIR /market-insights

COPY Gemfile Gemfile.lock ./
RUN bundle install

COPY . /market-insights

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

version: '3'
services:
  db:
    image: postgres:9.5
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: market_insights_dev
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'; env"
    volumes:
      - .:/market-insights
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment:
      POSTGRES_HOST: db
      PGUSER: postgres
      PGPASSWORD: postgres
      RAILS_ENV: development

entrypoint.sh

#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /market-insights/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"
rafaelfranca commented 4 years ago

Thank you for the issue but I don't think this is a problem in the thor gem.