ruby-debug / ruby-debug-ide

An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and RubyMine.
https://www.jetbrains.com/ruby/features/ruby_debugger.html
Other
370 stars 83 forks source link

Cannot debug on VSCode and Docker #207

Closed FiloSpaTeam closed 3 years ago

FiloSpaTeam commented 3 years ago

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Rails",
      "type": "Ruby",
      "request": "attach",
      "remoteHost": "127.0.0.1",
      "remotePort": "1234",
      "remoteWorkspaceRoot": "/app",
      "cwd": "${workspaceRoot}",
      "showDebuggerOutput": true,
    } ,
    {
      "name": "Sidekiq",
      "type": "Ruby",
      "request": "attach",
      "remoteHost": "127.0.0.1",
      "remotePort": "1235",
      "remoteWorkspaceRoot": "/app",
      "cwd": "${workspaceRoot}",
      "showDebuggerOutput": true,
    }
  ]
}

Dockerfile

FROM ruby:2.6.6-alpine
ENV BUNDLER_VERSION=1.17.3

RUN apk add --update --no-cache \
      binutils-gold \
      build-base \
      curl \
      file \
      g++ \
      gcc \
      git \
      less \
      libstdc++ \
      libffi-dev \
      libc-dev \
      linux-headers \
      libxml2-dev \
      libxslt-dev \
      libgcrypt-dev \
      make \
      netcat-openbsd \
      nodejs \
      npm \
      openssl \
      pkgconfig \
      postgresql-dev \
      python3 \
      tzdata \
      yarn

RUN gem install bundler -v 1.17.3

WORKDIR /app

COPY Gemfile Gemfile.lock ./

RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install

COPY package.json yarn.lock ./

RUN yarn install --check-files

COPY . ./

EXPOSE 3000
EXPOSE 1234
EXPOSE 1235
EXPOSE 26162
EXPOSE 26163

docker-composer.yml

version: '3.4'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    command: bundle exec rdebug-ide --debug --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b 0.0.0.1
    user: ${CURRENT_UID}
    depends_on:
      - database
      - redis
    ports:
      - "1234:1234"
      - "26162:26162"
      - "3000:3000"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development
    deploy:
      resources:
        limits:
          memory: 1G
  database:
    image: postgres:12.1
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"
  redis:
    image: redis:5.0.7
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
  sidekiq:
    build:
      context: .
      dockerfile: Dockerfile
    command: bundle exec rdebug-ide --debug --host 0.0.0.0 --port 1235 --dispatcher-port 26163 -- bin/bundle exec sidekiq
    user: ${CURRENT_UID}
    depends_on:
      - app
      - database
      - redis
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development
    # entrypoint: ./entrypoints/sidekiq-entrypoint.sh
    deploy:
      replicas: 1
      mode: replicated
      resources:
        limits:
          memory: 500M
    ports:
      - "1235:1235"
      - "26163:26163"
volumes:
  gem_cache:
  db_data:
  node_modules:
  redis-data:
FiloSpaTeam commented 3 years ago

There is something strange, when i launch docker with docker-compose up -d, i see spawn message about debug but nothing about Rails server, later i connect VSCode and rails server starts working.

But nothing is shown inside VSCode, no breakpoints is working... what i'm missing?

FiloSpaTeam commented 3 years ago

Ok now seems working.

What i changed: