Skip to content

Commit 6a1b97a

Browse files
Merge pull request #1 from davidnguyen179/abc
Update docker-compose for setting up db
2 parents 9894570 + 24ebfd4 commit 6a1b97a

File tree

6 files changed

+23
-37
lines changed

6 files changed

+23
-37
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ WORKDIR /todo_api
99
COPY --from=builder /todo_api ./
1010
RUN yarn install --production=true
1111
EXPOSE 8080
12-
ENTRYPOINT ["yarn", "serve"]
12+
ENTRYPOINT ["yarn"]

README.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,23 @@ Make sure you have [Docker](https://www.docker.com/) installed
88

99
### Setting up
1010

11-
**Commands**
12-
13-
To install the database management, run:
14-
15-
```bash
16-
docker-compose up -d
17-
```
18-
19-
To create database, run:
20-
21-
```bash
22-
docker exec -it todo psql -U postgres -c "create database todo"
23-
```
24-
2511
**.env file**
2612

2713
1. Create the `.env` file
2814
2. Copy and parse the `connection information` below:
2915

3016
```bash
31-
DB_USER=postgres
32-
DB_HOST=localhost
33-
DB_DATABASE=todo
34-
DB_PORT=54320
17+
POSTGRES_USER=docker
18+
POSTGRES_PASSWORD=docker
19+
POSTGRES_HOST=localhost
20+
POSTGRES_DB=todo
21+
POSTGRES_PORT=54320
3522
```
3623

37-
## Create tables
38-
39-
Open and run the `database/sql/database.sql` by postgres tools (i.e. [pgAdmin](https://www.pgadmin.org/))
24+
**database**
25+
```bash
26+
docker-compose up -d
27+
```
4028

4129
## Seeding data
4230

database/sql/database.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
create database todo;
2-
31
create table todo_list
42
(
53
id serial primary key not null,

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ services:
33
db:
44
image: "postgres:11"
55
container_name: "todo"
6+
env_file:
7+
- ./.env
68
ports:
79
- "54320:5432"
810
volumes:
9-
- todo:/var/lib/postgresql/data
10-
volumes:
11-
todo:
11+
- ./database/sql/database.sql:/docker-entrypoint-initdb.d/database.sql

scripts/seed/db/connect.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ require('dotenv').config();
33

44
function connect() {
55
return new Pool({
6-
user: process.env.DB_USER,
7-
host: process.env.DB_HOST,
8-
database: process.env.DB_DATABASE,
9-
password: process.env.DB_PASSWORD,
10-
port: process.env.DB_PORT,
6+
user: process.env.POSTGRES_USER,
7+
host: process.env.POSTGRES_HOST,
8+
database: process.env.POSTGRES_DB,
9+
password: process.env.POSTGRES_PASSWORD,
10+
port: process.env.POSTGRES_PORT,
1111
});
1212
}
1313

src/db/connect.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ require('dotenv').config();
33

44
export function connect() {
55
return new Pool({
6-
user: process.env.DB_USER,
7-
host: process.env.DB_HOST,
8-
database: process.env.DB_DATABASE,
9-
password: process.env.DB_PASSWORD,
10-
port: process.env.DB_PORT,
6+
user: process.env.POSTGRES_USER,
7+
host: process.env.POSTGRES_HOST,
8+
database: process.env.POSTGRES_DB,
9+
password: process.env.POSTGRES_PASSWORD,
10+
port: process.env.POSTGRES_PORT,
1111
});
1212
}

0 commit comments

Comments
 (0)