Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

adds dockerfiles #538 #539

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docker/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Build base images:

docker-compose build


For development:

docker-compose -f docker-compose-dev.yml build
docker-compose -f docker-compose-dev.yml up

Go to http://localhost:1337/


For production:

docker-compose -f docker-compose-prod.yml build
docker-compose -f docker-compose-prod.yml up

Go to http://localhost/
19 changes: 19 additions & 0 deletions docker/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.2"
services:
react:
image: react-dev
volumes:
- type: bind
source: ../
target: /code
- type: bind
source: ./node_modules
target: /code/node_modules
build:
context: ../
dockerfile: docker/react/Dockerfile-dev
ports:
- "1337:1337"
- "7331:7331"
environment:
- HOST=localhost
33 changes: 33 additions & 0 deletions docker/docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.2"
services:
react:
image: react-prod
build:
context: ../
dockerfile: docker/react/Dockerfile-prod
ports:
- "1337"
environment:
- HOST=localhost
- PORT=1337
- REACT_COPY_STATIC=on
- INSTANCES=1
command: /usr/local/bin/pm2-docker start react.config.js
volumes:
- type: volume
source: static
target: /static
nginx:
image: nginx:1.13.6-alpine
command: sh -c "cp /etc/nginx/conf.d/mysite.template /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
volumes:
- type: bind
source: ./nginx/mysite.template
target: /etc/nginx/conf.d/mysite.template
- type: volume
source: static
target: /static
ports:
- "80:80"
volumes:
static:
7 changes: 7 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3.2"
services:
react:
image: react-base
build:
context: ../
dockerfile: docker/react/Dockerfile
32 changes: 32 additions & 0 deletions docker/nginx/mysite.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# mysite_nginx.conf

upstream react {
server react:1337;
}

# configuration of the server
server {
# the port your site will be served on
listen 0.0.0.0:80;
# the domain name it will serve for
server_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;

# max upload size
client_max_body_size 75M; # adjust to taste

location /client {
alias /static;
}

# Finally, send all non-media requests to the react server.
location / {
proxy_pass http://react;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_redirect off;
}
}

17 changes: 17 additions & 0 deletions docker/react/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:8.9.0-alpine

RUN mkdir /code

COPY package.json /code/

WORKDIR /code

RUN /usr/local/bin/npm install -g babel-cli

RUN /usr/local/bin/npm install --production

RUN cp -R node_modules /node_modules.production

RUN /usr/local/bin/npm install

RUN mv node_modules /node_modules.build
17 changes: 17 additions & 0 deletions docker/react/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM react-base

RUN mkdir /build

COPY package.json /build/package.json

WORKDIR /build

RUN /usr/local/bin/npm install -g cross-env

COPY docker/react/docker-entrypoint-dev.sh /docker-entrypoint.sh

CMD ["/usr/local/bin/npm", "run", "develop"]

EXPOSE 1337 7331

ENTRYPOINT ["/docker-entrypoint.sh"]
36 changes: 36 additions & 0 deletions docker/react/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM react-base

COPY / /code/

WORKDIR /code

RUN ls

RUN rm -rf node_modules

# Copy development node_modules into place
RUN mv /node_modules.build node_modules

# Build code and remove source
RUN /usr/local/bin/npm run build && \
mv build ../ && \
rm -rf * && \
mv ../build ./ && \
rm -rf ../build/

# Copy production node_modules into place
RUN mv /node_modules.production node_modules

RUN /usr/local/bin/npm uninstall -g babel-cli

RUN /usr/local/bin/npm install -g pm2

COPY docker/react/react.config.js /code/

COPY docker/react/docker-entrypoint.sh /docker-entrypoint.sh

CMD ["/usr/local/bin/pm2-docker", "start", "react.config.js"]

EXPOSE 80 1337

ENTRYPOINT ["/docker-entrypoint.sh"]
14 changes: 14 additions & 0 deletions docker/react/docker-entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -e

if [ -z "`find /code/node_modules/ -type f`" ]; then
cp -R /build/node_modules/* /code/node_modules/
fi

if [ "x$REACT_NPM_INSTALL" = 'xon' ]; then
cd /code && /usr/local/bin/npm install
fi

cd /code

exec "$@"
10 changes: 10 additions & 0 deletions docker/react/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -e

if [ "x$REACT_COPY_STATIC" = 'xon' ]; then
cp -R /code/build/client/* /static/
fi

cd /code

exec "$@"
16 changes: 16 additions & 0 deletions docker/react/react.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
apps: [
{
name: "server",
script: "./build/server/index.js",
watch: true,
instances: process.env.INSTANCES
? parseInt(process.env.INSTANCES, 10)
: 1,
exec_mode: "cluster",
env: {
NODE_ENV: "production"
}
}
]
};