diff --git a/.dockerignore b/.dockerignore index 0271fe2..6e81eed 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,9 @@ * +!/bin/ !/config/ !/db/ !/lib/ -!/script/server !/views/ !/.ruby-version !/config.ru diff --git a/.rubocop.yml b/.rubocop.yml index cbab567..9832330 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,10 @@ plugins: AllCops: Exclude: - - bin/**/* + - bin/puma + - bin/rake + - bin/rspec + - bin/rubocop - config/**/* - db/schema.rb - vendor/**/* diff --git a/Dockerfile b/Dockerfile index cd66a0a..9906386 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,4 +57,4 @@ RUN groupadd --system --gid 1000 fleetfocus-api && \ USER 1000:1000 EXPOSE 80 -CMD ["script/server", "--port=80"] +CMD ["bin/puma", "config.ru", "--port=80"] diff --git a/Gemfile.lock b/Gemfile.lock index 8b144f3..ad39610 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -380,7 +380,7 @@ CHECKSUMS bcrypt_pbkdf (1.1.2) sha256=c2414c23ce66869b3eb9f643d6a3374d8322dfb5078125c82792304c10b94cf6 bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f - bundler (4.0.12) sha256=7f8b757d28dfb636e7b24fba2344ac6dd13b5b24f4b46d62573d483f211825ac + bundler (4.0.13) sha256=19f08be7f27022cf0b89f27da0b044ae075e8270a9ef44ad248a932614e1ca3b concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a crass (1.0.6) sha256=dc516022a56e7b3b156099abc81b6d2b08ea1ed12676ac7a5657617f012bd45d @@ -489,4 +489,4 @@ RUBY VERSION ruby 3.4.8p72 BUNDLED WITH - 4.0.6 + 4.0.13 diff --git a/README.md b/README.md index 627b9c6..6bbae6f 100644 --- a/README.md +++ b/README.md @@ -62,20 +62,20 @@ Setup ----- 1) Install ruby. (`rbenv install`) 2) Ensure you have [freetds](https://www.freetds.org/) installed. If you're on macOS, you can download this through homebrew: `brew install freetds` -3) Run the setup script. (`script/setup`) +3) Run the setup script. (`bin/setup`) 4) Place the credentials key file in `config/fleetfocus-api.key`. (Get from KeePass or another developer) Scripts ------- ```bash bin/bundle # install dependencies +bin/console # run irb +bin/dev # run development server - requires database tunnel bin/rake # run tasks bin/rspec # run specs bin/rubocop # run linter -script/console # run irb -script/server # run server - requires database tunnel -script/setup # set up development environment -script/tunnel # open a database tunnel to the production server - requires ssh access, vpn connection, credentials key +bin/setup # set up development environment +bin/tunnel # open a database tunnel to the production server - requires ssh access, vpn connection, credentials key ``` License diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 50da5fd..0000000 --- a/bin/bundle +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'bundle' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "rubygems" - -m = Module.new do - module_function - - def invoked_as_script? - File.expand_path($0) == File.expand_path(__FILE__) - end - - def env_var_version - ENV["BUNDLER_VERSION"] - end - - def cli_arg_version - return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` - bundler_version = nil - update_index = nil - ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) - bundler_version = a - end - next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 - update_index = i - end - bundler_version - end - - def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] - return gemfile if gemfile && !gemfile.empty? - - File.expand_path("../Gemfile", __dir__) - end - - def lockfile - lockfile = - case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") - else "#{gemfile}.lock" - end - File.expand_path(lockfile) - end - - def lockfile_version - return unless File.file?(lockfile) - lockfile_contents = File.read(lockfile) - return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ - Regexp.last_match(1) - end - - def bundler_requirement - @bundler_requirement ||= - env_var_version || - cli_arg_version || - bundler_requirement_for(lockfile_version) - end - - def bundler_requirement_for(version) - return "#{Gem::Requirement.default}.a" unless version - - bundler_gem_version = Gem::Version.new(version) - - bundler_gem_version.approximate_recommendation - end - - def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile - - activate_bundler - end - - def activate_bundler - gem_error = activation_error_handling do - gem "bundler", bundler_requirement - end - return if gem_error.nil? - require_error = activation_error_handling do - require "bundler/version" - end - return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) - warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" - exit 42 - end - - def activation_error_handling - yield - nil - rescue StandardError, LoadError => e - e - end -end - -m.load_bundler! - -if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") -end diff --git a/script/console b/bin/console similarity index 100% rename from script/console rename to bin/console diff --git a/bin/dev b/bin/dev new file mode 100755 index 0000000..153a3f8 --- /dev/null +++ b/bin/dev @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e +cd "$(dirname "$0")/.." + +bin/puma config.ru "$@" diff --git a/bin/puma b/bin/puma new file mode 100755 index 0000000..ef0fb29 --- /dev/null +++ b/bin/puma @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'puma' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("puma", "puma") diff --git a/bin/rake b/bin/rake index 4eb7d7b..9efbee9 100755 --- a/bin/rake +++ b/bin/rake @@ -10,17 +10,6 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - require "rubygems" require "bundler/setup" diff --git a/bin/rspec b/bin/rspec index cb53ebe..93e191c 100755 --- a/bin/rspec +++ b/bin/rspec @@ -10,17 +10,6 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - require "rubygems" require "bundler/setup" diff --git a/bin/rubocop b/bin/rubocop index 369a05b..d73598d 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -10,17 +10,6 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - require "rubygems" require "bundler/setup" diff --git a/script/setup b/bin/setup similarity index 100% rename from script/setup rename to bin/setup diff --git a/script/tunnel b/bin/tunnel similarity index 100% rename from script/tunnel rename to bin/tunnel diff --git a/config/database.yml b/config/database.yml index 0b1b113..64f2723 100644 --- a/config/database.yml +++ b/config/database.yml @@ -7,7 +7,7 @@ production: reconnect: true # Because our application never writes to the database, you can tunnel -# through the production server to the prod database by running `script/tunnel`. +# through the production server to the prod database by running `bin/tunnel`. # # The MS-SQL username specified here only needs read-only access to the `FTK_MAIN` table. development: diff --git a/script/server b/script/server deleted file mode 100755 index 621e0f6..0000000 --- a/script/server +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require 'fileutils' - -# path to your application root. -APP_ROOT = File.expand_path('..', __dir__) - -FileUtils.chdir APP_ROOT do - system 'bundle', 'exec', 'puma', 'config.ru', *ARGV -end