mirror of
https://github.com/zhigang1992/server-components-demo.git
synced 2026-04-29 09:45:37 +08:00
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM node:14.15.3
|
||||
|
||||
RUN mkdir -p /opt/notes-app
|
||||
WORKDIR /opt/notes-app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
12
README.md
12
README.md
@@ -36,6 +36,18 @@ Then open http://localhost:4000.
|
||||
|
||||
The app won't work until you set up the database, as described below.
|
||||
|
||||
<details>
|
||||
<summary>Setup with Docker</summary>
|
||||
<p>You can also start dev build of the app by using docker-compose.</p>
|
||||
<p>Make sure you have docker and docker-compose installed then run:</p>
|
||||
<pre><code>docker-compose up</code></pre>
|
||||
<h4>Running seed script</h4>
|
||||
<p>1. Run containers in the detached mode</p>
|
||||
<pre><code>docker-compose up -d</code></pre>
|
||||
<p>2. Run seed script</p>
|
||||
<pre><code>docker-compose exec notes-app npm run seed</code></pre>
|
||||
</details>
|
||||
|
||||
## DB Setup
|
||||
|
||||
This demo uses Postgres. First, follow its [installation link](https://wiki.postgresql.org/wiki/Detailed_installation_guides) for your platform.
|
||||
|
||||
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
environment:
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: admin
|
||||
POSTGRES_DB: notesapi
|
||||
ports:
|
||||
- '5432:5432'
|
||||
volumes:
|
||||
- ./scripts/init_db.sh:/docker-entrypoint-initdb.d/init_db.sh
|
||||
- db:/var/lib/postgresql/data
|
||||
|
||||
notes-app:
|
||||
build:
|
||||
context: .
|
||||
depends_on:
|
||||
- postgres
|
||||
ports:
|
||||
- '4000:4000'
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./notes:/opt/notes-app/notes
|
||||
- ./public:/opt/notes-app/public
|
||||
- ./scripts:/opt/notes-app/scripts
|
||||
- ./server:/opt/notes-app/server
|
||||
- ./src:/opt/notes-app/src
|
||||
- ./credentials.json:/opt/notes-app/credentials.json
|
||||
|
||||
volumes:
|
||||
db:
|
||||
17
scripts/init_db.sh
Normal file
17
scripts/init_db.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
CREATE ROLE notesadmin WITH LOGIN PASSWORD 'password';
|
||||
ALTER ROLE notesadmin WITH SUPERUSER;
|
||||
ALTER DATABASE notesapi OWNER TO notesadmin;
|
||||
|
||||
DROP TABLE IF EXISTS notes;
|
||||
CREATE TABLE notes (
|
||||
id SERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
title TEXT,
|
||||
body TEXT
|
||||
);
|
||||
EOSQL
|
||||
Reference in New Issue
Block a user