Skip to content

Added dockerized postgres #6

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dist
.webpack
.env
coverage
db_data

# Temp dir
tmp
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ This is a minimal example of using the [Warthog](https://github.com/goldcaddy77/

## Setup

To get things set up, run `yarn bootstrap`.
To get things set up,

1. Start PostgreSQL. You can BYO or we've provided a dockerized PostgreSQL, which can be run with `yarn postgres:start`
2. Install dependencies with `yarn bootstrap`

## Running the server

Run `yarn start` to run the server.
1. Start the PostgreSQL instance you created during setup
2. Run `yarn start` to run the server

## Using GraphQL Playground

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/goldcaddy77"
},
"scripts": {
"bootstrap": "cp .env.example .env && yarn && yarn db:create && yarn db:seed:dev",
"bootstrap": "cp .env.example .env && yarn && yarn db:create && NODE_ENV=development yarn db:seed:dev",
"db:create": "createdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :",
"db:drop": "dropdbjs $(dotenv -p TYPEORM_DATABASE) 2>&1 || :",
"db:seed:dev": "ts-node tools/seed.ts",
Expand All @@ -19,7 +19,9 @@
"start": "DEBUG=warthog* yarn start:ts",
"start:ts": "ts-node-dev --type-check src/index.ts",
"test": "jest --detectOpenHandles --verbose --coverage",
"watch:ts": "nodemon -e ts,graphql -x ts-node --type-check src/index.ts"
"watch:ts": "nodemon -e ts,graphql -x ts-node --type-check src/index.ts",
"postgres:start": "cd postgres && docker-compose up",
"postgres:clean": "docker stop $(docker ps -a -q); docker rm $(docker ps -a -q); docker volume prune -f"
},
"husky": {
"hooks": {
Expand Down
Empty file added postgres/db_data/.gitkeep
Empty file.
17 changes: 17 additions & 0 deletions postgres/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.6'
Copy link
Owner

Choose a reason for hiding this comment

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

Can we just name the folder db and mount the data in the root... or are you concerned that then this file would then get mounted as well? If so, what about the folder names db and data so that the directory structure is db/data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you could, but I like to keep the data separate from source files (i.e. the docker-compose file) for the sake of self-documentation. Also, in the future I would add a README and possibly other assets in the postgres folder, like possibly a seed file. Your call though.

services:
postgres:
image: postgres
restart: always
volumes:
- ./db_data:/var/lib/postgresql/data
ports:
- 5432:5432
# To set password, use, etc. Default is u/p/db: postgres/none/postgres
#environment:
# POSTGRES_DB: warthog-example
# POSTGRES_PASSWORD: testpassword
# POSTGRES_USER: postgres

volumes:
db_data: