Skip to content

Commit

Permalink
Set production docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
Wysogota committed Aug 25, 2022
1 parent 0598855 commit 2db9ff5
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 21 deletions.
1 change: 1 addition & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
./node_modules
yarn.lock
2 changes: 1 addition & 1 deletion client/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_DOMAIN=localhost
REACT_APP_SERVER_PORT=3000
REACT_APP_SERVER_PORT=80
ESLINT_NO_DEV_ERRORS=true
25 changes: 25 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:16.15.1-alpine3.15 as build-stage

ARG NODE_ENV="production"

RUN mkdir -p ./client

WORKDIR /client

COPY package.json ./

# COPY yarn.lock ./

RUN yarn install

COPY . .

RUN npm rebuild node-sass

RUN yarn run build

FROM nginx:1.23.1-alpine

COPY --from=build-stage /client/build /usr/share/nginx/html

COPY ./nginx.conf /etc/nginx/conf.d/default.conf
2 changes: 1 addition & 1 deletion client/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ RUN yarn install

RUN mkdir -p node_modules/.cache && chmod -R 777 node_modules/.cache

CMD npm start
CMD yarn start
11 changes: 11 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
listen 80;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}

include /etc/nginx/extra-conf.d/*.conf;
}
64 changes: 64 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '3'
services:

front-prod:
build:
context: ./client
dockerfile: Dockerfile
environment:
NODE_ENV: production
depends_on:
- server-prod
volumes:
- ./client:/client
- /client/node_modules
networks:
- frontend
ports:
- "3000:80"

server-prod:
build:
context: ./server
dockerfile: Dockerfile
environment:
NODE_ENV: production
ports:
- "80:80"
depends_on:
- db-prod
- mongo-prod
networks:
- frontend
- backend
volumes:
- ./server:/server
- /server/node_modules

mongo-prod:
image: mongo:latest
networks:
- backend
ports:
- "27017:27017"

db-prod:
image: postgres:14.3-alpine
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=mangoose-prod
networks:
- backend
ports:
- "5432:5432"

volumes:
server-prod:


networks:
frontend:
driver: bridge
backend:
driver: bridge
1 change: 1 addition & 0 deletions server/.adminjs/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!function(){"use strict";AdminJS.UserComponents={}}();
4 changes: 2 additions & 2 deletions server/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DOMAIN=localhost
PORT=3000
CLIENT_PORT=5000
PORT=80
CLIENT_PORT=3000
SALT_ROUNDS=4
ACCESS_TOKEN_SECRET=eyJpc3MiOiJhc2RhZGEiLCJpYXQiOjE2NTgzOTk3MTUsImV4cCI6MTY4OTkzNTcx
ACCESS_TOKEN_TIME=1h
Expand Down
1 change: 0 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ yarn-debug.log*
yarn-error.log*

# .env
/uploads
23 changes: 23 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:16.15.1-alpine3.15

ARG NODE_ENV="production"

RUN mkdir /server

WORKDIR /server

COPY package.json ./

COPY yarn.lock ./

RUN yarn global add sequelize-cli

RUN yarn global add @babel/core @babel/cli

RUN yarn install

COPY . .

RUN yarn run build

CMD ./start.sh
4 changes: 1 addition & 3 deletions server/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ RUN yarn global add sequelize-cli

RUN yarn install

RUN mkdir -p node_modules/.cache && chmod -R 777 node_modules/.cache

COPY . .

EXPOSE 3000

CMD ./start.sh
CMD ./start-dev.sh
2 changes: 1 addition & 1 deletion server/config/mongoConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"production": {
"database": "mangoose-prod",
"host": "mongo-dev",
"host": "mongo-prod",
"port": 27017
}
}
8 changes: 4 additions & 4 deletions server/config/postgresConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"test": {
"username": "postgres",
"password": "admin",
"password": "password",
"database": "mangoose-test",
"host": "db-dev",
"host": "db-test",
"dialect": "postgres",
"operatorsAliases": "Op"
},
"production": {
"username": "postgres",
"password": "admin",
"password": "password",
"database": "mangoose-prod",
"host": "db-dev",
"host": "db-prod",
"dialect": "postgres",
"operatorsAliases": "Op"
}
Expand Down
7 changes: 5 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"description": "",
"main": "src/server.js",
"scripts": {
"start": "nodemon server.js"
"start": "nodemon server.js",
"build": "babel src -d build"
},
"keywords": [],
"author": "Wysogota",
"license": "ISC",
"devDependencies": {
"cors": "^2.8.5",
"@babel/cli": "^7.18.10",
"@babel/core": "^7.18.13",
"nodemon": "^2.0.16",
"sequelize-cli": "^6.4.1"
},
Expand All @@ -23,6 +25,7 @@
"axios": "^0.27.2",
"bcrypt": "^5.0.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-formidable": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const http = require('http');
require('./mongoose');
const app = require('./app');
const server = http.createServer(app);
const PORT = process.env.PORT || 3000;
const PORT = process.env.PORT || 80;

server.listen(PORT, () => console.log('Server started on port = ' + PORT));
15 changes: 15 additions & 0 deletions server/start-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# Run Sequalize's migrations.
echo "-----> Running application migrations"
npx sequelize db:migrate
echo ""

# Run Sequalize's seeds.
echo "-----> Running application seeds"
npx sequelize db:seed:all
echo "<----- Seeds created"

echo "-----> Starting server"
yarn start
echo ""
2 changes: 1 addition & 1 deletion server/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ npx sequelize db:seed:all
echo "<----- Seeds created"

echo "-----> Starting server"
yarn start
node ./build/server.js
echo ""
Loading

0 comments on commit 2db9ff5

Please sign in to comment.