From 817f24abbed527268aeb679e8e1e9cdfe259955b Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 2 Dec 2025 08:17:59 +0000 Subject: [PATCH 01/15] Add devcontainer for Codespaces --- .devcontainer/codespaces/devcontainer.json | 18 ++++++++++++++++++ .devcontainer/codespaces/onCreateCommand.sh | 15 +++++++++++++++ .devcontainer/codespaces/postCreateCommand.sh | 11 +++++++++++ .devcontainer/codespaces/postStartCommand.sh | 2 ++ 4 files changed, 46 insertions(+) create mode 100644 .devcontainer/codespaces/devcontainer.json create mode 100644 .devcontainer/codespaces/onCreateCommand.sh create mode 100644 .devcontainer/codespaces/postCreateCommand.sh create mode 100644 .devcontainer/codespaces/postStartCommand.sh diff --git a/.devcontainer/codespaces/devcontainer.json b/.devcontainer/codespaces/devcontainer.json new file mode 100644 index 0000000000..5e57b1de95 --- /dev/null +++ b/.devcontainer/codespaces/devcontainer.json @@ -0,0 +1,18 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/universal +{ + "name": "For Codespaces", + + "image": "mcr.microsoft.com/devcontainers/universal:4", + + "containerEnv": { + "DATABASE_URL": "postgresql://postgres:@localhost" + }, + + "onCreateCommand": "bash --login .devcontainer/codespaces/onCreateCommand.sh", + + "postCreateCommand": "bash --login .devcontainer/codespaces/postCreateCommand.sh", + + "postStartCommand": "bash --login .devcontainer/codespaces/postStartCommand.sh" + +} diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh new file mode 100644 index 0000000000..e0feca47f0 --- /dev/null +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -0,0 +1,15 @@ +RUBY_VERSION=3.4.6 +rvm list +rvm install $RUBY_VERSION +rvm --default use $RUBY_VERSION +ruby -v + +wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome.deb +sudo apt update && sudo apt install -y /tmp/google-chrome.deb && rm /tmp/google-chrome.deb +google-chrome --version + +CHROMEDRIVER_VERSION=$(google-chrome --version | awk '{print $3}') +wget https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip +unzip chromedriver-linux64.zip +sudo mv chromedriver-linux64/chromedriver /usr/local/bin/ +rm -rf chromedriver-linux64.zip chromedriver-linux64 diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh new file mode 100644 index 0000000000..36d56f7e05 --- /dev/null +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -0,0 +1,11 @@ + +docker run -d -i --name postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres +until docker exec postgres pg_isready -U postgres; do sleep 1; done + +./bin/setup +./bin/setup +RAILS_ENV=test bundle exec rake db:setup dev:prime + +echo "" >> .env && echo "DATABASE_URL=postgresql://postgres:@localhost" >> .env + +docker stop postgres diff --git a/.devcontainer/codespaces/postStartCommand.sh b/.devcontainer/codespaces/postStartCommand.sh new file mode 100644 index 0000000000..7e11a015f0 --- /dev/null +++ b/.devcontainer/codespaces/postStartCommand.sh @@ -0,0 +1,2 @@ + +docker start postgres From 05f7585693415e4ad0380a6859676897a5649771 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 2 Dec 2025 17:14:46 +0000 Subject: [PATCH 02/15] Update configuration for prebuild and rebuild compatibility --- .devcontainer/codespaces/postCreateCommand.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh index 36d56f7e05..4e57bcf6b7 100644 --- a/.devcontainer/codespaces/postCreateCommand.sh +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -1,4 +1,6 @@ +until docker info >/dev/null 2>&1; do sleep 1; done +docker rm postgres >/dev/null 2>&1 docker run -d -i --name postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres until docker exec postgres pg_isready -U postgres; do sleep 1; done From 5e0981f05ef75571ec64e39b66a0f5ce23b4ae7c Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 3 Dec 2025 02:31:16 +0000 Subject: [PATCH 03/15] Add workaround for CSRF issue in current GitHub Codespaces --- spec/example_app/config/environments/development.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/example_app/config/environments/development.rb b/spec/example_app/config/environments/development.rb index 31644dbb98..f54c9589ca 100644 --- a/spec/example_app/config/environments/development.rb +++ b/spec/example_app/config/environments/development.rb @@ -75,4 +75,11 @@ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # config.generators.apply_rubocop_autocorrect_after_generate! + + # In the current GitHub Codespaces, the Origin header is rewritten, which breaks CSRF protection. + # See: https://github.com/orgs/community/discussions/156532 + if ENV["GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"] == "app.github.dev" + warn "WARNING: (development) Disabling CSRF protection Origin header check!" + config.action_controller.forgery_protection_origin_check = false + end end From 371a4d7cdd48fd658f82be24874cfd56c779e90d Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 3 Dec 2025 14:25:25 +0000 Subject: [PATCH 04/15] Add libvips to Codespace devcontainer --- .devcontainer/codespaces/onCreateCommand.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index e0feca47f0..5d55e34aab 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -13,3 +13,8 @@ wget https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VER unzip chromedriver-linux64.zip sudo mv chromedriver-linux64/chromedriver /usr/local/bin/ rm -rf chromedriver-linux64.zip chromedriver-linux64 + +sudo apt install -y libvips + +sudo apt-get clean +sudo rm -rf /var/lib/apt/lists/* From 196b92ab04c5019d9bd790a127f1f0a6e2aea3be Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 04:56:30 +0000 Subject: [PATCH 05/15] Remove addition of ENV variables to .env --- .devcontainer/codespaces/postCreateCommand.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh index 4e57bcf6b7..9d2d4049d2 100644 --- a/.devcontainer/codespaces/postCreateCommand.sh +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -4,10 +4,11 @@ docker rm postgres >/dev/null 2>&1 docker run -d -i --name postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres until docker exec postgres pg_isready -U postgres; do sleep 1; done +# Create config/database.yml ./bin/setup +# Setup & Create .env ./bin/setup -RAILS_ENV=test bundle exec rake db:setup dev:prime -echo "" >> .env && echo "DATABASE_URL=postgresql://postgres:@localhost" >> .env +RAILS_ENV=test bundle exec rake db:setup dev:prime docker stop postgres From 41ba8227c070abcfd13bec70b35e7b20f2be781c Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 06:40:50 +0000 Subject: [PATCH 06/15] Allow connections to forwarded ports in GitHub Codespaces --- spec/example_app/config/environments/development.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spec/example_app/config/environments/development.rb b/spec/example_app/config/environments/development.rb index f54c9589ca..310817bdd1 100644 --- a/spec/example_app/config/environments/development.rb +++ b/spec/example_app/config/environments/development.rb @@ -76,10 +76,8 @@ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # config.generators.apply_rubocop_autocorrect_after_generate! - # In the current GitHub Codespaces, the Origin header is rewritten, which breaks CSRF protection. - # See: https://github.com/orgs/community/discussions/156532 - if ENV["GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"] == "app.github.dev" - warn "WARNING: (development) Disabling CSRF protection Origin header check!" - config.action_controller.forgery_protection_origin_check = false + # In GitHub Codespaces, allow connections to the forwarded port. + if ENV["CODESPACES"] == "true" && ENV["RAILS_DEVELOPMENT_HOSTS"].present? + config.hosts << ENV["RAILS_DEVELOPMENT_HOSTS"] end end From 3dc15c2d531dd45d7d37ea6e094adae258761d5c Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 07:26:41 +0000 Subject: [PATCH 07/15] Refile test database setup --- .devcontainer/codespaces/postCreateCommand.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh index 9d2d4049d2..9d749870a3 100644 --- a/.devcontainer/codespaces/postCreateCommand.sh +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -9,6 +9,7 @@ until docker exec postgres pg_isready -U postgres; do sleep 1; done # Setup & Create .env ./bin/setup -RAILS_ENV=test bundle exec rake db:setup dev:prime +# Create test database and run seeds +RAILS_ENV=test ./bin/rails dev:prime docker stop postgres From 843b1bdb036b0139287f2c3d4f7033f93f1117bb Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 6 Jan 2026 18:12:23 +0000 Subject: [PATCH 08/15] Update Ruby version in devcontainer setup scripts --- .devcontainer/codespaces/onCreateCommand.sh | 5 ++--- .devcontainer/codespaces/postCreateCommand.sh | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index 5d55e34aab..697f992d29 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -1,8 +1,7 @@ -RUBY_VERSION=3.4.6 -rvm list +RUBY_VERSION=4.0.0 +rvm install 3.4.6 rvm install $RUBY_VERSION rvm --default use $RUBY_VERSION -ruby -v wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome.deb sudo apt update && sudo apt install -y /tmp/google-chrome.deb && rm /tmp/google-chrome.deb diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh index 9d749870a3..a35262c710 100644 --- a/.devcontainer/codespaces/postCreateCommand.sh +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -1,3 +1,4 @@ +rvm --default use $(cat ./.ruby-version) until docker info >/dev/null 2>&1; do sleep 1; done docker rm postgres >/dev/null 2>&1 From 6951c5cdd40002c693686e8854fabbef21d1c296 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 6 Jan 2026 20:11:26 +0000 Subject: [PATCH 09/15] Workaround for install Ruby 4.0.0 with RVM --- .devcontainer/codespaces/onCreateCommand.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index 697f992d29..ce237cf841 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -1,7 +1,16 @@ -RUBY_VERSION=4.0.0 +# Workaround for install Ruby 4.0.0 with RVM +rvm list +curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - +curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - +rvm get master +rvm list known + +# Install Ruby rvm install 3.4.6 -rvm install $RUBY_VERSION -rvm --default use $RUBY_VERSION +rvm install 4.0.0 +rvm --default use 4.0.0 +rvm list +ruby --version wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome.deb sudo apt update && sudo apt install -y /tmp/google-chrome.deb && rm /tmp/google-chrome.deb From 994bd1d9a86219d3a352e804e44a8f96f3bd24fb Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 7 Jan 2026 04:18:31 +0000 Subject: [PATCH 10/15] add labels --- .devcontainer/codespaces/onCreateCommand.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index ce237cf841..e296e83c92 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -12,17 +12,22 @@ rvm --default use 4.0.0 rvm list ruby --version +# Install Google Chrome wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome.deb sudo apt update && sudo apt install -y /tmp/google-chrome.deb && rm /tmp/google-chrome.deb google-chrome --version +# Install Chromedriver CHROMEDRIVER_VERSION=$(google-chrome --version | awk '{print $3}') wget https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip unzip chromedriver-linux64.zip sudo mv chromedriver-linux64/chromedriver /usr/local/bin/ rm -rf chromedriver-linux64.zip chromedriver-linux64 +chromedriver --version +# Install libs sudo apt install -y libvips +# Cleanup sudo apt-get clean sudo rm -rf /var/lib/apt/lists/* From c031e2cb14f344fd8126b3e72e1b55c1f08d5867 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 3 Mar 2026 14:35:17 +0000 Subject: [PATCH 11/15] Add workaround for Yarn GPG key error on apt update in devcontainer --- .devcontainer/codespaces/onCreateCommand.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index e296e83c92..35419657aa 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -12,6 +12,11 @@ rvm --default use 4.0.0 rvm list ruby --version +# Workaround for Yarn GPG key +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/yarnkey.gpg +echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list +sudo apt update + # Install Google Chrome wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome.deb sudo apt update && sudo apt install -y /tmp/google-chrome.deb && rm /tmp/google-chrome.deb From 37af0f17ef98bf18fa60c703226e7a8c38537896 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 8 Sep 2026 16:30:46 +0900 Subject: [PATCH 12/15] Update .devcontainer/codespaces/devcontainer.json Co-authored-by: Pablo Brasero <36066+pablobm@users.noreply.github.com> --- .devcontainer/codespaces/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/codespaces/devcontainer.json b/.devcontainer/codespaces/devcontainer.json index 5e57b1de95..9b1e601fdd 100644 --- a/.devcontainer/codespaces/devcontainer.json +++ b/.devcontainer/codespaces/devcontainer.json @@ -1,4 +1,4 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// 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/universal { "name": "For Codespaces", From 51e4365e7bfbc454ae60ffa523e68ee3bcd2c3a7 Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 16 Sep 2026 13:05:38 +0000 Subject: [PATCH 13/15] replace rv with rvm --- .devcontainer/codespaces/onCreateCommand.sh | 22 +++++++++---------- .devcontainer/codespaces/postCreateCommand.sh | 5 ++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.devcontainer/codespaces/onCreateCommand.sh b/.devcontainer/codespaces/onCreateCommand.sh index 35419657aa..e0c0ddd397 100644 --- a/.devcontainer/codespaces/onCreateCommand.sh +++ b/.devcontainer/codespaces/onCreateCommand.sh @@ -1,15 +1,13 @@ -# Workaround for install Ruby 4.0.0 with RVM -rvm list -curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - -curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - -rvm get master -rvm list known - -# Install Ruby -rvm install 3.4.6 -rvm install 4.0.0 -rvm --default use 4.0.0 -rvm list +# Install Ruby via rv +curl -LsSf https://rv.dev/install | sh +source ~/.cargo/env +rv ruby list +rv ruby install 3.4.6 +rv ruby install 4.0.0 +rv ruby list +echo 'eval "$(rv shell init bash)"' >> ~/.bashrc +source ~/.bashrc +which ruby ruby --version # Workaround for Yarn GPG key diff --git a/.devcontainer/codespaces/postCreateCommand.sh b/.devcontainer/codespaces/postCreateCommand.sh index a35262c710..b1f23b525f 100644 --- a/.devcontainer/codespaces/postCreateCommand.sh +++ b/.devcontainer/codespaces/postCreateCommand.sh @@ -1,5 +1,8 @@ -rvm --default use $(cat ./.ruby-version) +# Init ruby via rv +source "$HOME/.cargo/env" +eval "$(rv shell init bash)" +# Wait for Docker to be ready and start PostgreSQL container until docker info >/dev/null 2>&1; do sleep 1; done docker rm postgres >/dev/null 2>&1 docker run -d -i --name postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres From a65a40d01a248d38e38e2d59354ce11475af4579 Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 16 Sep 2026 13:06:10 +0000 Subject: [PATCH 14/15] use universal:6 --- .devcontainer/codespaces/devcontainer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.devcontainer/codespaces/devcontainer.json b/.devcontainer/codespaces/devcontainer.json index 9b1e601fdd..32d8e843a3 100644 --- a/.devcontainer/codespaces/devcontainer.json +++ b/.devcontainer/codespaces/devcontainer.json @@ -3,10 +3,11 @@ { "name": "For Codespaces", - "image": "mcr.microsoft.com/devcontainers/universal:4", + "image": "mcr.microsoft.com/devcontainers/universal:6", "containerEnv": { - "DATABASE_URL": "postgresql://postgres:@localhost" + "DATABASE_URL": "postgresql://postgres:@localhost", + "COREPACK_ENABLE_DOWNLOAD_PROMPT": "0" }, "onCreateCommand": "bash --login .devcontainer/codespaces/onCreateCommand.sh", From 6d50565d0f2efd44246863b01f798df56fdbfc0f Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 16 Sep 2026 16:39:04 +0000 Subject: [PATCH 15/15] Add CSRF workaround again --- spec/example_app/config/environments/development.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/example_app/config/environments/development.rb b/spec/example_app/config/environments/development.rb index 310817bdd1..13ea03e5f6 100644 --- a/spec/example_app/config/environments/development.rb +++ b/spec/example_app/config/environments/development.rb @@ -76,6 +76,13 @@ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # config.generators.apply_rubocop_autocorrect_after_generate! + # In the current GitHub Codespaces, the Origin header is rewritten, which breaks CSRF protection. + # See: https://github.com/orgs/community/discussions/156532 + if ENV["GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"] == "app.github.dev" + warn "WARNING: (development) Disabling CSRF protection Origin header check!" + config.action_controller.forgery_protection_origin_check = false + end + # In GitHub Codespaces, allow connections to the forwarded port. if ENV["CODESPACES"] == "true" && ENV["RAILS_DEVELOPMENT_HOSTS"].present? config.hosts << ENV["RAILS_DEVELOPMENT_HOSTS"]