diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..bd2845112b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM mcr.microsoft.com/devcontainers/universal:2 diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000000..59984e3720 --- /dev/null +++ b/.devcontainer/README.md @@ -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! \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..0a76f23d6a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,6 @@ +{ + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "onCreateCommand": "bash -i .devcontainer/install-dependencies.sh" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..a3cf4b14e9 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -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: diff --git a/.devcontainer/install-dependencies.sh b/.devcontainer/install-dependencies.sh new file mode 100644 index 0000000000..8787ce9398 --- /dev/null +++ b/.devcontainer/install-dependencies.sh @@ -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 \ No newline at end of file