1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

separate nginx and app in docker

This commit is contained in:
Peng DU 2016-09-06 12:19:47 +02:00
parent c384cf9b56
commit b3ae59f426
6 changed files with 38 additions and 42 deletions

View File

@ -1,18 +1,11 @@
FROM ruby:2.3
MAINTAINER peng@sleede.com
# cf: nginx Dockerfile : https://github.com/nginxinc/docker-nginx
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
RUN echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list
ENV NGINX_VERSION 1.9.7-1~jessie
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && \
apt-get install -y \
nginx=${NGINX_VERSION} \
nodejs \
supervisor
@ -28,16 +21,6 @@ RUN bundle install --binstubs
# Clean up APT when done.
#RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Nginx
# Remove the default site
RUN rm /etc/nginx/conf.d/default.conf
# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log
# Web app
RUN mkdir -p /usr/src/app
RUN mkdir -p /usr/src/app/config
@ -58,13 +41,14 @@ COPY . /usr/src/app
# Volumes
VOLUME /usr/src/app/invoices
VOLUME /usr/src/app/exports
VOLUME /usr/src/app/public
VOLUME /usr/src/app/public/uploads
VOLUME /usr/src/app/public/assets
VOLUME /var/log/supervisor
# Expose port 80 and ssl 443 to the Docker host, so we can access it
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 80 443
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by

View File

@ -236,23 +236,30 @@ docker run --rm \
```bash
docker run --restart=always -d --name=fabmanager \
-p 80:80 \
-p 443:443 \
--link=fabmanager-postgres:postgres \
--link=fabmanager-redis:redis \
--link=fabmanager-elastic:elasticsearch \
-e RAILS_ENV=production \
-e RACK_ENV=production \
--env-file /home/core/fabmanager/config/env \
-v /home/core/fabmanager/config/nginx:/etc/nginx/conf.d \
-v /home/core/fabmanager/public/assets:/usr/src/app/public/assets \
-v /home/core/fabmanager/public/uploads:/usr/src/app/public/uploads \
-v /home/core/fabmanager/invoices:/usr/src/app/invoices \
-v /home/core/fabmanager/exports:/usr/src/app/exports \
-v /home/core/fabmanager/plugins:/usr/src/app/plugins \
-v /home/core/fabmanager/log:/var/log/supervisor \
-v /home/core/fabmanager/letsencrypt/etc:/etc/letsencrypt \
sleede/fab-manager
docker run --restart=always -d --name=nginx \
-p 80:80 \
-p 443:443 \
--link=fabmanager:fabmanager \
-v /home/core/fabmanager/config/nginx:/etc/nginx/conf.d \
-v /home/core/fabmanager/letsencrypt/etc:/etc/letsencrypt \
-v /home/core/fabmanager/log:/var/log/nginx \
--volumes-from fabmanager:ro
nginx:1.9
```

View File

@ -5,40 +5,50 @@ services:
environment:
RAILS_ENV: production
RACK_ENV: production
ports:
- "80:80"
- "443:443"
env_file:
- /home/core/fabmanager/config/env
volumes:
- /home/core/fabmanager/config/nginx:/etc/nginx/conf.d
- /home/core/fabmanager/public/assets:/usr/src/app/public/assets
- /home/core/fabmanager/public/uploads:/usr/src/app/public/uploads
- /home/core/fabmanager/invoices:/usr/src/app/invoices
- /home/core/fabmanager/exports:/usr/src/app/exports
- /home/core/fabmanager/log:/var/log/supervisor
- /home/core/fabmanager/plugins:/usr/src/app/plugins
- /home/core/fabmanager/letsencrypt/etc:/etc/letsencrypt
depends_on:
- fabmanager-postgres
- fabmanager-redis
- fabmanager-elastic
- postgres
- redis
- elasticsearch
restart: always
fabmanager-postgres:
postgres:
image: postgres:9.4
volumes:
- /home/core/fabmanager/postgresql:/var/lib/postgresql/data
restart: always
fabmanager-elastic:
elasticsearch:
image: elasticsearch:1.7
volumes:
- /home/core/fabmanager/elasticsearch:/usr/share/elasticsearch/data
restart: always
fabmanager-redis:
redis:
image: redis:3.0
volumes:
- /home/core/fabmanager/redis:/data
restart: always
nginx:
image: nginx:1.9
ports:
- "80:80"
- "443:443"
volumes:
- /home/core/fabmanager/config/nginx:/etc/nginx/conf.d
- /home/core/fabmanager/letsencrypt/etc:/etc/letsencrypt
- /home/core/suez-efw/log:/var/log/nginx
volumes_form:
- fabmanager:ro
links:
- fabmanager:fabmanager
restart: always

View File

@ -1,5 +1,5 @@
upstream puma {
server unix:/usr/src/app/tmp/sockets/fabmanager.sock fail_timeout=0;
server fabmanager:3000;
}
server {

View File

@ -1,5 +1,5 @@
upstream puma {
server unix:/usr/src/app/tmp/sockets/fabmanager.sock fail_timeout=0;
server fabmanager:3000;
}
server {

View File

@ -14,13 +14,8 @@ childlogdir=/var/log/supervisor/ ; where child log files will liv
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
[program:nginx]
command=nginx -g "daemon off;"
stderr_logfile=/var/log/supervisor/nginx-stderr.log
stdout_logfile=/var/log/supervisor/nginx-stdout.log
[program:app]
command=bundle exec puma -b unix:///usr/src/app/tmp/sockets/fabmanager.sock --pidfile /usr/src/app/tmp/pids/fabmanager.pid
command=bundle exec rails s puma -p 3000 -b 0.0.0.0
stderr_logfile=/var/log/supervisor/app-stderr.log
stdout_logfile=/var/log/supervisor/app-stdout.log