Skip to content

Commit

Permalink
chore: add postgres service to docker compose (#13)
Browse files Browse the repository at this point in the history
* docs: add setup instructions to README

* build: add docker compose for local postgres

* docs: document new docker compose files
  • Loading branch information
Gum-Joe authored Jul 1, 2024
1 parent 85dc888 commit 0344664
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
# Getting Started with Create React App
# Answerbook UI (Frontend)
This repo contains the frontend code for the Answerbook project. The frontend is a React app that uses the Radix UI library for styling & component primitives.

## Setup
1. Run `nvm use` to ensure you're using the correct Node version.
2. Run `npm install` to install dependencies (this will also setup commit hooks).

## Running the application
### In Docker
#### With Docker-based postgres (recommended)
1. For first run, do: `docker compose -f dev.docker-compose.yml up --build`
2. After, use: `docker compose -f dev.docker-compose.yml up`

#### With a local copy of Postgres
1. For first run, do: `docker compose -f dev.local.docker-compose.yml up --build`
2. After, use: `docker compose -f dev.local.docker-compose.yml up`

For either, you might also want to pass in `-d` to run in detached mode.

#### After startup
1. Setup the database: `docker exec $(docker ps -qf "name=answerbook-ui-backend" | head -n1) poetry run alembic upgrade head`

# Old README: Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

Expand Down
42 changes: 21 additions & 21 deletions dev.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Basically dev.local.docker-compose.yml, but with postgres
services:
backend:
image: api
build:
context: ../answerbook-api
dockerfile: dev.Dockerfile
command: poetry run uvicorn main:app --reload --host 0.0.0.0 --port 5004
extends:
file: dev.local.docker-compose.yml
service: backend
environment:
- DB_URL=postgresql://user:[email protected]/answerbook
volumes:
- ../answerbook-api:/api
ports:
- 127.0.0.1:5004:5004

- DB_URL=postgresql://user:pass@db/answerbook

frontend:
image: node:20.13
ports:
- 127.0.0.1:3000:3000
working_dir: /ui
volumes:
- ./:/ui
command: npm start
extends:
file: dev.local.docker-compose.yml
service: frontend

# add db
db:
image: postgres:15
environment:
- REACT_APP_API_ENTRYPOINT=http://localhost:5004
depends_on:
- backend
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: answerbook
volumes:
- answerbook-api-pgdata:/var/lib/postgresql/data

volumes:
answerbook-api-pgdata:
28 changes: 28 additions & 0 deletions dev.local.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Run answerbook in docker but use a host-based postgres database

services:
backend:
image: api
build:
context: ../answerbook-api
dockerfile: dev.Dockerfile
command: poetry run uvicorn main:app --reload --host 0.0.0.0 --port 5004
environment:
- DB_URL=postgresql://user:[email protected]/answerbook
volumes:
- ../answerbook-api:/api
ports:
- 127.0.0.1:5004:5004

frontend:
image: node:20.13
ports:
- 127.0.0.1:3000:3000
working_dir: /ui
volumes:
- ./:/ui
command: npm start
environment:
- REACT_APP_API_ENTRYPOINT=http://localhost:5004
depends_on:
- backend

0 comments on commit 0344664

Please sign in to comment.