From 173343034104d2f725d2c06abd2edccb6c95c3eb Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Thu, 15 Jan 2026 12:26:30 +0630 Subject: [PATCH] Initial Rails test app --- .gitignore | 6 + Dockerfile | 18 ++ Gemfile | 12 + Gemfile.lock | 244 ++++++++++++++++++ Rakefile | 2 + app/controllers/application_controller.rb | 2 + app/controllers/home_controller.rb | 19 ++ app/views/home/index.html.erb | 20 ++ app/views/layouts/application.html.erb | 19 ++ config.ru | 4 + config/application.rb | 11 + config/boot.rb | 3 + config/database.yml | 20 ++ config/environment.rb | 2 + config/environments/production.rb | 16 ++ .../initializers/filter_parameter_logging.rb | 1 + config/puma.rb | 13 + config/routes.rb | 4 + config/secrets.yml | 2 + 19 files changed, 418 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/home_controller.rb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/layouts/application.html.erb create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/production.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/secrets.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8c6fce --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.log +tmp/ +.bundle +vendor/bundle +node_modules/ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6ee5336 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ruby:3.2-slim + +RUN apt-get update -qq && \ + apt-get install -y build-essential libmariadb-dev git curl && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY Gemfile Gemfile.lock ./ +RUN bundle install + +COPY . . + +RUN bundle exec rails assets:precompile 2>/dev/null || true + +EXPOSE 3000 + +CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4a50053 --- /dev/null +++ b/Gemfile @@ -0,0 +1,12 @@ +source 'https://rubygems.org' + +ruby '3.2.0' + +gem 'rails', '~> 7.1.0' +gem 'mysql2', '~> 0.5' +gem 'puma', '~> 6.0' +gem 'bootsnap', require: false + +group :development, :test do + gem 'debug', platforms: %i[mri windows] +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d1ea998 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,244 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.1.6) + actionpack (= 7.1.6) + activesupport (= 7.1.6) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.6) + actionpack (= 7.1.6) + activejob (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.6) + actionpack (= 7.1.6) + actionview (= 7.1.6) + activejob (= 7.1.6) + activesupport (= 7.1.6) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.6) + actionview (= 7.1.6) + activesupport (= 7.1.6) + cgi + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.6) + actionpack (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.6) + activesupport (= 7.1.6) + builder (~> 3.1) + cgi + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.6) + activesupport (= 7.1.6) + globalid (>= 0.3.6) + activemodel (7.1.6) + activesupport (= 7.1.6) + activerecord (7.1.6) + activemodel (= 7.1.6) + activesupport (= 7.1.6) + timeout (>= 0.4.0) + activestorage (7.1.6) + actionpack (= 7.1.6) + activejob (= 7.1.6) + activerecord (= 7.1.6) + activesupport (= 7.1.6) + marcel (~> 1.0) + activesupport (7.1.6) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + mutex_m + securerandom (>= 0.3) + tzinfo (~> 2.0) + base64 (0.3.0) + benchmark (0.5.0) + bigdecimal (4.0.1) + bootsnap (1.21.1) + msgpack (~> 1.2) + builder (3.3.0) + cgi (0.5.1) + concurrent-ruby (1.3.6) + connection_pool (3.0.2) + crass (1.0.6) + date (3.5.1) + debug (1.11.1) + irb (~> 1.10) + reline (>= 0.3.8) + drb (2.2.3) + erb (6.0.1) + erubi (1.13.1) + globalid (1.3.0) + activesupport (>= 6.1) + i18n (1.14.8) + concurrent-ruby (~> 1.0) + io-console (0.8.2) + irb (1.16.0) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + logger (1.7.0) + loofah (2.25.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.9.0) + logger + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.1.0) + mini_mime (1.1.5) + minitest (6.0.1) + prism (~> 1.5) + msgpack (1.8.0) + mutex_m (0.3.0) + mysql2 (0.5.7) + bigdecimal + net-imap (0.6.2) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.0-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.19.0-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.19.0-arm64-darwin) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-linux-musl) + racc (~> 1.4) + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + prism (1.8.0) + psych (5.3.1) + date + stringio + puma (6.6.1) + nio4r (~> 2.0) + racc (1.8.1) + rack (3.2.4) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.3.1) + rack (>= 3) + rails (7.1.6) + actioncable (= 7.1.6) + actionmailbox (= 7.1.6) + actionmailer (= 7.1.6) + actionpack (= 7.1.6) + actiontext (= 7.1.6) + actionview (= 7.1.6) + activejob (= 7.1.6) + activemodel (= 7.1.6) + activerecord (= 7.1.6) + activestorage (= 7.1.6) + activesupport (= 7.1.6) + bundler (>= 1.15.0) + railties (= 7.1.6) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (7.1.6) + actionpack (= 7.1.6) + activesupport (= 7.1.6) + cgi + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.3.1) + rdoc (7.1.0) + erb + psych (>= 4.0.0) + tsort + reline (0.6.3) + io-console (~> 0.5) + securerandom (0.4.1) + stringio (3.2.0) + thor (1.5.0) + timeout (0.6.0) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + websocket-driver (0.8.0) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.7.4) + +PLATFORMS + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + bootsnap + debug + mysql2 (~> 0.5) + puma (~> 6.0) + rails (~> 7.1.0) + +RUBY VERSION + ruby 3.4.7p58 + +BUNDLED WITH + 2.6.9 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7820749 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require_relative "config/application" +Rails.application.load_tasks diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..d8d7952 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,19 @@ +class HomeController < ApplicationController + def index + @db_status = check_database + @timestamp = Time.current + end + + def health + render json: { status: "ok", database: check_database, timestamp: Time.current } + end + + private + + def check_database + ActiveRecord::Base.connection.execute("SELECT 1") + "connected" + rescue => e + "error: #{e.message}" + end +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..abd2e68 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,20 @@ +
+

Rails Test Application

+

Unity Platform - Coolify Deployment Test

+ +

Status

+
+ Database: <%= @db_status %> +
+ +

Environment

+ + +

Health Endpoint

+

Check /health for JSON status

+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..9f8eb77 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,19 @@ + + + + Rails Test App + + + + + <%= yield %> + + diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..5c59c6f --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..fc6e837 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,11 @@ +require_relative "boot" +require "rails/all" + +Bundler.require(*Rails.groups) + +module RailsTest + class Application < Rails::Application + config.load_defaults 7.1 + config.api_only = false + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..0a0a2b7 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +require 'bundler/setup' +require 'bootsnap/setup' diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..72e46f8 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,20 @@ +default: &default + adapter: mysql2 + encoding: utf8mb4 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + username: <%= ENV.fetch("DB_USERNAME") { "root" } %> + password: <%= ENV.fetch("DB_PASSWORD") { "" } %> + host: <%= ENV.fetch("DB_HOST") { "localhost" } %> + port: <%= ENV.fetch("DB_PORT") { 3306 } %> + +development: + <<: *default + database: rails_test_development + +test: + <<: *default + database: rails_test_test + +production: + <<: *default + database: <%= ENV.fetch("DB_NAME") { "rails_test_production" } %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..40c19d2 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,2 @@ +require_relative "application" +Rails.application.initialize! diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..5c97dc9 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,16 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + config.enable_reloading = false + config.eager_load = true + config.consider_all_requests_local = false + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.force_ssl = false + config.logger = ActiveSupport::Logger.new(STDOUT) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + config.log_tags = [:request_id] + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.active_support.report_deprecations = false + config.active_record.dump_schema_after_migration = false +end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..2eba5a4 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1 @@ +Rails.application.config.filter_parameters += [:password, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn] diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..0590b13 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,13 @@ +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + +port ENV.fetch("PORT") { 3000 } + +environment ENV.fetch("RAILS_ENV") { "production" } + +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f51b2b7 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,4 @@ +Rails.application.routes.draw do + root "home#index" + get "health", to: "home#health" +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..2c7c6b3 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,2 @@ +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>