diff --git a/.env.example b/.env.example index 7970ef9..20dc230 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,11 @@ -PORT=1234 +ENV=local +PORT=8080 + +# local machine에서 local machine으로 접근할 때는 localhost를 사용 +POSTGRES_HOST=localhost +# # local machine에서 docker container로 접근할 때는 host.docker.internal을 사용 +# POSTGRES_HOST=host.docker.internal +POSTGRES_USER=example-user +POSTGRES_PASSWORD=password +POSTGRES_DB=tbh-db +POSTGRES_PORT=5432 diff --git a/.gitignore b/.gitignore index 5322a9a..75faffe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .DS_Store .idea -.env +*.env diff --git a/README.md b/README.md new file mode 100644 index 0000000..223b73d --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +## DB 실행 + +### 로컬 DB 실행 +```bash +./dev-db.sh +``` + +### 테스트용 DB 실행 +```bash +./test-db.sh +``` diff --git a/deploy/postgresql/.env.dev b/deploy/postgresql/.env.dev new file mode 100644 index 0000000..0ef38a7 --- /dev/null +++ b/deploy/postgresql/.env.dev @@ -0,0 +1,5 @@ +POSTGRES_USER=example-user +POSTGRES_PASSWORD=password +POSTGRES_DB=tbh-db +POSTGRES_PORT=5432 +POSTGRES_CONTAINER_NAME=local-tbh-postgres diff --git a/deploy/postgresql/.env.example b/deploy/postgresql/.env.example new file mode 100644 index 0000000..0ef38a7 --- /dev/null +++ b/deploy/postgresql/.env.example @@ -0,0 +1,5 @@ +POSTGRES_USER=example-user +POSTGRES_PASSWORD=password +POSTGRES_DB=tbh-db +POSTGRES_PORT=5432 +POSTGRES_CONTAINER_NAME=local-tbh-postgres diff --git a/deploy/postgresql/.env.test b/deploy/postgresql/.env.test new file mode 100644 index 0000000..8503bfe --- /dev/null +++ b/deploy/postgresql/.env.test @@ -0,0 +1,5 @@ +POSTGRES_USER=example-user +POSTGRES_PASSWORD=password +POSTGRES_DB=tbh-db +POSTGRES_PORT=5433 +POSTGRES_CONTAINER_NAME=test-tbh-postgres diff --git a/deploy/postgresql/docker-compose.dev.yml b/deploy/postgresql/docker-compose.dev.yml new file mode 100644 index 0000000..10d1a5a --- /dev/null +++ b/deploy/postgresql/docker-compose.dev.yml @@ -0,0 +1,12 @@ +name: dev-tbh-postgresql +services: + postgresql: + volumes: + - dev_postgres_data:/var/lib/postgresql/data + - dev_postgres_config:/etc/postgresql/postgresql.conf + +volumes: + dev_postgres_data: + name: dev_postgres_data + dev_postgres_config: + name: dev_postgres_config diff --git a/deploy/postgresql/docker-compose.test.yml b/deploy/postgresql/docker-compose.test.yml new file mode 100644 index 0000000..2a37304 --- /dev/null +++ b/deploy/postgresql/docker-compose.test.yml @@ -0,0 +1,12 @@ +name: test-tbh-postgresql +services: + postgresql: + volumes: + - test_postgres_data:/var/lib/postgresql/data + - test_postgres_config:/etc/postgresql/postgresql.conf + +volumes: + test_postgres_data: + name: test_postgres_data + test_postgres_config: + name: test_postgres_config diff --git a/deploy/postgresql/docker-compose.yml b/deploy/postgresql/docker-compose.yml new file mode 100644 index 0000000..3e542d8 --- /dev/null +++ b/deploy/postgresql/docker-compose.yml @@ -0,0 +1,28 @@ +name: tbh-postgresql +services: + postgresql: + image: postgres:16 + container_name: ${POSTGRES_CONTAINER_NAME} + restart: unless-stopped + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - postgres_data:/var/lib/postgresql/data + - postgres_config:/etc/postgresql/postgresql.conf + ports: + - ${POSTGRES_PORT}:5432 + deploy: + resources: + limits: + cpus: "1" + memory: 512M + reservations: + memory: 256M + +volumes: + postgres_data: + name: postgres_data + postgres_config: + name: postgres_config diff --git a/dev-db.sh b/dev-db.sh new file mode 100755 index 0000000..9b49800 --- /dev/null +++ b/dev-db.sh @@ -0,0 +1 @@ +docker compose -f ./deploy/postgresql/docker-compose.yml -f ./deploy/postgresql/docker-compose.dev.yml --env-file ./deploy/postgresql/.env.dev up -d diff --git a/test-db.sh b/test-db.sh new file mode 100755 index 0000000..e411be6 --- /dev/null +++ b/test-db.sh @@ -0,0 +1 @@ +docker compose -f ./deploy/postgresql/docker-compose.yml -f ./deploy/postgresql/docker-compose.test.yml --env-file ./deploy/postgresql/.env.test up -d