From 6a09691c47bb7ea80b3c1a2a420dd565afa270a6 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Wed, 24 Sep 2025 09:33:19 +0100 Subject: [PATCH] Configure devcontainer setup --- .devcontainer/Dockerfile | 17 +++++ .devcontainer/compose.yaml | 17 ++--- .devcontainer/devcontainer.json | 6 +- .devcontainer/start | 11 +++ bin/setup | 1 + config/devcontainer.database.yml | 113 ++++--------------------------- 6 files changed, 53 insertions(+), 112 deletions(-) create mode 100755 .devcontainer/start diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0d6d7a024..2f76be5df 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,20 @@ # 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 + +USER root +ENV DEBIAN_FRONTEND=noninteractive + +# Required on Windows +RUN mkdir -p /workspaces/openstreetmap-website \ + && chown -R vscode:vscode /workspaces/openstreetmap-website + +# Install system packages then clean up to minimize image size +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + file \ + libarchive-dev \ + libgd-dev \ + osmosis \ + && apt-get clean \ + && apt-get distclean diff --git a/.devcontainer/compose.yaml b/.devcontainer/compose.yaml index a8fabf106..b9265f6fd 100644 --- a/.devcontainer/compose.yaml +++ b/.devcontainer/compose.yaml @@ -8,6 +8,7 @@ services: volumes: - ../..:/workspaces:cached + - mise-cache:/home/vscode/.local/share/mise # Overrides default command so things don't shut down after the process ends. command: sleep infinity @@ -19,19 +20,12 @@ services: # (Adding the "ports" property to this file will not forward from a Codespace.) depends_on: - selenium - - redis - postgres selenium: - image: selenium/standalone-chromium + image: selenium/standalone-firefox restart: unless-stopped - redis: - image: redis:7.2 - restart: unless-stopped - volumes: - - redis-data:/data - postgres: image: postgres:16.1 restart: unless-stopped @@ -40,9 +34,10 @@ services: volumes: - postgres-data:/var/lib/postgresql/data environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + POSTGRES_DB: openstreetmap + POSTGRES_USER: openstreetmap + POSTGRES_PASSWORD: openstreetmap volumes: - redis-data: postgres-data: + mise-cache: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 359c7e153..e2c08c716 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,6 +9,7 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, "ghcr.io/rails/devcontainer/features/activestorage": {}, "ghcr.io/rails/devcontainer/features/postgres-client": {} }, @@ -16,12 +17,11 @@ "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], + "forwardPorts": [3000, 5432], // Configure tool-specific properties. // "customizations": {}, @@ -31,5 +31,5 @@ // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "bin/setup --skip-server" + "postCreateCommand": ".devcontainer/start" } diff --git a/.devcontainer/start b/.devcontainer/start new file mode 100755 index 000000000..9b4d529c7 --- /dev/null +++ b/.devcontainer/start @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# This setup uses https://mise.jdx.dev to manage language versions. +# Mark the config file as trusted to avoid an interactive prompt. +mise trust /workspaces/mise.local.toml + +cp config/devcontainer.database.yml config/database.yml +cp config/example.storage.yml config/storage.yml +touch config/settings.local.yml + +bin/setup --skip-server diff --git a/bin/setup b/bin/setup index f882c0024..ccac37778 100755 --- a/bin/setup +++ b/bin/setup @@ -16,6 +16,7 @@ FileUtils.chdir APP_ROOT do puts "== Installing dependencies ==" system("bundle check") || system!("bundle install") + system("yarn install --check-dependencies") # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") diff --git a/config/devcontainer.database.yml b/config/devcontainer.database.yml index ae09b4ebd..f65469580 100644 --- a/config/devcontainer.database.yml +++ b/config/devcontainer.database.yml @@ -1,103 +1,20 @@ -# 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 %> - +# This configuration is tailored for use with devcontainers. See DEVCONTAINER.md for more information. 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 + adapter: postgresql + database: openstreetmap + username: openstreetmap + password: openstreetmap + host: <%= ENV["DB_HOST"] %> + encoding: utf8 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> -# 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 + adapter: postgresql + database: osm_test + username: openstreetmap + password: openstreetmap + host: <%= ENV["DB_HOST"] %> + encoding: utf8 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> -# 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 -- 2.39.5