commit a1f1862ba28af66fefeaddaebd1187c0ba64a024 Author: Andrew Dolgov Date: Fri Nov 15 15:51:55 2019 +0300 initial diff --git a/.env b/.env new file mode 100644 index 0000000..429bba0 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e17501 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# A primitive set of scripts to deploy tt-rss via docker-compose + +The idea is to provide tt-rss working (and updating) out of the box +with minimal fuss. + +The general outline of the configuration is as follows: + +- three linked containers (frontend: nginx, database: pgsql, application: php/fpm) +- nginx has its http port exposed to the outside +- feed updating is done via embedded cron job, every 15 minutes +- tt-rss source updates from git master repository on container restart +- schema is installed automatically on first startup +- SSL termination not included, you use a sidecar container for that + +Post your feedback here: + +https://community.tt-rss.org/t/docker-compose-tt-rss/2894 + diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..8ec1c3b --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.9 +EXPOSE 9000/tcp + +RUN apk add --no-cache php7 php7-fpm \ + php7-pdo php7-gd php7-pgsql php7-pdo_pgsql php7-mbstring \ + php7-intl php7-xml php7-curl php7-session \ + php7-dom php7-fileinfo php7-json \ + git postgresql-client dcron sudo + +ADD startup.sh / +ADD scripts/update /etc/periodic/15min/ + +RUN sed -i.bak 's/^listen = 127.0.0.1:9000/listen = 9000/' /etc/php7/php-fpm.d/www.conf + +CMD /startup.sh diff --git a/app/scripts/update b/app/scripts/update new file mode 100755 index 0000000..e311565 --- /dev/null +++ b/app/scripts/update @@ -0,0 +1,7 @@ +#!/bin/sh + +DST_DIR=/var/www/html/tt-rss + +if [ -s $DST_DIR/config.php ]; then + sudo -u nobody $DST_DIR/update.php --feeds +fi diff --git a/app/startup.sh b/app/startup.sh new file mode 100755 index 0000000..46100c5 --- /dev/null +++ b/app/startup.sh @@ -0,0 +1,44 @@ +#!/bin/sh -ex + +OWNER=nobody +DST_DIR=/var/www/html/tt-rss +SRC_REPO=https://git.tt-rss.org/fox/tt-rss.git + +export PGPASSWORD=$DB_PASS + +PSQL="psql -q -h $DB_HOST -U $DB_USER $DB_NAME" + +if [ ! -d $DST_DIR ]; then + mkdir -p $DST_DIR + git clone $SRC_REPO $DST_DIR +else + cd $DST_DIR && git pull origin master +fi + +chown -R $OWNER $DST_DIR +chmod +x /etc/periodic/15min/* + +for d in cache lock feed-icons; do + chmod -R 777 $DST_DIR/$d +done + +if ! $PSQL -c 'select * from ttrss_version'; then + $PSQL < /var/www/html/tt-rss/schema/ttrss_schema_pgsql.sql +fi + +if [ ! -s $DST_DIR/config.php ]; then + SELF_URL_PATH=$(echo $SELF_URL_PATH | sed -e 's/[\/&]/\\&/g') + + sed \ + -e "s/define('DB_HOST'.*/define('DB_HOST','$DB_HOST');/" \ + -e "s/define('DB_USER'.*/define('DB_USER','$DB_USER');/" \ + -e "s/define('DB_NAME'.*/define('DB_NAME','$DB_NAME');/" \ + -e "s/define('DB_PASS'.*/define('DB_PASS','$DB_PASS');/" \ + -e "s/define('SELF_URL_PATH'.*/define('SELF_URL_PATH','$SELF_URL_PATH');/" \ + < $DST_DIR/config.php-dist > $DST_DIR/config.php +fi + +crond & + +exec /usr/sbin/php-fpm7 -F + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7768eed --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3' + +# set database password in .env +# please don't use quote (') or (") symbols in variables + +services: + db: + image: postgres:12-alpine + restart: unless-stopped + volumes: + - db:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_USER=${POSTGRES_USER} + + app: + build: ./app + restart: unless-stopped + environment: + - DB_TYPE=pgsql + - DB_HOST=db + - DB_NAME=${POSTGRES_USER} + - DB_USER=${POSTGRES_USER} + - DB_PASS=${POSTGRES_PASSWORD} + - SELF_URL_PATH=http://localhost:8280/tt-rss + volumes: + - html:/var/www/html + depends_on: + - db + + web: + build: ./web + restart: unless-stopped + ports: + - 8280:80 + volumes: + - html:/var/www/html + depends_on: + - app + +volumes: + db: + html: diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..9e620af --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/web/nginx.conf b/web/nginx.conf new file mode 100644 index 0000000..44f1614 --- /dev/null +++ b/web/nginx.conf @@ -0,0 +1,53 @@ +worker_processes auto; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + access_log /dev/stdout; + error_log /dev/stderr warn; + + sendfile on; + + upstream app { + server app:9000; + } + + server { + listen 80; + root /var/www/html; + + location / { + try_files $uri $uri/index.php; + } + + location /tt-rss/cache { + aio threads; + internal; + access_log /var/log/nginx/fakecake_debug.log; + } + + location ~ \.php$ { + # regex to split $uri to $fastcgi_script_name and $fastcgi_path + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + + # Bypass the fact that try_files resets $fastcgi_path_info + # see: http://trac.nginx.org/nginx/ticket/321 + set $path_info $fastcgi_path_info; + fastcgi_param PATH_INFO $path_info; + + fastcgi_index index.php; + include fastcgi.conf; + + fastcgi_pass app; + } + } +}