Skip to content

Commit

Permalink
Merge pull request i-barysiuk#8 from i-barysiuk/F7/Prod_Dev_Env
Browse files Browse the repository at this point in the history
Prod&Dev Environment
  • Loading branch information
mishagitwork authored Jul 18, 2019
2 parents 760331f + b8d3a30 commit 0232ae9
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/db
/db
/package.json
npm-debug.log
17 changes: 0 additions & 17 deletions app/Dockerfile

This file was deleted.

48 changes: 48 additions & 0 deletions app/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
server_tokens off;

include /etc/nginx/mime.types;
default_type text/javascript;

access_log off;
error_log /var/log/nginx/error.log;

gzip on;
gzip_min_length 100;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

client_max_body_size 8M;
server {
listen 80;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}

location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

}
}
11 changes: 10 additions & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"cross-env": "^5.2.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "cross-env NODE_ENV=production react-scripts build",
"build:uat": "cross-env NODE_ENV=test react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
14 changes: 14 additions & 0 deletions app/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Stage 1 - the build process
FROM node:latest as build-deps
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . ./
RUN npm run build

# Stage 2 - the production environment
FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build-deps /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
14 changes: 14 additions & 0 deletions app/uat.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Stage 1 - the build process
FROM node:latest as build-deps
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . ./
RUN npm run build:uat

# Stage 2 - the production environment
FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build-deps /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
36 changes: 36 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.7"

services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: trytofindme
volumes:
- ./db/db_prod:/var/lib/postgresql/data

adminer:
image: adminer
restart: always
ports:
- 8002:8080
depends_on:
- db

app:
build:
context: ./app
dockerfile: prod.Dockerfile
restart: always
ports:
- 8000:80

server:
build:
context: ./server
dockerfile: prod.Dockerfile
restart: always
ports:
- 8001:3000
depends_on:
- db
32 changes: 32 additions & 0 deletions docker-compose.uat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.7"

services:
db_uat:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: trytofindme
volumes:
- ./db/db_uat:/var/lib/postgresql/data

adminer_uat:
image: adminer
restart: always
ports:
- 8012:8080

app_uat:
build:
context: ./app
dockerfile: uat.Dockerfile
restart: always
ports:
- 8010:3000

server_uat:
build:
context: ./server
dockerfile: uat.Dockerfile
restart: always
ports:
- 8011:3000
28 changes: 0 additions & 28 deletions docker-compose.yml

This file was deleted.

28 changes: 28 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"description": "",
"main": "server.js",
"dependencies": {
"cross-env": "^5.2.0",
"express": "^4.17.1",
"nodemon": "^1.19.1"
},
"devDependencies": {},
"scripts": {
"dev": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
"start": "node server.js",
"start:uat": "cross-env node server.js"
},
"author": "",
"license": "ISC"
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile → server/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ COPY . .

EXPOSE 3000

CMD sleep 15s && npm start
CMD npm start
12 changes: 12 additions & 0 deletions server/uat.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:latest
WORKDIR /usr/src/app

COPY ./package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD npm run start:uat

0 comments on commit 0232ae9

Please sign in to comment.