Route docs requests to Phoenix

This commit is contained in:
Marcin Kulik 2017-05-12 18:52:42 +02:00
parent 1e130fb159
commit faaf28b913
4 changed files with 62 additions and 3 deletions

View File

@ -10,11 +10,15 @@ RUN apt-get update && \
apt-get install -y wget software-properties-common apt-transport-https && \
add-apt-repository ppa:brightbox/ruby-ng && \
echo "deb https://deb.nodesource.com/$NODE_VERSION $DISTRO main" >/etc/apt/sources.list.d/nodesource.list && \
echo "deb https://packages.erlang-solutions.com/ubuntu $DISTRO contrib" >/etc/apt/sources.list.d/esl.list && \
wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
wget --quiet -O - https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | apt-key add - && \
apt-get update && \
apt-get install -y \
autoconf \
build-essential \
elixir \
esl-erlang \
git-core \
libfontconfig1 \
libpq-dev \
@ -35,9 +39,15 @@ RUN apt-get update && \
# libfontconfig1 for PhantomJS
# ttf-bitstream-vera for a2png
# install Bundler
# install Bundler and SASS
RUN gem install bundler
RUN gem install bundler sass
# install Hex and Rebar
ENV LANG=C.UTF-8
RUN mix local.hex --force && mix local.rebar --force
# install PhantomJS
@ -77,10 +87,13 @@ ARG LEIN_ROOT=yes
# install asciinema
ENV RAILS_ENV "production"
ENV MIX_ENV "prod"
RUN mkdir -p /app/tmp /app/log
WORKDIR /app
# install gems
COPY Gemfile* /app/
RUN bundle install --deployment --without development test --jobs 10 --retry 5
@ -104,6 +117,16 @@ COPY src /app/src
COPY resources /app/resources
RUN lein uberjar
# install hex packages
COPY mix.* /app/
RUN mix deps.get --only prod
# install brunch & co
COPY package.json /app/
RUN npm install
# copy the rest of the source code
COPY . /app
@ -115,10 +138,18 @@ ENV REDIS_URL "redis://redis:6379"
RUN cd src && make
# compile assets
# compile assets with assets pipeline
RUN bundle exec rake assets:precompile
# compile assets with brunch and generate digest file
RUN node_modules/brunch/bin/brunch build --production && mix phoenix.digest
# compile Elixir app
RUN mix compile
# install smtp configuration
COPY docker/asciinema.yml /app/config/asciinema.yml
@ -147,3 +178,4 @@ CMD ["/usr/bin/supervisord"]
EXPOSE 80
EXPOSE 3000
EXPOSE 4000
EXPOSE 5000

View File

@ -56,6 +56,7 @@ services:
env_file: .env.production
ports:
- "3000:80"
- "5000:5000"
volumes:
- ./uploads:/app/uploads
- ./log:/app/log

View File

@ -2,6 +2,10 @@ upstream rails-server {
server 127.0.0.1:3000 fail_timeout=0;
}
upstream phoenix-server {
server 127.0.0.1:5000 fail_timeout=0;
}
upstream clj-server {
server 127.0.0.1:4000 fail_timeout=0;
}
@ -16,6 +20,10 @@ server {
client_max_body_size 16m;
location ~ ^/(phoenix/|css/|js/|images/|fonts/|docs/?) {
try_files /maintenance.html $uri/index.html $uri.html $uri @phoenix;
}
location ~ ^/a/[^.]+\.(json|png)$ {
try_files $uri $uri/index.html $uri.html @clj;
}
@ -42,6 +50,15 @@ server {
error_page 500 502 504 /500.html; # Rails error pages
}
location @phoenix {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_pass http://phoenix-server;
proxy_redirect off;
}
location @clj {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View File

@ -16,6 +16,15 @@ stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:phoenix]
command=mix phoenix.server
directory=/app
environment=PORT=5000
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:clj]
command=/app/start.sh
directory=/app