From 134afec8813e9a341036b20fbcff7b8ac2b161f9 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 2 Dec 2025 08:17:59 +0000 Subject: [PATCH 01/11] 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 c71b5eb9b84516b00d2591bc430c7e278a90ac69 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 2 Dec 2025 17:14:46 +0000 Subject: [PATCH 02/11] 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 4b9291acd314b2b9793a68343c7d56ad8c787e0e Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 3 Dec 2025 02:31:16 +0000 Subject: [PATCH 03/11] 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 3677fd39bac72a2e73a1b74915fc851036d9d04d Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 3 Dec 2025 14:25:25 +0000 Subject: [PATCH 04/11] 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 ce5acc010f7d550efd9fcb49464bb2fcf797a44f Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 04:56:30 +0000 Subject: [PATCH 05/11] 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 3bf48cfb189e9fd663a85f5ee449f48c6033edf5 Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 06:40:50 +0000 Subject: [PATCH 06/11] 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 7c1c13d94d3d7e874d26a40c042152b8f441fc9c Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 24 Dec 2025 07:26:41 +0000 Subject: [PATCH 07/11] 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 f1360cf09de18fe923bf55a7a93455cfb5348bb1 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 6 Jan 2026 18:12:23 +0000 Subject: [PATCH 08/11] 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 1bec0dafe1d804f38e1bec98ab1238f797ba4f33 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 6 Jan 2026 20:11:26 +0000 Subject: [PATCH 09/11] 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 3b70cf4fa95b95c1efa75e84ba347cca78d9a41e Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 7 Jan 2026 04:18:31 +0000 Subject: [PATCH 10/11] 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 73325d8d60ef49d49bc76f842c7804869d03f9f8 Mon Sep 17 00:00:00 2001 From: nakamura Date: Tue, 3 Mar 2026 14:35:17 +0000 Subject: [PATCH 11/11] 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