Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add dev container infrastructure #4842

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
22b1f70
Start dev container config
ianjmacintosh Oct 25, 2024
d6cf003
Follow instructions from containers.dev
ianjmacintosh Oct 25, 2024
401e26f
Add docker compose for postgres
ianjmacintosh Oct 25, 2024
30d076e
Remove unnecessary newline
ianjmacintosh Oct 27, 2024
d45b7f6
Add redis and change network mode
ianjmacintosh Oct 27, 2024
e8ce830
Revert "Add redis and change network mode"
ianjmacintosh Oct 27, 2024
118165e
Attach postgres service to devcontainer's network interface
ianjmacintosh Oct 27, 2024
af4ffcd
Install postgresql-client during setup
ianjmacintosh Oct 27, 2024
fbec261
Add redis container to setup
ianjmacintosh Oct 27, 2024
38730ec
Add documentation for codespaces setup
ianjmacintosh Oct 27, 2024
215b6e0
Clarify docs for dev container config
ianjmacintosh Oct 27, 2024
6df017d
Stop installing psql unnecessarily
ianjmacintosh Oct 27, 2024
bbe61c2
Update env setup step in docs
ianjmacintosh Oct 27, 2024
0530ba2
Add setup script
ianjmacintosh Oct 28, 2024
5556d61
Add environment vars for dev setup
ianjmacintosh Oct 28, 2024
0d9691d
Update dependency script
ianjmacintosh Oct 28, 2024
e038b55
Add dependency install script
ianjmacintosh Oct 28, 2024
a037a12
Use correct Ruby management tool
ianjmacintosh Oct 28, 2024
68f50a9
Go back to using rvm
ianjmacintosh Oct 28, 2024
d08563f
Set ruby 3.3.5 as default
ianjmacintosh Oct 28, 2024
507771c
Run setup script when creating dev container
ianjmacintosh Oct 28, 2024
8083fc5
Remove deprecated attribute
ianjmacintosh Oct 28, 2024
62b683d
Explicitly set Ruby using documented commands
ianjmacintosh Oct 28, 2024
7b3e69b
Run setup in interactive mode (docs insist)
ianjmacintosh Oct 28, 2024
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
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/universal:2
37 changes: 37 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

These files in `/.devcontainer` let you use services like GitHub Codespaces to quickly get up and running with The Odin Project

You'll still to do some setup after starting your dev container:
```bash
# Install ruby-3.3.5 for rvm
rvm install "ruby-3.3.5"

# Remove a tool that will cause build issues
gem uninstall -i /usr/local/rvm/rubies/ruby-3.3.5/lib/ruby/gems/3.3.0 gem-wrappers

# Install required gems
bundle install

# Install required JS dependencies
yarn install

# Prepare .env
cp env.sample .env

# Manually update .env with postgres username and password; default is "postgres" for both
# POSTGRES_USERNAME: 'postgres'
# POSTGRES_PASSWORD: 'postgres

# Install Chrome (for running tests)
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
sudo apt update && \
sudo apt install ./google-chrome-stable_current_amd64.deb -y && \
rm ./google-chrome-stable_current_amd64.deb

# Set up your database
rails db:create
rails db:environment:set RAILS_ENV=development
rails db:schema:load
```

> Note: If you think some of this could be automated, you're probably right. Open a pull request with those changes that can give other engineers a turbo boost!
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"onCreateCommand": "bash -i .devcontainer/install-dependencies.sh"
}
40 changes: 40 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
services:
devcontainer:
build:
context: .
dockerfile: Dockerfile
volumes:
- ../..:/workspaces:cached
command: sleep infinity
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres

db:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
network_mode: service:devcontainer
depends_on:
- devcontainer

redis:
image: redis:latest
command: redis-server
volumes:
- redis:/var/lib/redis
- redis-config:/usr/local/etc/redis/redis.conf
network_mode: service:devcontainer
depends_on:
- devcontainer


volumes:
postgres-data:
redis:
redis-config:
40 changes: 40 additions & 0 deletions .devcontainer/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Install and use ruby 3.3.5 as default; our Docker image uses rvm
rvm install 3.3.5
rvm use 3.3.5

# Display current ruby version (for logging)
ruby -v

# Remove tooling that causes build issues
gem uninstall -i /usr/local/rvm/rubies/ruby-3.3.5/lib/ruby/gems/3.3.0 gem-wrappers

# Install required gems
bundle install

# Install required JS dependencies
yarn install

# Prepare .env
cp env.sample .env

# Install Chrome (for running tests)
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
sudo apt update && \
sudo apt install ./google-chrome-stable_current_amd64.deb -y && \
rm ./google-chrome-stable_current_amd64.deb

# Set up your database
rails db:create
rails db:environment:set RAILS_ENV=development
rails db:schema:load

# Remind user how to get started
echo
echo To get started you can run your tests by running this command:
echo
echo bin/rspec
echo
echo ...or you can run the web site by running this command:
echo
echo bin/dev
echo