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

refactor: add example env file for easier environment variable management #685

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
49 changes: 49 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
env_file:
Copy link
Author

Choose a reason for hiding this comment

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

I can't honestly say I know how I mangled the git history here, but the diff should only be the switch from using environment variables to an env file like shown in this duplicate (and now closed) PR.

Copy link
Author

Choose a reason for hiding this comment

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

Ahhh, I see now. Y'all purged docker files on develop. I can definitely just nix this file, but thinking more about how this impacts the PRs we have in the queue... 🤔

- .env.local

db:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
- ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql
env_file:
- .env.local
# Your config/database.yml should use the user and password you set here,
# and host "db" (as that's the name of this service). You can use whatever
# database name you want. Use `bin/rails db:prepare` to create the database.
#
# Example:
#
# development:
# <<: *default
# host: db
# username: postgres
# password: postgres
# database: myapp_development

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
postgres-data:

28 changes: 28 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# App settings
RACK_ENV=development
RAILS_ENV=development
HOST='localhost:3000'
PORT=3000

# DB settings needed only for db creation
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=klaxon
POSTGRES_HOST=db

# Postgres URI pattern is postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
DATABASE_URL="postgres://postgres:postgres@db:5432/klaxon"
SECRET_KEY_BASE="secret_key_base"
ADMIN_EMAILS="[email protected]" # comma-separated list of email addresses

# Email config if using Sendgrid
SENDGRID_USERNAME=
SENDGRID_PASSWORD=

# Email config if using Amazon SES
SMTP_PROVIDER= # SES
SES_ADDRESS=
SES_USERNAME=
SES_PASSWORD=
SES_DOMAIN=
MAILER_FROM_ADDRESS=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ snapshots

/app/assets/builds/*
!/app/assets/builds/.keep

.env*
!.env.*.example
7 changes: 3 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ gem install bundler
bundle install
```

In order to be allowed to login to Klaxon once it's running on your machine, it'll need to know that your email address is. Create a file named `.env` and paste in these two items:
In order to be allowed to login to Klaxon once it's running on your machine, it'll need to know that your email address is. Create an env file for local development like so:

```
ADMIN_EMAILS="[email protected]"
HOST='localhost:5000'
cp .env.local.example .env.local
```

Feel free to substitute in your email address. In development, Klaxon doesn't actually send emails locally, so a real address is not required.
Feel free to substitute in your email address in `ADMIN_EMAILS`. In development, Klaxon doesn't actually send emails locally, so a real address is not required. But, those will be the addresses used to log into the app.

Now that's set, you'll run a couple of commands for Rails to create Klaxon's database on your machine.

Expand Down