Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .devcontainer/codespaces/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"

}
33 changes: 33 additions & 0 deletions .devcontainer/codespaces/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Workaround for install Ruby 4.0.0 with RVM
rvm list
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t required for the installation itself, but when it fails, the cause is often unclear, so I’m outputting version information and similar details to the build logs.

curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
rvm get master
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby 4.0 isn’t available in the stable RVM release yet, so I’m installing it from master.
Once it becomes stable, I’ll remove this workaround.

rvm list known

# Install Ruby
rvm install 3.4.6
rvm install 4.0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some older PR branches still use older Ruby versions, so I install several versions to allow switching easily via RVM when needed.

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/*
16 changes: 16 additions & 0 deletions .devcontainer/codespaces/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rvm --default use $(cat ./.ruby-version)

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

# Create config/database.yml
./bin/setup
# Setup & Create .env
./bin/setup

# Create test database and run seeds
RAILS_ENV=test ./bin/rails dev:prime

docker stop postgres
2 changes: 2 additions & 0 deletions .devcontainer/codespaces/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

docker start postgres
5 changes: 5 additions & 0 deletions spec/example_app/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@

# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
# config.generators.apply_rubocop_autocorrect_after_generate!

# 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