Skip to content

Commit 2e492cd

Browse files
authored
Add postgres development database via docker compose (#393)
1 parent 9ae67f5 commit 2e492cd

5 files changed

Lines changed: 61 additions & 0 deletions

File tree

.env.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CORS_ORIGINS=http://localhost:5173,https://example.com
22
DATABASE_URL=postgres://postgres:postgres@localhost:5432/river_dev
3+
TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/river_test
34
OTEL_ENABLED=false
45
PORT=8080
56
VITE_RIVER_API_BASE_URL=http://localhost:8080/api

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ verify: verify/sqlc
4747
.PHONY: verify/sqlc
4848
verify/sqlc:
4949
cd internal/dbsqlc && sqlc diff
50+
51+
.PHONY: docker-db/up
52+
docker-db/up:
53+
docker compose -f docker-compose.dev.yaml down
54+
docker compose -f docker-compose.dev.yaml up
55+
56+
.PHONY: docker-db/down
57+
docker-db/down:
58+
docker compose -f docker-compose.dev.yaml down

docker-compose.dev.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: riverui-dev
2+
3+
services:
4+
postgres:
5+
image: "postgres:16-alpine"
6+
environment:
7+
- POSTGRES_USER=postgres
8+
- POSTGRES_PASSWORD=postgres
9+
healthcheck:
10+
test: ["CMD", "pg_isready", "-d", "river_dev", "-U", "postgres"]
11+
timeout: 20s
12+
retries: 10
13+
start_period: 3s
14+
volumes:
15+
- ./scripts/docker-compose-dev/postgres/init:/docker-entrypoint-initdb.d
16+
ports:
17+
- "5432:5432"
18+
migrate:
19+
image: "golang:1.24-alpine"
20+
depends_on:
21+
postgres:
22+
condition: "service_healthy"
23+
entrypoint: "/bin/sh"
24+
# cache the go binaries so they don't redownload
25+
volumes:
26+
- gopath:/go
27+
command:
28+
- -c
29+
- |
30+
echo "downloading river binary"
31+
go install github.com/riverqueue/river/cmd/river@latest
32+
echo "migrating river_dev database"
33+
river migrate-up --database-url "postgres://postgres:postgres@postgres/river_dev"
34+
echo "migrating river_test database"
35+
river migrate-up --database-url "postgres://postgres:postgres@postgres/river_test"
36+
volumes:
37+
gopath:

docs/development.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ $ go install github.com/riverqueue/river/cmd/river
4242
$ river migrate-up --database-url postgres://localhost/river_dev
4343
```
4444

45+
## Postgres with Docker Compose
46+
Using Docker compose, you can skip the database migration steps for testing and development.
47+
48+
The database will be bound to `localhost:5432`.
49+
```sh
50+
# start/restart
51+
make docker-db/up
52+
53+
# stop
54+
make docker-db/down
55+
```
56+
4557
## Run tests
4658

4759
Raise test database:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE DATABASE river_dev;
2+
CREATE DATABASE river_test;

0 commit comments

Comments
 (0)