Browse Source

new debugger

pagy
pvincent 8 months ago
parent
commit
e274463d7a
  1. 37
      .dockerignore
  2. 1
      .env.sample
  3. 9
      .gitattributes
  4. 3
      .gitignore
  5. 1
      .ruby-version
  6. 8
      .vscode/launch.json
  7. 19
      .vscode/tasks.json
  8. 62
      Dockerfile
  9. 2
      Gemfile
  10. 4
      Procfile.dev
  11. 19
      bin/may_kill_dev.sh
  12. 2
      config.ru
  13. 2
      config/database.yml

37
.dockerignore

@ -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

1
.env.sample

@ -0,0 +1 @@
RAILS_PORT=7500

9
.gitattributes

@ -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

3
.gitignore

@ -8,8 +8,7 @@
/.bundle /.bundle
# Ignore all environment files (except templates). # Ignore all environment files (except templates).
/.env*
!/.env*.erb
/.env
# Ignore all logfiles and tempfiles. # Ignore all logfiles and tempfiles.
/log/* /log/*

1
.ruby-version

@ -1 +0,0 @@
ruby-3.1.2

8
.vscode/launch.json

@ -1,11 +1,9 @@
{ {
"version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "ruby_lsp", "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",
}, },
]
} }

19
.vscode/tasks.json

@ -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"
}

62
Dockerfile

@ -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"]

2
Gemfile

@ -61,7 +61,6 @@ group :development do
gem 'error_highlight', '>= 0.4.0', platforms: [:ruby] gem 'error_highlight', '>= 0.4.0', platforms: [:ruby]
gem 'rainbow'
gem 'rubocop', require: false gem 'rubocop', require: false
gem 'rubocop-packaging' gem 'rubocop-packaging'
gem 'rubocop-performance' gem 'rubocop-performance'
@ -74,6 +73,7 @@ group :development do
gem 'htmlbeautifier' gem 'htmlbeautifier'
gem 'rails_live_reload' gem 'rails_live_reload'
gem 'rails_semantic_logger' gem 'rails_semantic_logger'
gem 'rainbow'
end end
group :test do group :test do

4
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

19
bin/may_kill_dev.sh

@ -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

2
config.ru

@ -1,6 +1,6 @@
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require_relative "config/environment"
require_relative 'config/environment'
run Rails.application run Rails.application
Rails.application.load_server Rails.application.load_server

2
config/database.yml

@ -24,7 +24,7 @@ development:
database: ruby-debug database: ruby-debug
user: ruby-debug user: ruby-debug
password: ruby-debug password: ruby-debug
host: ct1.lxd
host: localhost
# The specified database role being used to connect to PostgreSQL. # The specified database role being used to connect to PostgreSQL.
# To create additional roles in PostgreSQL see `$ createuser --help`. # To create additional roles in PostgreSQL see `$ createuser --help`.

Loading…
Cancel
Save