mirror of
https://github.com/zhigang1992/server-components-demo.git
synced 2026-01-12 09:33:54 +08:00
Fixes docker-compose & pg initialization (#10)
* Fixes docker-compose & pg initialization - ./scripts/init_db.sh is not executable (/bin/bash: bad interpreter: Permission denied) - same script fails because user is already created, only table creation is necessary. * Actually fix docker-compose development workflow * Incorporate PR feedback * Remove credentials.json
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
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"]
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT [ "npm", "run" ]
|
||||
CMD [ "start" ]
|
||||
|
||||
7
credentials.js
Normal file
7
credentials.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
database: 'notesapi',
|
||||
user: 'notesadmin',
|
||||
password: 'password',
|
||||
port: '5432',
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"database": "notesapi",
|
||||
"user": "notesadmin",
|
||||
"password": "password",
|
||||
"port": "5432"
|
||||
}
|
||||
@@ -19,14 +19,15 @@ services:
|
||||
- postgres
|
||||
ports:
|
||||
- '4000:4000'
|
||||
network_mode: host
|
||||
environment:
|
||||
DB_HOST: postgres
|
||||
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
|
||||
- ./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.js:/opt/notes-app/credentials.js
|
||||
|
||||
volumes:
|
||||
db:
|
||||
|
||||
20
scripts/init_db.sh
Normal file → Executable file
20
scripts/init_db.sh
Normal file → Executable file
@@ -2,16 +2,12 @@
|
||||
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
|
||||
);
|
||||
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
|
||||
|
||||
@@ -13,7 +13,7 @@ const path = require('path');
|
||||
const {Pool} = require('pg');
|
||||
const {readdir, unlink, writeFile} = require('fs/promises');
|
||||
const startOfYear = require('date-fns/startOfYear');
|
||||
const credentials = require('../credentials.json');
|
||||
const credentials = require('../credentials');
|
||||
|
||||
const NOTES_PATH = './notes';
|
||||
const pool = new Pool(credentials);
|
||||
|
||||
@@ -29,7 +29,7 @@ const React = require('react');
|
||||
const ReactApp = require('../src/App.server').default;
|
||||
|
||||
// Don't keep credentials in the source tree in a real app!
|
||||
const pool = new Pool(require('../credentials.json'));
|
||||
const pool = new Pool(require('../credentials'));
|
||||
|
||||
const PORT = 4000;
|
||||
const app = express();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Pool} from 'react-pg';
|
||||
import credentials from '../credentials.json';
|
||||
import credentials from '../credentials';
|
||||
|
||||
// Don't keep credentials in the source tree in a real app!
|
||||
export const db = new Pool(credentials);
|
||||
|
||||
Reference in New Issue
Block a user