From cb89efc6d40f4b5128ac2dad808da240cfeb7645 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Sat, 8 Oct 2022 15:43:11 -0700 Subject: [PATCH] feat: docker for development --- .dockerdev/.bashrc | 1 + .dockerdev/.psqlrc | 26 +++++ .dockerdev/Aptfile | 3 + .dockerdev/Dockerfile | 85 ++++++++++++++++ .dockerdev/Procfile.frontend | 4 + .dockerdev/README.md | 78 ++++++++++++++ .dockerdev/compose.yml | 146 +++++++++++++++++++++++++++ bin/configure | 117 +++++++++++++-------- bin/setup | 26 ++--- config/database.yml | 1 + dip.yml | 108 ++++++++++++++++++++ test/application_system_test_case.rb | 27 +++-- test/test_helper.rb | 2 +- 13 files changed, 558 insertions(+), 66 deletions(-) create mode 100644 .dockerdev/.bashrc create mode 100644 .dockerdev/.psqlrc create mode 100644 .dockerdev/Aptfile create mode 100644 .dockerdev/Dockerfile create mode 100644 .dockerdev/Procfile.frontend create mode 100644 .dockerdev/README.md create mode 100644 .dockerdev/compose.yml create mode 100644 dip.yml diff --git a/.dockerdev/.bashrc b/.dockerdev/.bashrc new file mode 100644 index 000000000..4f233c532 --- /dev/null +++ b/.dockerdev/.bashrc @@ -0,0 +1 @@ +alias be="bundle exec" diff --git a/.dockerdev/.psqlrc b/.dockerdev/.psqlrc new file mode 100644 index 000000000..05c0dcb22 --- /dev/null +++ b/.dockerdev/.psqlrc @@ -0,0 +1,26 @@ +-- Don't display the "helpful" message on startup. +\set QUIET 1 + +-- Allow specifying the path to history file via `PSQL_HISTFILE` env variable +-- (and fallback to the default $HOME/.psql_history otherwise) +\set HISTFILE `[ -z $PSQL_HISTFILE ] && echo $HOME/.psql_history || echo $PSQL_HISTFILE` + +-- Show how long each query takes to execute +\timing + +-- Use best available output format +\x auto + +-- Verbose error reports +\set VERBOSITY verbose + +-- If a command is run more than once in a row, +-- only store it once in the history +\set HISTCONTROL ignoredups +\set COMP_KEYWORD_CASE upper + +-- By default, NULL displays as an empty space. Is it actually an empty +-- string, or is it null? This makes that distinction visible +\pset null '[NULL]' + +\unset QUIET diff --git a/.dockerdev/Aptfile b/.dockerdev/Aptfile new file mode 100644 index 000000000..f00443c3f --- /dev/null +++ b/.dockerdev/Aptfile @@ -0,0 +1,3 @@ +# We might need an editor to work with credentials +vim +libicu-dev diff --git a/.dockerdev/Dockerfile b/.dockerdev/Dockerfile new file mode 100644 index 000000000..7efbb2ef7 --- /dev/null +++ b/.dockerdev/Dockerfile @@ -0,0 +1,85 @@ +# syntax=docker/dockerfile:1 + +ARG RUBY_VERSION +ARG DISTRO_NAME=bullseye + +FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME + +ARG DISTRO_NAME + +# Common dependencies +# Using --mount to speed up build with caching, see https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#run---mount +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + --mount=type=tmpfs,target=/var/log \ + rm -f /etc/apt/apt.conf.d/docker-clean; \ + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache; \ + apt-get update -qq && \ + DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ + build-essential \ + gnupg2 \ + curl \ + less \ + git + +ARG PG_MAJOR +RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/" \ + $DISTRO_NAME-pgdg main $PG_MAJOR | tee /etc/apt/sources.list.d/postgres.list > /dev/null +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + --mount=type=tmpfs,target=/var/log \ + apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ + libpq-dev \ + postgresql-client-$PG_MAJOR + +ARG NODE_MAJOR +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + --mount=type=tmpfs,target=/var/log \ + curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ + nodejs + +ARG YARN_VERSION +RUN npm install -g yarn@$YARN_VERSION + +# Application dependencies +# We use an external Aptfile for this, stay tuned +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + --mount=type=tmpfs,target=/var/log \ + --mount=type=bind,source=Aptfile,target=/tmp/Aptfile \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ + $(grep -Ev '^\s*#' /tmp/Aptfile | xargs) + +# Install Hivemind to run frontend builders in a single container +RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \ + curl -L "https://github.com/DarthSim/hivemind/releases/download/v1.1.0/hivemind-v1.1.0-linux-${arch}.gz" | gunzip > /usr/local/bin/hivemind && \ + chmod +x /usr/local/bin/hivemind + +# Configure bundler +ENV LANG=C.UTF-8 \ + BUNDLE_JOBS=4 \ + BUNDLE_RETRY=3 + +# Store Bundler settings in the project's root +ENV BUNDLE_APP_CONFIG=.bundle + +# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec` +# ENV PATH /app/bin:$PATH + +# Upgrade RubyGems and install the latest Bundler version +RUN gem update --system && \ + gem install bundler + +# Create a directory for the app code +RUN mkdir -p /app +WORKDIR /app + +# Document that we're going to expose port 3000 +EXPOSE 3000 +# Use Bash as the default command +CMD ["/usr/bin/bash"] diff --git a/.dockerdev/Procfile.frontend b/.dockerdev/Procfile.frontend new file mode 100644 index 000000000..4e222f462 --- /dev/null +++ b/.dockerdev/Procfile.frontend @@ -0,0 +1,4 @@ +js: yarn build --watch +light-js: yarn light:build --watch +light-css: yarn light:build:css --watch +light-mailer-css: yarn light:build:mailer:css --watch diff --git a/.dockerdev/README.md b/.dockerdev/README.md new file mode 100644 index 000000000..3d6177fe0 --- /dev/null +++ b/.dockerdev/README.md @@ -0,0 +1,78 @@ +# Docker for Development + +Source: [Ruby on Whales: Dockerizing Ruby and Rails development](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development). + +## Installation + +- Docker installed. + +For MacOS just use the [official app](https://docs.docker.com/engine/installation/mac/). + +- [`dip`](https://github.com/bibendi/dip) installed. + +You can install `dip` as Ruby gem: + +```sh +gem install dip +``` + +## Provisioning + +When using Dip it could be done with a single command: + +```sh +dip provision +``` + +## Running + +```sh +dip rails s +``` + +## Developing with Dip + +### Useful commands + +```sh +# run rails console +dip rails c + +# run rails server with debugging capabilities (i.e., `debugger` would work) +dip rails s + +# or run the while web app (with all the dependencies) +dip up web + +# run migrations +dip rails db:migrate + +# pass env variables into application +dip VERSION=20100905201547 rails db:migrate:down + +# run super scaffolding +dip super-scaffold + +# simply launch bash within app directory (with dependencies up) +dip runner + +# execute an arbitrary command via Bash +dip bash -c 'ls -al tmp/cache' + +# Additional commands + +# update gems or packages +dip bundle install + +# run psql console +dip psql + +# run tests +dip rails test + +# run system tests +dip rails test:system + +# shutdown all containers +dip down +``` diff --git a/.dockerdev/compose.yml b/.dockerdev/compose.yml new file mode 100644 index 000000000..000e97590 --- /dev/null +++ b/.dockerdev/compose.yml @@ -0,0 +1,146 @@ +x-app: &app + build: + context: . + args: + RUBY_VERSION: '3.2.1' + PG_MAJOR: '14' + NODE_MAJOR: '19' + YARN_VERSION: '1.22.19' + image: untitled-application-dev:1.0.0 + environment: &env + NODE_ENV: ${NODE_ENV:-development} + RAILS_ENV: ${RAILS_ENV:-development} + BULLET_TRAIN_ENV: "docker" + tmpfs: + - /tmp + - /app/tmp/pids + +x-backend: &backend + <<: *app + stdin_open: true + tty: true + volumes: + - ..:/app:cached + - bundle:/usr/local/bundle + - rails_cache:/app/tmp/cache + - node_modules:/app/node_modules + - assets:/app/public/assets + - assets_builds:/app/app/assets/builds + - history:/usr/local/hist + - ./.psqlrc:/root/.psqlrc:ro + - ./.bashrc:/root/.bashrc:ro + environment: &backend_environment + <<: *env + REDIS_URL: redis://redis:6379/ + DATABASE_URL: postgres://postgres:postgres@postgres:5432 + REMOTE_CHROME_URL: ${REMOTE_CHROME_URL:-http://chrome:3333} + MALLOC_ARENA_MAX: 2 + WEB_CONCURRENCY: ${WEB_CONCURRENCY:-1} + BOOTSNAP_CACHE_DIR: /usr/local/bundle/_bootsnap + XDG_DATA_HOME: /app/tmp/cache + YARN_CACHE_FOLDER: /app/node_modules/.yarn-cache + HISTFILE: /usr/local/hist/.bash_history + PSQL_HISTFILE: /usr/local/hist/.psql_history + IRB_HISTFILE: /usr/local/hist/.irb_history + EDITOR: vi + depends_on: &backend_depends_on + postgres: + condition: service_healthy + redis: + condition: service_healthy + +services: + rails: + <<: *backend + command: bundle exec rails + + web: + <<: *backend + command: bundle exec rails server -b 0.0.0.0 + ports: + - '3000:3000' + depends_on: + frontend: + condition: service_started + sidekiq: + condition: service_started + + # Special service definition for system tests + # which launches Chrome service in addition to other deps + rails_chrome: + <<: *backend + environment: + <<: *backend_environment + APP_HOST: ${APP_HOST:-http://untitled-application.test:3001} + ports: + - '3001:3001' + depends_on: + <<: *backend_depends_on + chrome: + condition: service_started + networks: + default: + aliases: + - untitled-application.test + + sidekiq: + <<: *backend + command: bundle exec sidekiq + + frontend: + <<: *backend + command: hivemind --root=./ .dockerdev/Procfile.frontend + + postgres: + image: postgres:14 + volumes: + - .psqlrc:/root/.psqlrc:ro + - postgres:/var/lib/postgresql/data + - history:/user/local/hist + environment: + PSQL_HISTFILE: /user/local/hist/.psql_history + POSTGRES_PASSWORD: postgres + ports: + - 5432 + healthcheck: + test: pg_isready -U postgres -h 127.0.0.1 + interval: 5s + + redis: + image: redis:6.2-alpine + volumes: + - redis:/data + ports: + - 6379 + healthcheck: + test: redis-cli ping + interval: 1s + timeout: 3s + retries: 30 + + chrome: + # See https://github.com/browserless/chrome/issues/1393 + image: browserless/chrome:latest + ports: + - "3333:3333" + # Mount application source code to support file uploading + # (otherwise Chrome won't be able to find files). + # NOTE: Make sure you use absolute paths in `#attach_file`. + volumes: + - ..:/app:cached + environment: + # By default, it uses 3000, which is typically used by Rails. + PORT: 3333 + # Set connection timeout to avoid timeout exception during debugging + # https://docs.browserless.io/docs/docker.html#connection-timeout + CONNECTION_TIMEOUT: 600000 + +volumes: + bundle: + node_modules: + history: + rails_cache: + postgres: + redis: + assets: + assets_builds: diff --git a/bin/configure b/bin/configure index 4af7a60f2..516b94c16 100755 --- a/bin/configure +++ b/bin/configure @@ -60,60 +60,79 @@ def check_package(package) end end +# Dockerized development (opt-in) +# https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development +use_dip = ask "Would you like to use Docker for development?" +if use_dip + puts "" + puts `gem install dip` + puts "" + # Switch to Cuprite, which is the only supported with Docker for now + replace_in_file('Gemfile', ' gem "selenium-webdriver"', ' # gem "selenium-webdriver"') + replace_in_file('Gemfile', ' gem "webdrivers"', ' # gem "webdrivers"') + replace_in_file('Gemfile', ' # gem "cuprite"', ' gem "cuprite"') +end -# Unless the shell's current version of Ruby is the same as what the application requires, we should flag it. -# rbenv produces strings like "3.1.2" while rvm produces ones like "ruby-3.1.2", so we account for that here. -required_ruby = `cat ./.ruby-version`.strip.gsub(/^ruby-/, "") -actual_ruby = `ruby -v`.strip -message = "Bullet Train requires Ruby #{required_ruby} and `ruby -v` returns #{actual_ruby}." -if actual_ruby.include?(required_ruby) - puts message.green -else - puts message.red - input = ask "Try proceeding with with Ruby #{actual_ruby} anyway? [y/n]" - if input.downcase[0] == "n" - exit +unless use_dip + # Unless the shell's current version of Ruby is the same as what the application requires, we should flag it. + # rbenv produces strings like "3.1.2" while rvm produces ones like "ruby-3.1.2", so we account for that here. + required_ruby = `cat ./.ruby-version`.strip.gsub(/^ruby-/, "") + actual_ruby = `ruby -v`.strip + message = "Bullet Train requires Ruby #{required_ruby} and `ruby -v` returns #{actual_ruby}." + if actual_ruby.include?(required_ruby) + puts message.green + else + puts message.red + input = ask "Try proceeding with with Ruby #{actual_ruby} anyway? [y/n]" + if input.downcase[0] == "n" + exit + end end -end -if `brew info 2> /dev/null`.length > 0 - puts "Homebrew is installed.".green -else - puts "You don't have Homebrew installed. This isn't necessarily a problem, you might not even be on macOS, but we can't check your dependencies without it.".red - input = ask "Try proceeding without Homebrew? [y/n]" - if input.downcase[0] == "n" - exit + if `brew info 2> /dev/null`.length > 0 + puts "Homebrew is installed.".green + else + puts "You don't have Homebrew installed. This isn't necessarily a problem, you might not even be on macOS, but we can't check your dependencies without it.".red + input = ask "Try proceeding without Homebrew? [y/n]" + if input.downcase[0] == "n" + exit + end end -end +<<<<<<< HEAD check_package("postgresql@14") check_package("redis") check_package("icu4c") check_package("node") - -if `yarn -v 2> /dev/null`.length > 0 - puts "Yarn is installed.".green -else - puts "You don't have Yarn installed. We can't proceed without it. Try `brew install yarn` or see the installation instructions at https://yarnpkg.com/getting-started/install .".red - exit -end +======= + check_package("postgresql@14") + check_package("redis") + check_package("icu4c") + check_package("node") +>>>>>>> c01cc4b (feat: docker for development) + + if `yarn -v 2> /dev/null`.length > 0 + puts "Yarn is installed.".green + else + puts "You don't have Yarn installed. We can't proceed without it. Try `brew install yarn` or see the installation instructions at https://yarnpkg.com/getting-started/install .".red + exit + end -required_node = `cat ./.nvmrc`.strip -actual_node = `node -v`.strip.gsub("v", "") -message = "Bullet Train requires Node.js #{required_node} and `node -v` returns #{actual_node}." -if Gem::Version.new(actual_node) >= Gem::Version.new(required_node) - puts message.green -else - puts message.red - input = ask "Try proceeding with Node #{actual_node} anyway? [y/n]" - if input.downcase[0] == "n" - exit + actual_node = `node -v`.strip.gsub("v", "") + message = "Bullet Train requires Node.js #{required_node} and `node -v` returns #{actual_node}." + if Gem::Version.new(actual_node) >= Gem::Version.new(required_node) + puts message.green + else + puts message.red + input = ask "Try proceeding with Node #{actual_node} anyway? [y/n]" + if input.downcase[0] == "n" + exit + end end end - puts "Next, let's push your application to GitHub." puts "If you would like to use another service like Gitlab to manage your repository," puts "you can opt out of this step and set up the repository manually." @@ -157,11 +176,13 @@ if skip_github.downcase[0] == "y" stream "git push origin #{local_branch}:main 2>&1" end -puts "Running `bundle install`.".green -stream "bundle install" +unless use_dip + puts "Running `bundle install`.".green + stream "bundle install" -puts "Running `yarn install`.".green -stream "yarn install" + puts "Running `yarn install`.".green + stream "yarn install" +end human = ask "What is the name of your new application in title case? (e.g. \"Some Great Application\")" while human == "" @@ -195,6 +216,9 @@ replace_in_file("./zapier/package.json", "untitled-application", kebab_case) replace_in_file("./zapier/package.json", "Untitled Application", human) replace_in_file("./app/views/api/v1/open_api/index.yaml.erb", "Untitled Application", human) +replace_in_file("./.dockerdev/compose.yml", "untitled-application", kebab_case) +replace_in_file("./dip.yml", "untitled-application", kebab_case) +replace_in_file("./dip.yml", "untitled_application", variable) puts "" unless skip_github @@ -224,5 +248,10 @@ end puts "" puts "OK, we're done, but at some point you should edit `config/locales/en/application.en.yml`!".yellow puts "" -puts "Next you can run `bin/dev` to spawn a local instance, then navigate to http://localhost:3000.".green + +if use_dip + puts "Next you can run `dip provision` and then `dip rails s`".green +else + puts "Next you can run `bin/dev` to spawn a local instance, then navigate to http://localhost:3000.".green +end puts "" diff --git a/bin/setup b/bin/setup index ed9f76059..65a33e069 100755 --- a/bin/setup +++ b/bin/setup @@ -56,17 +56,19 @@ FileUtils.chdir APP_ROOT do system! "cp config/application.yml.example config/application.yml" end - puts "\n== Checking Redis connection ==" - redis_url = ENV.fetch("REDIS_URL", "redis://localhost:6379/1") - result = `redis-cli -u #{redis_url} info clients` - if result.include?("connected_clients") - connected_clients = result.scan(/connected_clients:\d+/).first.split(":").last - puts "You are connected to #{connected_clients} server#{"s" if connected_clients.to_i > 1}." - else - puts "You are not connected to a Redis server. Please run `$ redis-server` in another tab and run bin/setup again.".red - exit 1 - end + unless ENV['BULLET_TRAIN_ENV'] == 'docker' + puts "\n== Checking Redis connection ==" + redis_url = ENV.fetch("REDIS_URL", "redis://localhost:6379/1") + result = `redis-cli -u #{redis_url} info clients` + if result.include?("connected_clients") + connected_clients = result.scan(/connected_clients:\d+/).first.split(":").last + puts "You are connected to #{connected_clients} server#{"s" if connected_clients.to_i > 1}." + else + puts "You are not connected to a Redis server. Please run `$ redis-server` in another tab and run bin/setup again.".red + exit 1 + end - puts "\n== Restarting application server ==" - system! "bin/rails restart" + puts "\n== Restarting application server ==" + system! "bin/rails restart" + end end diff --git a/config/database.yml b/config/database.yml index 3d9650661..76d1c5561 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,6 +20,7 @@ default: &default # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + url: <%= ENV['DATABASE_URL'] %> development: <<: *default diff --git a/dip.yml b/dip.yml new file mode 100644 index 000000000..54cf761b3 --- /dev/null +++ b/dip.yml @@ -0,0 +1,108 @@ +version: '7.1' + +# Define default environment variables to pass +# to Docker Compose +environment: + RAILS_ENV: development + +compose: + files: + - .dockerdev/compose.yml + project_name: untitled-application + +interaction: + # This command spins up a Rails container with the required dependencies (such as databases), + # and opens a terminal within it. + runner: + description: Open a Bash shell within a Rails container (with dependencies up) + service: rails + command: /bin/bash + + # Run a Rails container without any dependent services (useful for non-Rails scripts) + bash: + description: Run an arbitrary script within a container (or open a shell without deps) + service: rails + command: /bin/bash + compose_run_options: [ no-deps ] + + # A shortcut to run Bundler commands + bundle: + description: Run Bundler commands + service: rails + command: bundle + compose_run_options: [ no-deps ] + + # A shortcut to run RSpec (which overrides the RAILS_ENV) + rspec: + description: Run RSpec commands + service: rails + environment: + RAILS_ENV: test + command: bundle exec rspec + + rails: + description: Run Rails commands + service: rails + command: bundle exec rails + subcommands: + s: + description: Run Rails server at http://localhost:3000 + service: web + compose: + run_options: [service-ports, use-aliases] + test: + description: Run unit tests + service: rails + command: bundle exec rails test + environment: + RAILS_ENV: test + test:system: &rails_test_system + description: Run system tests + service: rails_chrome + default_args: test/system + command: bundle exec rails test + environment: + RAILS_ENV: test + compose: + run_options: [use-aliases] + # Run Chrome via: + # chrome --remote-debugging-port=3333 --no-sandbox --no-startup-window + test:system:local: + <<: *rails_test_system + description: Run system tests via the local Chrome + environment: + RAILS_ENV: test + REMOTE_CHROME_URL: http://host.docker.internal:3333 + APP_HOST: http://localhost:3001 + compose: + run_options: [service-ports, use-aliases] + + super-scaffold: + description: Run BulletTrain super scaffolding + service: rails + command: bundle exec bin/super-scaffold + compose_run_options: [ no-deps ] + + yarn: + description: Run Yarn commands + service: rails + command: yarn + compose_run_options: [ no-deps ] + + psql: + description: Run Postgres psql console + service: postgres + default_args: untitle_application_development + command: psql -h postgres -U postgres + + 'redis-cli': + description: Run Redis console + service: redis + command: redis-cli -h redis + +provision: + - dip compose up -d postgres redis + - dip bundle install + - dip yarn install + - dip bash -c bin/setup + - dip rails db:test:prepare diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index bfd25900d..5640f52d7 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -11,6 +11,19 @@ require "capybara/cuprite" require "support/ferrum_console_logger" + remote_chrome_url = ENV["REMOTE_CHROME_URL"].presence + + # Chrome doesn't allow connecting to CDP by hostnames (other than localhost), + # but allows using IP addresses. + if remote_chrome_url&.match?(/host.docker.internal/) + require "resolv" + + uri = URI.parse(remote_chrome_url) + ip = Resolv.getaddress(uri.host) + + remote_chrome_url = remote_chrome_url.sub("host.docker.internal", ip) + end + Capybara.register_driver(:bt_cuprite) do |app| Capybara::Cuprite::Driver.new( app, @@ -19,6 +32,7 @@ process_timeout: 10, inspector: true, headless: !ENV["HEADLESS"].in?(%w[n 0 no false]) && !ENV["MAGIC_TEST"].in?(%w[y 1 yes true]), + url: remote_chrome_url, ) end Capybara.default_driver = Capybara.javascript_driver = :bt_cuprite @@ -29,15 +43,10 @@ Capybara.default_max_wait_time = ENV.fetch("CAPYBARA_DEFAULT_MAX_WAIT_TIME", ENV["MAGIC_TEST"].present? ? 5 : 15) -Capybara.register_server :puma do |app, port, host| - require "rack/handler/puma" - # current we need at least three threads for the webhooks tests to pass. - Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: "5:5", config_files: ["-"]) -end - -Capybara.server = :puma +Capybara.server = :puma, {Silent: true, Threads: "5:5", config_files: ["-"]} Capybara.server_port = 3001 -Capybara.app_host = "http://localhost:3001" +Capybara.server_host = "0.0.0.0" if ENV["BULLET_TRAIN_ENV"] == "docker" +Capybara.app_host = ENV.fetch("APP_HOST", "http://localhost:3001") class ApplicationSystemTestCase < ActionDispatch::SystemTestCase def self.use_cuprite? @@ -69,7 +78,7 @@ def another_example_password end def setup - ENV["BASE_URL"] = "http://localhost:3001" + ENV["BASE_URL"] = Capybara.app_host Capybara.use_default_driver Capybara.reset_sessions! end diff --git a/test/test_helper.rb b/test/test_helper.rb index ba7a56341..a60d6e22c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -ENV["RAILS_ENV"] ||= "test" +ENV["RAILS_ENV"] = "test" require_relative "../config/environment" require "rails/test_help" require "simplecov"