Skip to content

Commit 6686bc8

Browse files
committed
Add Codespaces support
This commit adds support for GitHub Codespaces. It includes a devcontainer configuration that will be used to create a Codespace for this repository. The configuration includes: - Dockerfile: Installs `ruby:dev-3.2-buster` image. When the version of ruby used by this project changes, the Dockerfile should be updated. An attempt to install the correct version of ruby will be done, but it will take a while to download and compile the version. - devcontainer.json: Specifies the configuration for the Codespace. It includes the Dockerfile to use, the extensions to install, and the settings to use. - docker-compose.yml: Specifies the services to run in the Codespace. It includes the `postgres` service. - post-create.sh: Script that runs after the Codespace is created. It optionally installs a new version of ruby, sets up the database, and prepares the environment.
1 parent a5da0e4 commit 6686bc8

File tree

7 files changed

+97
-3
lines changed

7 files changed

+97
-3
lines changed

.devcontainer/.env.codespaces

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is the .env that is used by the codespaces environment.
2+
# See the .devcontainer/devcontainer.json file for how this is configured.
3+
PG_USERNAME=postgres
4+
PG_PASSWORD=postgres
5+
DELAYED_JOB_USERNAME='admin'
6+
DELAYED_JOB_PASSWORD='password'
7+
FLIPPER_USERNAME="admin"
8+
FLIPPER_PASSWORD="password"
9+
RECAPTCHA_SITE_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
10+
RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
11+
12+
# [OPTIONAL] - Used to fetch copies of production DB
13+
AZURE_STORAGE_ACCOUNT_NAME=
14+
AZURE_STORAGE_ACCESS_KEY=

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Installs Ruby 3.2.2. When human-essentials moves to a newer version of ruby,
2+
# it will be more efficient to change the image.
3+
# See https://github.com/devcontainers/images/blob/main/src/ruby/history/
4+
FROM mcr.microsoft.com/devcontainers/ruby:dev-3.2-buster
5+
RUN apt -y update && apt install -y vim curl gpg postgresql postgresql-contrib

.devcontainer/devcontainer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/postgres
3+
{
4+
"dockerComposeFile": "docker-compose.yml",
5+
"forwardPorts": [3000, 5432],
6+
"workspaceFolder": "/workspaces/human-essentials",
7+
"service": "app",
8+
"customizations": {
9+
"vscode": {
10+
"extensions": ["Shopify.ruby-extensions-pack"],
11+
"settings": {
12+
"rubyLsp.rubyVersionManager": {
13+
"identifier": "rvm"
14+
}
15+
}
16+
}
17+
},
18+
19+
"postCreateCommand": ".devcontainer/post-create.sh"
20+
}

.devcontainer/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
9+
volumes:
10+
- ../..:/workspaces:cached
11+
12+
# Overrides default command so things don't shut down after the process ends.
13+
command: sleep infinity
14+
15+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
16+
network_mode: service:postgres
17+
18+
postgres:
19+
image: postgres:latest
20+
restart: always
21+
volumes:
22+
- postgres-data:/var/lib/postgresql/data
23+
environment:
24+
POSTGRES_USER: postgres
25+
POSTGRES_DB: postgres
26+
POSTGRES_PASSWORD: postgres
27+
# Note that these ports are ignored by the devcontainer.
28+
# Instead, the ports are specified in .devcontainer/devcontainer.json.
29+
# ports:
30+
# - "5432:5432"
31+
volumes:
32+
postgres-data:

.devcontainer/post-create.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RUBY_VERSION="$(cat .ruby-version | tr -d '\n')"
2+
3+
cp .devcontainer/.env.codespaces .env
4+
5+
# source /usr/local/rvm/scripts/rvm
6+
7+
# If the project's required ruby version changes from 3.2.2, this command
8+
# will download and compile the correct version, but it will take a long time.
9+
if [ "$RUBY_VERSION" != "3.2.2" ]; then
10+
rvm install $RUBY_VERSION
11+
rvm use $RUBY_VERSION
12+
echo "Ruby $RUBY_VERSION installed"
13+
fi
14+
15+
bin/setup

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,4 +752,4 @@ DEPENDENCIES
752752
webmock (~> 3.23)
753753

754754
BUNDLED WITH
755-
2.5.7
755+
2.5.9

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ Thanks for checking us out! If you're new here, here are some things you should
6565
### Join us on slack 💬
6666
You can sign up [here](https://join.slack.com/t/rubyforgood/shared_invite/zt-21pyz2ab8-H6JgQfGGI0Ab6MfNOZRIQA) and find us in #human-essentials. Many helpful members are available to answer your questions. Just ask, and someone will be there to help you!
6767

68-
## Getting Started 🛠️
68+
## Getting Started (Codespaces) 🛠️
69+
70+
1. [Create a new Codespace.](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository) It is recommended to open the Codespace in VS Code.
71+
2. Wait for the container to start. This may take a few minutes since Ruby 3.2.2 needs to be installed, the database needs to be created, and the `bin/setup` script needs to run.
72+
3. Run `bin/start` and visit http://localhost:3000/ to see the human essentials page.
73+
4. Login as a sample user with these default credentials (which also work for [staging](https://staging.humanessentials.app/)):
74+
75+
Note that when the Ruby version in [`.ruby-version`](.ruby-version) changes, the image used by the Codespace should be updated too. See [`Dockerfile`](.devcontainer/Dockerfile) for more information.
76+
77+
## Getting Started (Local Environment) 🛠️
6978

7079
1. Install Ruby
7180
- Install the version specified in [`.ruby-version`](.ruby-version).
@@ -411,4 +420,3 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
411420
<!-- ALL-CONTRIBUTORS-LIST:END -->
412421

413422
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
414-

0 commit comments

Comments
 (0)