diff --git a/Dockerfile b/Dockerfile index b550d04..a765c4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 359b3bb..f046f0d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,6 +56,7 @@ services: env_file: .env.production ports: - "3000:80" + - "5000:5000" volumes: - ./uploads:/app/uploads - ./log:/app/log diff --git a/docker/nginx/asciinema.conf b/docker/nginx/asciinema.conf index 2b8c371..557c70c 100644 --- a/docker/nginx/asciinema.conf +++ b/docker/nginx/asciinema.conf @@ -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; diff --git a/docker/supervisor/asciinema.conf b/docker/supervisor/asciinema.conf index 0dd20d4..1b2e5e2 100644 --- a/docker/supervisor/asciinema.conf +++ b/docker/supervisor/asciinema.conf @@ -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