From ac1c1971c85177bdb2752487860ce012ee55e2ee Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Tue, 23 Sep 2025 09:45:20 +0100 Subject: [PATCH] $ ./bin/rails devcontainer # DB config written as config/devcontainer.database.yml --- .devcontainer/Dockerfile | 3 + .devcontainer/compose.yaml | 48 +++++++++++++ .devcontainer/devcontainer.json | 35 +++++++++ config/devcontainer.database.yml | 103 +++++++++++++++++++++++++++ test/application_system_test_case.rb | 10 ++- 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/compose.yaml create mode 100644 .devcontainer/devcontainer.json create mode 100644 config/devcontainer.database.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..0d6d7a024 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version +ARG RUBY_VERSION=3.4.7 +FROM ghcr.io/rails/devcontainer/images/ruby:$RUBY_VERSION diff --git a/.devcontainer/compose.yaml b/.devcontainer/compose.yaml new file mode 100644 index 000000000..a8fabf106 --- /dev/null +++ b/.devcontainer/compose.yaml @@ -0,0 +1,48 @@ +name: "open_street_map" + +services: + rails-app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Uncomment the next line to use a non-root user for all processes. + # user: vscode + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + depends_on: + - selenium + - redis + - postgres + + selenium: + image: selenium/standalone-chromium + restart: unless-stopped + + redis: + image: redis:7.2 + restart: unless-stopped + volumes: + - redis-data:/data + + postgres: + image: postgres:16.1 + restart: unless-stopped + networks: + - default + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + +volumes: + redis-data: + postgres-data: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..359c7e153 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://containers.dev/implementors/json_reference/. +// For config options, see the README at: https://github.com/devcontainers/templates/tree/main/src/ruby +{ + "name": "open_street_map", + "dockerComposeFile": "compose.yaml", + "service": "rails-app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/rails/devcontainer/features/activestorage": {}, + "ghcr.io/rails/devcontainer/features/postgres-client": {} + }, + + "containerEnv": { + "CAPYBARA_SERVER_PORT": "45678", + "SELENIUM_HOST": "selenium", + "REDIS_URL": "redis://redis:6379/1", + "DB_HOST": "postgres" + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [3000, 5432, 6379], + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://containers.dev/implementors/json_reference/#remoteUser. + // "remoteUser": "root", + + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bin/setup --skip-server" +} diff --git a/config/devcontainer.database.yml b/config/devcontainer.database.yml new file mode 100644 index 000000000..ae09b4ebd --- /dev/null +++ b/config/devcontainer.database.yml @@ -0,0 +1,103 @@ +# PostgreSQL. Versions 9.3 and up are supported. +# +# Install the pg driver: +# gem install pg +# On macOS with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem "pg" +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # https://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + <% if ENV["DB_HOST"] %> + host: <%= ENV["DB_HOST"] %> + username: postgres + password: postgres + <% end %> + + +development: + <<: *default + database: open_street_map_development + + # The specified database role being used to connect to PostgreSQL. + # To create additional roles in PostgreSQL see `$ createuser --help`. + # When left blank, PostgreSQL will use the default role. This is + # the same name as the operating system user running Rails. + #username: open_street_map + + # The password associated with the PostgreSQL role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: open_street_map_test + +# As with config/credentials.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# +production: + primary: &primary_production + <<: *default + database: open_street_map_production + username: open_street_map + password: <%= ENV["OPEN_STREET_MAP_DATABASE_PASSWORD"] %> + cache: + <<: *primary_production + database: open_street_map_production_cache + migrations_paths: db/cache_migrate + queue: + <<: *primary_production + database: open_street_map_production_queue + migrations_paths: db/queue_migrate + cable: + <<: *primary_production + database: open_street_map_production_cable + migrations_paths: db/cable_migrate diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index e10501f2b..e6f186462 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -14,8 +14,16 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase Capybara.configure do |config| config.enable_aria_label = true end + if ENV["CAPYBARA_SERVER_PORT"] + served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"] - driven_by :selenium, :using => Settings.system_test_headless ? :headless_firefox : :firefox do |options| + driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: { + browser: :remote, + url: "http://#{ENV["SELENIUM_HOST"]}:4444" + } + else + driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] + end options.add_preference("intl.accept_languages", "en") options.binary = Settings.system_test_firefox_binary if Settings.system_test_firefox_binary end -- 2.39.5