Andrew Dolgov 5 days ago
commit
58f39cd12f
9 changed files with 149 additions and 0 deletions
  1. 14 0
      .env-dist
  2. 1 0
      .gitignore
  3. 19 0
      README.md
  4. 22 0
      app/Dockerfile
  5. 3 0
      app/index.php
  6. 49 0
      app/startup.sh
  7. 32 0
      docker-compose.yml
  8. 6 0
      web/Caddyfile
  9. 3 0
      web/Dockerfile

+ 14 - 0
.env-dist

@@ -0,0 +1,14 @@
+# Copy this file to .env before building the container.
+# Put any local modifications here.
+
+OWNER_UID=1000
+OWNER_GID=1000
+
+# Calibre library base directory (mounts to /books)
+BOOKS_DIR=/home/fox/Books/
+
+# bind exposed port to 127.0.0.1 by default in case reverse proxy is used.
+# if you plan to run the container standalone and need origin port exposed
+# use next HTTP_PORT definition (or remove "127.0.0.1:").
+HTTP_PORT=127.0.0.1:8280
+#HTTP_PORT=8280

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+### Reverse proxy example
+
+```nginx
+	location ^~ /tt-irc/ {
+		client_max_body_size 50M;
+	
+		proxy_set_header Host $host;
+		proxy_set_header X-Real-IP $remote_addr;
+		proxy_set_header X-Forwarded-For $remote_addr;
+		proxy_set_header X-Forwarded-Proto $scheme;
+
+		proxy_buffering off;
+		proxy_request_buffering	off;
+
+		proxy_pass http://127.0.0.1:8280/tt-irc/;
+		break;
+	}
+```
+

+ 22 - 0
app/Dockerfile

@@ -0,0 +1,22 @@
+FROM alpine:3.9
+EXPOSE 9000/tcp
+
+RUN apk add --no-cache php7 php7-fpm \
+	php7-pdo php7-gd php7-mbstring \
+	php7-intl php7-xml php7-session \
+	php7-dom php7-fileinfo php7-json \
+	php7-sqlite3 php7-pdo_sqlite sqlite \
+	php7-zip git sudo
+
+RUN apk add --no-cache php7-exif
+
+ADD startup.sh /
+ADD index.php /
+
+RUN sed -i.bak 's/^listen = 127.0.0.1:9000/listen = 9000/' /etc/php7/php-fpm.d/www.conf
+#ADD www.conf /etc/php7/php-fpm.d/
+#ADD php.ini /etc/php7/php.ini
+
+RUN mkdir -p /var/www
+
+CMD /startup.sh

+ 3 - 0
app/index.php

@@ -0,0 +1,3 @@
+<?php
+   header("Location: /books/");
+   return;

+ 49 - 0
app/startup.sh

@@ -0,0 +1,49 @@
+#!/bin/sh -e
+
+if ! id app >/dev/null 2>&1; then
+	addgroup -g $OWNER_GID app
+	adduser -D -h /var/www/html -G app -u $OWNER_UID app
+fi
+
+DST_DIR=/var/www/html/books
+SRC_REPO=https://git.tt-rss.org/fox/the-epube.git
+
+[ -e $DST_DIR ] && rm -f $DST_DIR/.app_is_ready
+
+export PGPASSWORD=$DB_PASS 
+
+[ ! -e /var/www/html/index.php ] && cp /index.php /var/www/html
+
+PSQL="psql -q -h $DB_HOST -U $DB_USER $DB_NAME"
+
+if [ ! -d $DST_DIR/.git ]; then
+	mkdir -p $DST_DIR
+	echo cloning epube source from $SRC_REPO to $DST_DIR...
+	git clone $SRC_REPO $DST_DIR || echo error: failed to clone master repository.
+else
+	echo updating epube source in $DST_DIR from $SRC_REPO...
+	cd $DST_DIR && \
+		git config core.filemode false && \
+		git pull origin master || echo error: unable to update master repository.
+fi
+
+if [ ! -e $DST_DIR/index.php ]; then
+	echo "error: epube index.php missing (git clone failed?), unable to continue."
+	exit 1
+fi
+
+chown -R $OWNER_UID:$OWNER_GID $DST_DIR \
+	/var/log/php7
+
+for d in db sessions; do
+	chmod -R 777 $DST_DIR/$d
+done
+
+if [ ! -e $DST_DIR/config.php ]; then
+	cp $DST_DIR/config.php-dist $DST_DIR/config.php
+fi
+
+touch $DST_DIR/.app_is_ready
+
+sudo -u app /usr/sbin/php-fpm7 -F
+

+ 32 - 0
docker-compose.yml

@@ -0,0 +1,32 @@
+version: '3'
+
+# set database password in .env
+# please don't use quote (') or (") symbols in variables
+
+services:
+  app:
+    build: 
+      context:
+        ./app
+    restart: unless-stopped
+    environment:
+      - OWNER_UID=${OWNER_UID}
+      - OWNER_GID=${OWNER_GID}
+    volumes:
+      - app:/var/www/html
+      - ${BOOKS_DIR}:/books:ro
+
+  web:
+    build: ./web
+    restart: unless-stopped
+    ports:
+      - ${HTTP_PORT}:2015
+    volumes:
+      - app:/var/www/html:ro
+    depends_on:
+      - app
+
+volumes:
+  db:
+  app:  
+  certs:

+ 6 - 0
web/Caddyfile

@@ -0,0 +1,6 @@
+0.0.0.0
+root /var/www/html
+log stdout
+errors stderr
+internal /tt-rss/cache
+fastcgi / app:9000 php

+ 3 - 0
web/Dockerfile

@@ -0,0 +1,3 @@
+FROM abiosoft/caddy:no-stats
+
+COPY Caddyfile /etc/