From 7bff3dcb0d10f1bc47f0f2163e0217cc5ee3d08a Mon Sep 17 00:00:00 2001 From: sundowndev Date: Mon, 3 Sep 2018 17:53:26 +0200 Subject: [PATCH] Docker configuration --- .dockerignore | 11 +++++++ Dockerfile | 33 +++++++++++++++++++++ docker-compose.yaml | 48 ++++++++++++------------------- docker/nginx/Dockerfile | 23 +++++++++++++++ docker/nginx/docker-entrypoint.sh | 4 +++ docker/nginx/sites-enabled/app | 17 +++++++++++ processes.json | 9 ++++++ 7 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 .dockerignore create mode 100644 docker/nginx/Dockerfile create mode 100644 docker/nginx/docker-entrypoint.sh create mode 100644 docker/nginx/sites-enabled/app create mode 100644 processes.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f50512 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +**/*.log +**/._* +**/.DS_Store +**/.gitignore +**/.gitattributes +**/Thumbs.db +.dockerignore +Dockerfile +docker-compose.yaml +/node_modules/ +/npm-debug.log/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e69de29..72d9cb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Set the base image to Ubuntu +FROM ubuntu:14.04 + +MAINTAINER Adrien Desbiaux + +# Install Node.js and other dependencies +RUN apt-get update && \ + apt-get -y install curl && \ + apt-get -y install git && \ + apt-get -y install wget && \ + curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - && \ + apt-get install --yes nodejs + +# Install PM2 +RUN npm install -g pm2 + +RUN mkdir -p /var/www/app + +# Define working directory +WORKDIR /var/www/app + +ADD . /var/www/app + +RUN npm install + +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker/nginx/docker-entrypoint.sh"] + +# Expose port +EXPOSE 3000 + +# Run app +CMD pm2 start --no-daemon processes.json \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index fd6c443..44e8302 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,30 +1,18 @@ -version: '3' - -services: - app: - build: - context: . - dockerfile: ./Dockerfile - - nginx: - build: - context: . - dockerfile: ./Dockerfile.nginx - depends_on: - - app - volumes: - # Comment out the next line in production - - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro - - ./dist:/srv/app:ro - ports: - - '3000:80' - - # This HTTP/2 proxy is not secure: it should only be used in dev - h2-proxy: - build: - context: . - dockerfile: ./Dockerfile.h2-proxy - volumes: - - ./docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro - ports: - - '443:443' \ No newline at end of file +nginx: + build: ./docker/nginx + links: + - app1:app1 + ports: + - "8000:80" + - "443:443" + volumes: + - /etc/nginx/psw:/etc/nginx/psw + - /etc/nginx/ssl:/etc/nginx/ssl +app1: + build: . + ports: + - "3000" + volumes: + - /tmp:/tmp + environment: + - MODE=dev \ No newline at end of file diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..5155a75 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,23 @@ +# Set nginx base image +FROM nginx + +# File Author / Maintainer +MAINTAINER Adrien Desbiaux + +COPY docker-entrypoint.sh / +ENTRYPOINT ["./docker-entrypoint.sh"] + +# Copy custom configuration file from the current directory +COPY nginx.conf /etc/nginx/nginx.conf + +VOLUME ["/etc/nginx/ssl", "/etc/nginx/psw"] + +# Append "daemon off;" to the beginning of the configuration +# in order to avoid an exit of the container +RUN echo "daemon off;" >> /etc/nginx/nginx.conf + +# Expose ports +EXPOSE 443 + +# Define default command +CMD service nginx start \ No newline at end of file diff --git a/docker/nginx/docker-entrypoint.sh b/docker/nginx/docker-entrypoint.sh new file mode 100644 index 0000000..976f008 --- /dev/null +++ b/docker/nginx/docker-entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e +sed -i s/localhost/localhost/g /etc/nginx/nginx.conf +cat /etc/nginx/nginx.conf +exec "$@" \ No newline at end of file diff --git a/docker/nginx/sites-enabled/app b/docker/nginx/sites-enabled/app new file mode 100644 index 0000000..c04e269 --- /dev/null +++ b/docker/nginx/sites-enabled/app @@ -0,0 +1,17 @@ +server { + listen 80; ## listen for ipv4; this line is default and implied + listen [::]:80 default ipv6only=on; ## listen for ipv6 + access_log /var/log/nginx/nodejs_project.log; + charset utf-8; + + location /public { + alias /src/app/public; + } + + location / { + proxy_pass http://server:3000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/processes.json b/processes.json new file mode 100644 index 0000000..858d4c6 --- /dev/null +++ b/processes.json @@ -0,0 +1,9 @@ +{ + "apps" : [{ + "merge_logs" : true, + "name" : "worker1", + "out_file" : "/tmp/workers.log", + "log_date_format" : "MM/DD/YYYY HH:mm:ss", + "script" : "lib/worker.js" + }] +} \ No newline at end of file