From e274463d7a0203fa255e994a0aef42ac0efb007c Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 2 Apr 2024 16:01:27 +0400 Subject: [PATCH] new debugger --- .dockerignore | 37 ----------------- .env.sample | 1 + .gitattributes | 9 ---- .gitignore | 3 +- .ruby-version | 1 - .vscode/launch.json | 8 ++-- .vscode/tasks.json | 19 --------- Dockerfile | 62 ---------------------------- Gemfile | 2 +- Procfile.dev | 4 +- app/controllers/scores_controller.rb | 2 +- bin/may_kill_dev.sh | 19 --------- config.ru | 2 +- config/database.yml | 4 +- 14 files changed, 12 insertions(+), 161 deletions(-) delete mode 100644 .dockerignore create mode 100644 .env.sample delete mode 100644 .gitattributes delete mode 100644 .ruby-version delete mode 100644 .vscode/tasks.json delete mode 100644 Dockerfile delete mode 100755 bin/may_kill_dev.sh diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 9612375..0000000 --- a/.dockerignore +++ /dev/null @@ -1,37 +0,0 @@ -# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. - -# Ignore git directory. -/.git/ - -# Ignore bundler config. -/.bundle - -# Ignore all environment files (except templates). -/.env* -!/.env*.erb - -# Ignore all default key files. -/config/master.key -/config/credentials/*.key - -# Ignore all logfiles and tempfiles. -/log/* -/tmp/* -!/log/.keep -!/tmp/.keep - -# Ignore pidfiles, but keep the directory. -/tmp/pids/* -!/tmp/pids/.keep - -# Ignore storage (uploaded files in development and any SQLite databases). -/storage/* -!/storage/.keep -/tmp/storage/* -!/tmp/storage/.keep - -# Ignore assets. -/node_modules/ -/app/assets/builds/* -!/app/assets/builds/.keep -/public/assets diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..73642ea --- /dev/null +++ b/.env.sample @@ -0,0 +1 @@ +RAILS_PORT=7500 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 8dc4323..0000000 --- a/.gitattributes +++ /dev/null @@ -1,9 +0,0 @@ -# See https://git-scm.com/docs/gitattributes for more about git attribute files. - -# Mark the database schema as having been generated. -db/schema.rb linguist-generated - -# Mark any vendored files as having been vendored. -vendor/* linguist-vendored -config/credentials/*.yml.enc diff=rails_credentials -config/credentials.yml.enc diff=rails_credentials diff --git a/.gitignore b/.gitignore index 9b66b15..a6d82bb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,7 @@ /.bundle # Ignore all environment files (except templates). -/.env* -!/.env*.erb +/.env # Ignore all logfiles and tempfiles. /log/* diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 7bde84d..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-3.1.2 diff --git a/.vscode/launch.json b/.vscode/launch.json index e72992e..56f1d3b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,11 +1,9 @@ { + "version": "0.2.0", "configurations": [ { "type": "ruby_lsp", - "name": "Debug Rails", - "request": "launch", - "preLaunchTask": "ASK_FOR_KILL_RAILS", - "program": "${workspaceFolder}/bin/rails server --port 3000 -b 127.0.0.1", + "request": "attach", + "name": "Attach to existing server", }, - ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 32295b3..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "tasks": [ - { - "type": "shell", - "label": "ASK_FOR_KILL_RAILS", - "command": "${workspaceFolder}/bin/may_kill_dev.sh", - "detail": "ASK before killing the currently running Rails server", - "presentation": { - "showReuseMessage": false, - "reveal": "always", - "close": true, - "panel": "dedicated", - "echo": false - } - } - - ], - "version": "2.0.0" -} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index aa19520..0000000 --- a/Dockerfile +++ /dev/null @@ -1,62 +0,0 @@ -# syntax = docker/dockerfile:1 - -# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile -ARG RUBY_VERSION=3.1.2 -FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base - -# Rails app lives here -WORKDIR /rails - -# Set production environment -ENV RAILS_ENV="production" \ - BUNDLE_DEPLOYMENT="1" \ - BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development" - - -# Throw-away build stage to reduce size of final image -FROM base as build - -# Install packages needed to build gems -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config - -# Install application gems -COPY Gemfile Gemfile.lock ./ -RUN bundle install && \ - rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ - bundle exec bootsnap precompile --gemfile - -# Copy application code -COPY . . - -# Precompile bootsnap code for faster boot times -RUN bundle exec bootsnap precompile app/ lib/ - -# Precompiling assets for production without requiring secret RAILS_MASTER_KEY -RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile - - -# Final stage for app image -FROM base - -# Install packages needed for deployment -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libvips postgresql-client && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives - -# Copy built artifacts: gems, application -COPY --from=build /usr/local/bundle /usr/local/bundle -COPY --from=build /rails /rails - -# Run and own only the runtime files as a non-root user for security -RUN useradd rails --create-home --shell /bin/bash && \ - chown -R rails:rails db log storage tmp -USER rails:rails - -# Entrypoint prepares the database. -ENTRYPOINT ["/rails/bin/docker-entrypoint"] - -# Start the server by default, this can be overwritten at runtime -EXPOSE 3000 -CMD ["./bin/rails", "server"] diff --git a/Gemfile b/Gemfile index 2d10add..d75c7cf 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,6 @@ group :development do gem 'error_highlight', '>= 0.4.0', platforms: [:ruby] - gem 'rainbow' gem 'rubocop', require: false gem 'rubocop-packaging' gem 'rubocop-performance' @@ -74,6 +73,7 @@ group :development do gem 'htmlbeautifier' gem 'rails_live_reload' gem 'rails_semantic_logger' + gem 'rainbow' end group :test do diff --git a/Procfile.dev b/Procfile.dev index 8716870..5eeb157 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,2 +1,2 @@ -web: env TERMINAL_PREFIX=15 bin/rails server --port 3000 -b 127.0.0.1 -css: bin/rake tailwindcss:watch +web: bundle exec rdbg -O -n -c -- rails server --port $RAILS_PORT +css: env BROWSERSLIST_IGNORE_OLD_DATA=true bundle exec -- rails tailwindcss:watch diff --git a/app/controllers/scores_controller.rb b/app/controllers/scores_controller.rb index 1c6ca2f..b691bcc 100644 --- a/app/controllers/scores_controller.rb +++ b/app/controllers/scores_controller.rb @@ -4,7 +4,7 @@ class ScoresController < ApplicationController # GET /scores def index - @scores = Score.all + @scores = Score.all logger.info 'this is a normal message' # logger.info({ one: 1, two: 2 }) # logger.info 'this is an information', { four: 4, five: 5 } diff --git a/bin/may_kill_dev.sh b/bin/may_kill_dev.sh deleted file mode 100755 index 2292236..0000000 --- a/bin/may_kill_dev.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -PORT=3000 - -pid_rails=$(ss -tlnp | grep "$PORT" | grep -oP "pid=\K(\d+)" | head -n1) -if [[ -n $pid_rails ]]; then - echo "============================================================================" - echo "Rails already runs on port $PORT, You've asked for debugger on the same port." - echo "============================================================================" - echo -n "Do you to want to kill rails process in order to launch debugger: (y/N)?: " - read -n1 answer - case $(echo $answer | tr '[A-Z]' '[a-z]') in - y|yes) kill -15 $pid_rails ;; - *) echo " means NO"; exit 1 ;; - esac -else - echo "port $PORT is free for debugger, go on..." -fi - diff --git a/config.ru b/config.ru index 4a3c09a..ad1fbf2 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,6 @@ # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/config/database.yml b/config/database.yml index 793f3a6..85c1f34 100644 --- a/config/database.yml +++ b/config/database.yml @@ -24,8 +24,8 @@ development: database: ruby-debug user: ruby-debug password: ruby-debug - host: ct1.lxd - + host: localhost + # The specified database role being used to connect to PostgreSQL. # To create additional roles in PostgreSQL see `$ createuser --help`. # When left blank, PostgreSQL will use the default role. This is