From 72158617a540f243ab9a0da0491ea6cf1a8bcd21 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 2 Dec 2019 21:04:59 -0500 Subject: [PATCH] docker compose files --- docker-compose.yml | 43 ++++++++++++++++++++++++ docker/app/Dockerfile | 23 +++++++++++++ docker/web/Dockerfile | 7 ++++ docker/web/nginx.conf | 76 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/app/Dockerfile create mode 100644 docker/web/Dockerfile create mode 100644 docker/web/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..af2a292d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3' +volumes: + postgres_data: {} + elastic_data: {} + +services: + app: + build: + context: . + dockerfile: ./docker/app/Dockerfile + environment: + - MIX_ENV=dev + working_dir: /srv/philomena + volumes: + - .:/srv/philomena + depends_on: + - postgres + - elasticsearch + - redis + + postgres: + image: postgres:12.1 + volumes: + - postgres_data:/var/lib/postgresql/data + + elasticsearch: + image: elasticsearch:6.8.5 + volumes: + - elastic_data:/var/lib/elasticsearch + + redis: + image: redis:5.0.7 + + web: + build: + context: . + dockerfile: ./docker/app/Dockerfile + volumes: + - .:/srv/philomena + depends_on: + - app + ports: + - '80:8080' \ No newline at end of file diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile new file mode 100644 index 00000000..b0042449 --- /dev/null +++ b/docker/app/Dockerfile @@ -0,0 +1,23 @@ +FROM elixir:1.9.4 + +RUN apt-get update; \ + apt-get -qq -y install apt-transport-https; \ + echo "deb https://deb.nodesource.com/node_12.x stretch main" >> /etc/apt/sources.list; \ + wget -qO - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -; \ + apt-get update; \ + apt-get -qq -y install build-essential git ffmpeg nodejs libmagic-dev libpng-dev gifsicle optipng libjpeg-progs librsvg2-bin; \ + cd /tmp; \ + git clone https://github.com/derpibooru/cli_intensities; \ + cd cli_intensities; \ + make install; \ + echo -e '#!/bin/sh\nrsvg-convert < "$1" -o "$2"\n' > /usr/local/bin/safe-rsvg-convert; \ + chmod +x /usr/local/bin/safe-rsvg-convert + +WORKDIR /srv/philomena +ADD . /srv/philomena + +RUN cd /srv/philomena; \ + mix local.hex --force; \ + mix deps.get; \ + cd assets; \ + npm install \ No newline at end of file diff --git a/docker/web/Dockerfile b/docker/web/Dockerfile new file mode 100644 index 00000000..d2895bad --- /dev/null +++ b/docker/web/Dockerfile @@ -0,0 +1,7 @@ +FROM nginx:1.17.6 +ENV APP_DIR /srv/philomena +WORKDIR $APP_DIR +COPY docker/web/nginx.conf /tmp/docker.nginx +RUN envsubst '$APP_DIR' < /tmp/docker.nginx /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker/web/nginx.conf b/docker/web/nginx.conf new file mode 100644 index 00000000..ef6d14cb --- /dev/null +++ b/docker/web/nginx.conf @@ -0,0 +1,76 @@ +upstream philomena { + server localhost:4000 fail_timeout=0; +} + +server { + listen 80 default; + listen [::]:80; + + root $APP_DIR/priv/static; + + location ~ ^/img/view/(.+)/([0-9]+).*\.([A-Za-z]+)$ { + expires max; + add_header Cache-Control public; + alias "$APP_DIR/priv/static/system/images/thumbs/$1/$2/full.$3"; + } + + location ~ ^/img/download/(.+)/([0-9]+).*\.([A-Za-z]+)$ { + add_header Content-Disposition "attachment"; + expires max; + add_header Cache-Control public; + alias "$APP_DIR/priv/static/system/images/thumbs/$1/$2/full.$3"; + } + + location ~ ^/img/(.+) { + expires max; + add_header Cache-Control public; + alias $APP_DIR/priv/static/system/images/thumbs/$1; + } + + location ~ ^/spns/(.+) { + expires max; + add_header Cache-Control public; + alias $APP_DIR/priv/static/system/images/adverts/$1; + } + + location ~ ^/avatars/(.+) { + expires max; + add_header Cache-Control public; + alias $APP_DIR/priv/static/system/images/avatars/$1; + } + + location ~ ^/media/(.+) { + expires max; + add_header Cache-Control public; + alias $APP_DIR/priv/static/system/images/$1; + } + + location / { + try_files $uri @proxy; + } + + location @proxy { + proxy_pass http://philomena; + proxy_redirect off; + + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + client_max_body_size 30m; + client_body_buffer_size 128k; + + proxy_connect_timeout 90; + proxy_send_timeout 90; + proxy_read_timeout 90; + + proxy_buffer_size 4k; + proxy_buffers 4 32k; + proxy_busy_buffers_size 64k; + proxy_temp_file_write_size 64k; + + # Configuration for Phoenix WS + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +}