4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ FROM node:14.15.3
2
+
3
+ RUN mkdir -p /opt/notes-app
4
+ WORKDIR /opt/notes-app
5
+
6
+ COPY package.json package-lock.json ./
7
+
8
+ RUN npm install
9
+
10
+ CMD ["npm" , "run" , "start" ]
Original file line number Diff line number Diff line change @@ -36,6 +36,18 @@ Then open http://localhost:4000.
36
36
37
37
The app won't work until you set up the database, as described below.
38
38
39
+ <details >
40
+ <summary >Setup with Docker</summary >
41
+ <p >You can also start dev build of the app by using docker-compose.</p >
42
+ <p >Make sure you have docker and docker-compose installed then run:</p >
43
+ <pre ><code >docker-compose up</code ></pre >
44
+ <h4 >Running seed script</h4 >
45
+ <p >1. Run containers in the detached mode</p >
46
+ <pre ><code >docker-compose up -d</code ></pre >
47
+ <p >2. Run seed script</p >
48
+ <pre ><code >docker-compose exec notes-app npm run seed</code ></pre >
49
+ </details >
50
+
39
51
## DB Setup
40
52
41
53
This demo uses Postgres. First, follow its [ installation link] ( https://wiki.postgresql.org/wiki/Detailed_installation_guides ) for your platform.
Original file line number Diff line number Diff line change
1
+ version : " 3.8"
2
+ services :
3
+ postgres :
4
+ image : postgres:13
5
+ environment :
6
+ POSTGRES_USER : admin
7
+ POSTGRES_PASSWORD : admin
8
+ POSTGRES_DB : notesapi
9
+ ports :
10
+ - ' 5432:5432'
11
+ volumes :
12
+ - ./scripts/init_db.sh:/docker-entrypoint-initdb.d/init_db.sh
13
+ - db:/var/lib/postgresql/data
14
+
15
+ notes-app :
16
+ build :
17
+ context : .
18
+ depends_on :
19
+ - postgres
20
+ ports :
21
+ - ' 4000:4000'
22
+ network_mode : host
23
+ volumes :
24
+ - ./notes:/opt/notes-app/notes
25
+ - ./public:/opt/notes-app/public
26
+ - ./scripts:/opt/notes-app/scripts
27
+ - ./server:/opt/notes-app/server
28
+ - ./src:/opt/notes-app/src
29
+ - ./credentials.json:/opt/notes-app/credentials.json
30
+
31
+ volumes :
32
+ db :
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -e
3
+
4
+ psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " --dbname " $POSTGRES_DB " << -EOSQL
5
+ CREATE ROLE notesadmin WITH LOGIN PASSWORD 'password';
6
+ ALTER ROLE notesadmin WITH SUPERUSER;
7
+ ALTER DATABASE notesapi OWNER TO notesadmin;
8
+
9
+ DROP TABLE IF EXISTS notes;
10
+ CREATE TABLE notes (
11
+ id SERIAL PRIMARY KEY,
12
+ created_at TIMESTAMP NOT NULL,
13
+ updated_at TIMESTAMP NOT NULL,
14
+ title TEXT,
15
+ body TEXT
16
+ );
17
+ EOSQL
0 commit comments