Skip to content

Commit 1cb029b

Browse files
committed
Added a simple development configuration
1 parent ec40d18 commit 1cb029b

6 files changed

Lines changed: 186 additions & 26 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535

3636
.claude
3737
CLAUDE.md
38+
/.env.development

Dockerfile.dev

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG RUBY_VERSION=3.4
2+
FROM ruby:${RUBY_VERSION}
3+
4+
ENV RAILS_ENV=development \
5+
NODE_ENV=development \
6+
BUNDLE_WITHOUT=""
7+
8+
RUN apt-get update -qq && \
9+
apt-get install -y --no-install-recommends build-essential libpq-dev git curl && \
10+
rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /app
13+
14+
COPY Gemfile Gemfile.lock ./
15+
RUN bundle install --jobs=4 --retry=3
16+
17+
COPY . .
18+
19+
EXPOSE 3000
20+
21+
ENTRYPOINT ["./bin/docker-entrypoint"]
22+
CMD ["./bin/rails", "server", "-b", "0.0.0.0", "-p", "3000"]

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
COMPOSE ?= docker compose -f docker-compose.dev.yml
2+
3+
.PHONY: dev dev-detach down shell console test imap logs db-migrate db-reset psql
4+
5+
dev: ## Start dev stack (foreground)
6+
$(COMPOSE) up --build
7+
8+
dev-detach: ## Start dev stack in background
9+
$(COMPOSE) up -d --build
10+
11+
down: ## Stop dev stack
12+
$(COMPOSE) down
13+
14+
shell: ## Open a shell in the web container
15+
$(COMPOSE) exec web bash
16+
17+
console: ## Open Rails console in the web container
18+
$(COMPOSE) exec web bin/rails console
19+
20+
test: ## Run RSpec in the web container
21+
$(COMPOSE) exec web bundle exec rspec
22+
23+
db-migrate: ## Run db:migrate
24+
$(COMPOSE) exec web bin/rails db:migrate
25+
26+
db-reset: ## Drop and prepare (create/migrate)
27+
$(COMPOSE) run --rm web bin/rails db:drop && bin/rails db:prepare
28+
29+
psql: ## Open psql against the dev DB
30+
COMPOSE_PROFILES=tools $(COMPOSE) run --rm psql
31+
32+
imap: ## Start stack with IMAP worker profile
33+
$(COMPOSE) --profile imap up --build
34+
35+
logs: ## Follow web logs
36+
$(COMPOSE) logs -f web

README.md

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
1-
# README
2-
3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
5-
6-
Things you may want to cover:
7-
8-
* Ruby version
9-
10-
* System dependencies
11-
12-
* Configuration
13-
14-
* Database creation
15-
16-
* Database initialization
17-
18-
* How to run the test suite
19-
20-
* Services (job queues, cache servers, search engines, etc.)
21-
22-
* Deployment instructions
23-
24-
* ...
1+
# Hackorum
2+
3+
Rails 8 app backed by Postgres. Use the Docker-based development setup below for a quick start; production deploy lives under `deploy/` with its own `README`.
4+
5+
Live application is available at https://hackorum.dev
6+
7+
## Development (Docker)
8+
1) Copy the sample env and adjust as needed:
9+
```bash
10+
cp .env.development.example .env.development
11+
```
12+
2) Build and start the stack (web + Postgres):
13+
```bash
14+
docker compose -f docker-compose.dev.yml up --build
15+
```
16+
* App: http://localhost:3000
17+
* Postgres: localhost:15432 (user/password: hackorum/hackorum by default)
18+
* Emails sent by the application use `letter_opener`, will be opened by the browser automatically
19+
* If you run into a Postgres data-dir warning, clear the old volume: `docker volume rm hackorum_db-data`
20+
21+
Useful commands:
22+
* Shell: `docker compose -f docker-compose.dev.yml exec web bash`
23+
* Rails console: `docker compose -f docker-compose.dev.yml exec web bin/rails console`
24+
* Migrations/seeds: `docker compose -f docker-compose.dev.yml exec web bin/rails db:prepare`
25+
* Tests: `docker compose -f docker-compose.dev.yml exec web bundle exec rspec`
26+
27+
Makefile shortcuts:
28+
* `make dev` / `make dev-detach` / `make down`
29+
* `make shell` / `make console` / `make logs`
30+
* `make test`
31+
* `make db-migrate` / `make db-reset`
32+
* `make psql`
33+
34+
Optional IMAP worker (off by default):
35+
```bash
36+
docker compose -f docker-compose.dev.yml --profile imap up --build
37+
```
38+
Configure IMAP via `.env.development` (`IMAP_USERNAME`, `IMAP_PASSWORD`, `IMAP_MAILBOX_LABEL`, `IMAP_HOST`, `IMAP_PORT`, `IMAP_SSL`).
39+
Shortcut: `make imap`
40+
41+
Host, Port and ssl settings default to the gmail imap server.
42+
43+
The imap worker will connect to the specified imap, fetch all messages with the given label, import them to the database, and mark them as "read" on the server.
44+
It should point to a label subscribed to the pg-hackers list.
45+
It can't be INBOX, it has to be a specific label.
46+
47+
## Production
48+
See `deploy/README.md` for the single-host Docker Compose deployment (Puma + Caddy + Postgres + backups).

bin/docker-entrypoint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ if [ -z "${LD_PRELOAD+x}" ]; then
66
export LD_PRELOAD
77
fi
88

9-
# If running the rails server then create or migrate existing database
10-
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
9+
# If running the rails server (directly or via bin/dev), create or migrate the database
10+
if { [ "$1" = "./bin/rails" ] && [ "$2" = "server" ]; } || [ "$1" = "./bin/dev" ]; then
1111
./bin/rails db:prepare
1212
fi
1313

docker-compose.dev.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
services:
2+
db:
3+
image: postgres:18
4+
env_file:
5+
- .env.development
6+
volumes:
7+
- db-data:/var/lib/postgresql
8+
ports:
9+
- "15432:5432"
10+
healthcheck:
11+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-hackorum} -d ${POSTGRES_DB:-hackorum_development}"]
12+
interval: 10s
13+
timeout: 5s
14+
retries: 5
15+
16+
web:
17+
build:
18+
context: .
19+
dockerfile: Dockerfile.dev
20+
env_file:
21+
- .env.development
22+
environment:
23+
RAILS_ENV: development
24+
NODE_ENV: development
25+
DATABASE_URL: ${DATABASE_URL:-postgresql://${POSTGRES_USER:-hackorum}:${POSTGRES_PASSWORD:-hackorum}@db:5432/${POSTGRES_DB:-hackorum_development}}
26+
PGHOST: db
27+
PGPORT: 5432
28+
PGUSER: ${POSTGRES_USER:-hackorum}
29+
PGPASSWORD: ${POSTGRES_PASSWORD:-hackorum}
30+
PGDATABASE: ${POSTGRES_DB:-hackorum_development}
31+
volumes:
32+
- .:/app
33+
- bundle:/usr/local/bundle
34+
ports:
35+
- "3000:3000"
36+
depends_on:
37+
db:
38+
condition: service_healthy
39+
entrypoint: ["./bin/docker-entrypoint"]
40+
command: ["./bin/dev", "-b", "0.0.0.0", "-p", "3000"]
41+
42+
imap_worker:
43+
profiles: ["imap"]
44+
build:
45+
context: .
46+
dockerfile: Dockerfile.dev
47+
env_file:
48+
- .env.development
49+
command: ["bundle", "exec", "ruby", "script/imap_idle.rb"]
50+
environment:
51+
RAILS_ENV: development
52+
DATABASE_URL: ${DATABASE_URL:-postgresql://${POSTGRES_USER:-hackorum}:${POSTGRES_PASSWORD:-hackorum}@db:5432/${POSTGRES_DB:-hackorum_development}}
53+
PGHOST: db
54+
PGPORT: 5432
55+
PGUSER: ${POSTGRES_USER:-hackorum}
56+
PGPASSWORD: ${POSTGRES_PASSWORD:-hackorum}
57+
PGDATABASE: ${POSTGRES_DB:-hackorum_development}
58+
volumes:
59+
- .:/app
60+
- bundle:/usr/local/bundle
61+
depends_on:
62+
db:
63+
condition: service_healthy
64+
65+
psql:
66+
profiles: ["tools"]
67+
image: postgres:18
68+
entrypoint: ["psql", "postgresql://${POSTGRES_USER:-hackorum}:${POSTGRES_PASSWORD:-hackorum}@db:5432/${POSTGRES_DB:-hackorum_development}"]
69+
env_file:
70+
- .env.development
71+
depends_on:
72+
db:
73+
condition: service_healthy
74+
75+
volumes:
76+
db-data:
77+
bundle:

0 commit comments

Comments
 (0)