Skip to content

Commit

Permalink
Moving Docker compose and makefile additions into this codebase (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewheeler authored Sep 27, 2024
1 parent 724fe91 commit ea27a93
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

.env
*.dump

# Binaries for programs and plugins
*.exe
Expand Down
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@ PHIN VADS written in Go. Load `phinvads.dump` into a PostgreSQL database using `

## Dev setup

1. Clone this repo:
Clone the repo:

```bash
git clone https://github.com/skylight-hq/phinvads-go.git
cd phinvads-go
```
```bash
git clone https://github.com/skylight-hq/phinvads-go.git
cd phinvads-go
```

### direnv setup and configuration

1. [Install direnv (`brew install direnv`)](https://direnv.net/docs/installation.html)
2. [Add a hook for your shell](https://direnv.net/docs/hook.html)
3. Restart your terminal
4. Run `direnv allow` in the project directory

### Database setup

#### Running Postgres in Docker

1. Install and run [PostgreSQL](https://www.postgresql.org/download/), or just run `docker compose up`
Download and install [Docker](https://www.docker.com/products/docker-desktop/) if you don't already have it installed.

1. Place `phinvads.dump` into the top level of your project directory (`/phinvads-go`)
2. Navigate to the project directory and start your PostgreSQL database with `make start`
3. Run `make refresh` to create the `phinvads` database and load in the data

When you want to shut down your database environment, run `make stop`.

#### Running Postgres locally

1. Install and run [PostgreSQL](https://www.postgresql.org/download/)
1. Create an empty database:

```bash
Expand All @@ -24,6 +45,8 @@ PHIN VADS written in Go. Load `phinvads.dump` into a PostgreSQL database using `
pg_restore -d phinvads --no-owner --role=$(whoami) phinvads.dump
```

### Application setup

1. Install [Go](https://go.dev/doc/install)
1. Install [air](https://github.com/air-verse/air):

Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ services:
db:
image: postgres:alpine
environment:
POSTGRES_DB: phinvads
POSTGRES_DB: ${DB_NAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- 5433:5432
- ${DB_PORT}:5432
restart: on-failure
volumes:
- db-data:/var/lib/postgresql/data
- ./:/app

volumes:
db-data:
db-data:
20 changes: 20 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
DB_SERVICE = db # Name of the PostgreSQL service in docker-compose
DUMP_FILE = /app/phinvads.dump # Name of your SQL dump file (within db container)

start:
@echo "Starting database container..."
docker compose up -d

stop:
@echo "Stopping database container..."
docker compose down

load:
@echo "Inserting data from $(DUMP_FILE) into $(DB_NAME)..."
docker compose exec -T $(DB_SERVICE) pg_restore -U $(DB_USER) -x --no-owner -d $(DB_NAME) $(DUMP_FILE)

refresh:
@echo "Running database refresh..."
docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c "DROP DATABASE IF EXISTS $(DB_NAME) WITH (FORCE)"
docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c 'CREATE DATABASE $(DB_NAME)'
$(MAKE) load

0 comments on commit ea27a93

Please sign in to comment.