diff --git a/.docker/.dockerignore b/.docker/.dockerignore new file mode 100644 index 00000000..93f13619 --- /dev/null +++ b/.docker/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 00000000..a325cf68 --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,37 @@ +### STAGE 1: Build ### +FROM node:9.11.1-alpine as builder +ARG branch=develop +ENV BRANCH=$branch +WORKDIR /src/app +RUN mkdir -p /src/app/coriolis +RUN mkdir -p /src/app/coriolis-data + +COPY ./coriolis/ /src/app/coriolis +COPY ./coriolis-data/ /src/app/coriolis-data + +RUN apk update +RUN apk add git + +RUN npm i -g npm + +# Set up coriolis-data +WORKDIR /src/app/coriolis-data +RUN git fetch --all +RUN git reset --hard origin/$BRANCH +RUN npm install --no-package-lock +RUN npm start + +WORKDIR /src/app/coriolis +RUN git fetch --all +RUN git reset --hard origin/$BRANCH +RUN rm -rf node_modules/ +RUN npm install --no-package-lock +RUN npm run build + + +### STAGE 2: Production Environment ### +FROM nginx:1.13.12-alpine as web +COPY nginx.conf /etc/nginx/nginx.conf +COPY --from=builder /src/app/coriolis/build /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 00000000..222bbbca --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,39 @@ +version: '2.2' + +services: + coriolis_prod: + build: + dockerfile: coriolis/.docker/Dockerfile + context: ../.. + environment: + BRANCH: master + restart: always + networks: + - coriolis_web + - default + labels: + - "traefik.docker.network=coriolis_coriolis_web" + - "traefik.enable=true" + - "traefik.basic.frontend.rule=Host:coriolis.io,coriolis.edcd.io" + - "traefik.basic.port=80" + - "traefik.basic.protocol=http" + + coriolis_dev: + build: + dockerfile: coriolis/.docker/Dockerfile + context: ../.. + restart: always + environment: + BRANCH: feature/docker-deployment + networks: + - coriolis_web + - default + labels: + - "traefik.docker.network=coriolis_coriolis_web" + - "traefik.enable=true" + - "traefik.basic.frontend.rule=Host:beta.coriolis.io,beta.coriolis.edcd.io" + - "traefik.basic.port=80" + - "traefik.basic.protocol=http" + +networks: + coriolis_web: diff --git a/.docker/nginx.conf b/.docker/nginx.conf new file mode 100644 index 00000000..cd82ec07 --- /dev/null +++ b/.docker/nginx.conf @@ -0,0 +1,38 @@ +user nobody; +worker_processes auto; # it will be determinate automatically by the number of core + +error_log /var/log/nginx/error.log warn; +#pid /var/run/nginx.pid; # it permit you to use /etc/init.d/nginx reload|restart|stop|start + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile on; + access_log /var/log/nginx/access.log; + keepalive_timeout 3000; + server { + listen 80; + listen [::]:80; + + index index.html; + + server_name localhost; + root /src/app/coriolis/build; + + location ~* \.(?:manifest|appcache|html?|xml|json|css|js|map|jpg|jpeg|gif|png|ico|svg|eot|ttf|woff|woff2)$ { + expires -1; + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Credentials true; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; + add_header Access-Control-Allow-Headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + access_log off; + } + location / { + try_files $uri $uri/ /index.html =404; + } + } +}