From fb7a4048957343a1a310c260fd2a973e2175dcac Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Tue, 23 Apr 2024 13:10:05 +0200 Subject: [PATCH] use docker for local development --- Dockerfile | 9 +++++++++ README.md | 23 +++-------------------- compose.yml | 26 ++++++++++++++++++++++++++ config/database.yml | 9 ++++++--- test/application_system_test_case.rb | 13 +++++++++---- 5 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c7406275 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ruby:2.7.6 +RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-client +RUN mkdir /app +WORKDIR /app +copy .ruby-version /app/.ruby-version +COPY Gemfile /app/Gemfile +COPY Gemfile.lock /app/Gemfile.lock +RUN bundle install +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/README.md b/README.md index 5d65b254..4f48c23b 100644 --- a/README.md +++ b/README.md @@ -12,25 +12,8 @@ Staging web server: - https://staging-makeworks.herokuapp.com/ ### Getting started locally -- Install Ruby 2.7.6 with your version manager of choice: - `asdf install ruby 2.7.6; asdf local ruby 2.7.6` for asdf -- Install bundled gems: - `bundle install` -- Setup the database: - `bundle exec rake db:create && bundle exec rake db:schema:load` -- Install Node 14.21.2: - `nvm install 14.21.2; nvm use 14.21.2` for nvm -- Install Yarn dependencies: - `yarn install --check-files` -- Ensure ActionText is installed: - `bundle exec rails action_text install` -- Install chromedriver for system tests: - `brew install chromedriver` for homebrew on Mac OS X -- Run tests and check they pass: - `bundle exec rails test && bundle exec rails test:system` -- Run the development server: - `bundle exec rails server` - + - This is newly dockerised! Simply `docker compose up` and you're away. + - To get a shell for running tests, console, etc `docker compose exec app bash` ### Development * Run tests with `rails test` @@ -98,7 +81,7 @@ There are 3 roles: To become a 'champion' an admin needs to make you one, via the https://new.make.works/admin/user_regions interface. -Edit manufacturering tags in a not verified listing as an admin by deleting /admin/ out of listing URL to enter front end editor. +Edit manufacturering tags in a not verified listing as an admin by deleting /admin/ out of listing URL to enter front end editor. ## TODO consideration diff --git a/compose.yml b/compose.yml new file mode 100644 index 00000000..2b41cb5c --- /dev/null +++ b/compose.yml @@ -0,0 +1,26 @@ +services: + db: + image: postgres + volumes: + - mw-postgres:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + app: + build: . + volumes: + - .:/app + ports: + - "3000:3000" + environment: + CHROME_SERVER_HOST: chrome-server + depends_on: + - db + - chrome-server + chrome-server: + image: selenium/standalone-chrome:96.0 + ports: + - "7900:7900" + - "4444:4444" +volumes: + mw-postgres: + diff --git a/config/database.yml b/config/database.yml index 0d1276bb..7ec7c1f1 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,6 +11,9 @@ default: &default development: <<: *default + host: db + username: postgres + password: postgres database: makeworks_dev # Warning: The database defined as "test" will be erased and @@ -19,9 +22,9 @@ development: test: <<: *default database: <%= ENV['TEST_DB_NAME'] || 'makeworks_test' %> - host: <%= ENV['TEST_DB_HOST'] %> - username: <%= ENV['TEST_DB_USERNAME'] %> - password: <%= ENV['TEST_DB_PASSWORD'] %> + host: <%= ENV['TEST_DB_HOST'] || 'db' %> + username: <%= ENV['TEST_DB_USERNAME'] || 'postgres' %> + password: <%= ENV['TEST_DB_PASSWORD'] || 'postgres' %> production: <<: *default diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index f032aa33..4e21ca1f 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,14 +1,19 @@ require "test_helper" - class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include CapybaraSelect2 Capybara.configure do |config| config.ignore_hidden_elements = false + config.server_host = "0.0.0.0" + config.app_host = "http://#{ENV.fetch("HOSTNAME")}:#{Capybara.server_port}" end - if ENV['SYSTEM_TEST'] - driven_by :selenium, using: ENV['SYSTEM_TEST'].to_sym, screen_size: [1400, 1400] + options = if ENV["CHROME_SERVER_HOST"] + { browser: :remote, url: "http://#{ENV['CHROME_SERVER_HOST']}:4444" , } else - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + {} + end + + driven_by :selenium, using: ENV.fetch('SYSTEM_TEST', 'chrome').to_sym, screen_size: [1400, 1400], options: options do |driver_options| + driver_options.add_argument "disable-dev-shm-usage" end end