From 4381117a197efca11ce896791ef35c6e52c7130f Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Apr 2018 12:00:14 +0200 Subject: cron in Docker image (#1871) * cron in Docker image https://github.com/FreshRSS/FreshRSS/issues/1869 * Fix cron CMD * Minor readme * Docker run d instead of dit There should not be a need for STDIN or TTY * Minor sed param --- Docker/Dockerfile | 10 +++++++--- Docker/README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- Docker/entrypoint.sh | 12 ++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) create mode 100755 Docker/entrypoint.sh (limited to 'Docker') diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 9b7336e3b..78a0f0e8f 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -15,8 +15,12 @@ WORKDIR ${FRESHRSS_ROOT} COPY . ${FRESHRSS_ROOT} COPY ./Docker/*.Apache.conf /etc/apache2/conf.d/ +RUN echo "17,37 * * * * php ${FRESHRSS_ROOT}/app/actualize_script.php 2>&1 | tee /tmp/FreshRSS.log" >> \ + /var/spool/cron/crontabs/root + +ENV CRON_MIN '' +ENTRYPOINT ["./Docker/entrypoint.sh"] + EXPOSE 80 -CMD php -f ./cli/prepare.php > /dev/null && \ - chown -R :www-data ${FRESHRSS_ROOT} && \ - chmod -R g+r ${FRESHRSS_ROOT} && chmod -R g+w ${FRESHRSS_ROOT}/data/ && \ +CMD ([ -z "$CRON_MIN" ] || crond -d 6) && \ exec httpd -D FOREGROUND diff --git a/Docker/README.md b/Docker/README.md index ccf4ab3f0..5cfe4cf38 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -26,7 +26,7 @@ sudo docker build --tag freshrss/freshrss -f Docker/Dockerfile . ## Run FreshRSS -Example using SQLite, and exposing FreshRSS on port 8080. You may have to adapt the network parameters to fit your needs. +Example using SQLite, built-in cron, and exposing FreshRSS on port 8080. You may have to adapt the parameters to fit your needs. ```sh # You can optionally run from the directory containing the FreshRSS source code: @@ -35,8 +35,9 @@ cd ./FreshRSS/ # The data will be saved on the host in `./data/` mkdir -p ./data/ -sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \ +sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=5,35' \ -p 8080:80 \ --name freshrss freshrss/freshrss ``` @@ -50,8 +51,9 @@ See https://hub.docker.com/_/mysql/ ```sh sudo docker run -d -v /path/to/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=freshrss -e MYSQL_USER=freshrss -e MYSQL_PASSWORD=pass --name mysql mysql -sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \ +sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=17,47' \ --link mysql -p 8080:80 \ --name freshrss freshrss/freshrss ``` @@ -61,8 +63,9 @@ See https://hub.docker.com/_/postgres/ ```sh sudo docker run -d -v /path/to/pgsql-data:/var/lib/postgresql/data -e POSTGRES_DB=freshrss -e POSTGRES_USER=freshrss -e POSTGRES_PASSWORD=pass --name postgres postgres -sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \ +sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=23,53' \ --link postgres -p 8080:80 \ --name freshrss freshrss/freshrss ``` @@ -89,16 +92,50 @@ sudo docker exec --user apache -it freshrss php ./cli/list-users.php See the [CLI documentation](../cli/) for all the other commands. -### Cron job to refresh feeds +## Cron job to automatically refresh feeds +We recommend a refresh rate of about twice per hour (see *WebSub* / *PubSubHubbub* for real-time updates). +There is no less than 3 options. Pick a single one. + +### Option 1) Cron inside the FreshRSS Docker image +Easiest, built-in solution, also used in the examples above +(but your Docker instance will have a second process in the background, without monitoring). +Just pass the environment variable `CRON_MIN` to your `docker run` command, +containing a valid cron minute definition such as `'13,43'` (recommended) or `'*/20'`. +Not passing the `CRON_MIN` environment variable – or setting it to empty string – will disable the cron daemon. + +```sh +sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=13,43' \ + -p 8080:80 \ + --name freshrss freshrss/freshrss +``` + +### Option 2) Cron on the host machine +Traditional solution. Set a cron job up on your host machine, calling the `actualize_script.php` inside the FreshRSS Docker instance. +Remember not pass the `CRON_MIN` environment variable to your Docker run, to avoid running the built-in cron daemon of option 1. -#### Example on Debian / Ubuntu -Create `/etc/cron.d/FreshRSS` with: +Example on Debian / Ubuntu: Create `/etc/cron.d/FreshRSS` with: ``` 7,37 * * * * root docker exec --user apache -it freshrss php ./app/actualize_script.php > /tmp/FreshRSS.log 2>&1 ``` +### Option 3) Cron as another instance of the same FreshRSS Docker image +For advanced users. Offers good logging and monitoring with auto-restart on failure. +Watch out to use the same run parameters than in your main FreshRSS instance, for database, networking, and file system. +See cron option 1 for customising the cron schedule. + +```sh +sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=17,37' \ + --name freshrss_cron freshrss/freshrss \ + crond -f -d 6 +``` + + ## Debugging ```sh @@ -115,5 +152,6 @@ ls /var/www/FreshRSS/ ## Deployment in production -Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/) or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/), +Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/) +or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/), with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/). diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.sh new file mode 100755 index 000000000..5b643da93 --- /dev/null +++ b/Docker/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +php -f ./cli/prepare.php > /dev/null + +chown -R :www-data . +chmod -R g+r . && chmod -R g+w ./data/ + +if [ -n "$CRON_MIN" ]; then + sed -r -i "/FreshRSS/s/^[^ ]+ /$CRON_MIN /" /var/spool/cron/crontabs/root +fi + +exec "$@" -- cgit v1.2.3 From 90998c24370ea14b2b78d1e2a55bfe33947b2aa7 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Apr 2018 13:52:44 +0200 Subject: Apache overrides were not enough (#1873) It looks like overrides of CustomLog, ErrorLog, Listen did not do the job fully. Updated to comment out those lines in httpd.conf. Fixes the fact that logs were kept in /var/log/apache2/ (instead of being only given via STDOUT to Docker logs) and the "internal dummy connection" bug over IPv6 (Docker is typically only IPv4). --- Docker/Dockerfile | 5 +++-- Docker/FreshRSS.Apache.conf | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'Docker') diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 78a0f0e8f..189d7175a 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -15,8 +15,9 @@ WORKDIR ${FRESHRSS_ROOT} COPY . ${FRESHRSS_ROOT} COPY ./Docker/*.Apache.conf /etc/apache2/conf.d/ -RUN echo "17,37 * * * * php ${FRESHRSS_ROOT}/app/actualize_script.php 2>&1 | tee /tmp/FreshRSS.log" >> \ - /var/spool/cron/crontabs/root +RUN sed -r -i "/^[ ]*(CustomLog|ErrorLog|Listen) /s/^/#/" /etc/apache2/httpd.conf && \ + echo "17,37 * * * * php ${FRESHRSS_ROOT}/app/actualize_script.php 2>&1 | tee /tmp/FreshRSS.log" >> \ + /var/spool/cron/crontabs/root ENV CRON_MIN '' ENTRYPOINT ["./Docker/entrypoint.sh"] diff --git a/Docker/FreshRSS.Apache.conf b/Docker/FreshRSS.Apache.conf index 59151d749..adfc804c6 100644 --- a/Docker/FreshRSS.Apache.conf +++ b/Docker/FreshRSS.Apache.conf @@ -17,8 +17,8 @@ ServerName freshrss.localhost Listen 0.0.0.0:80 DocumentRoot /var/www/FreshRSS/p/ +CustomLog /dev/stdout combined ErrorLog /dev/stderr -TransferLog /dev/stdout AllowEncodedSlashes On -- cgit v1.2.3 From 404ca869e9aafa40931914812b8552e4b9973694 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Apr 2018 17:13:03 +0200 Subject: Tab to spaces in multiline shell Copy pasting the commands was not working due to tabs, in e.g. Ubuntu terminal. --- Docker/README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'Docker') diff --git a/Docker/README.md b/Docker/README.md index 5cfe4cf38..1767ae85d 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -36,10 +36,10 @@ cd ./FreshRSS/ mkdir -p ./data/ sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ - -v $(pwd)/data:/var/www/FreshRSS/data \ - -e 'CRON_MIN=5,35' \ - -p 8080:80 \ - --name freshrss freshrss/freshrss + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=5,35' \ + -p 8080:80 \ + --name freshrss freshrss/freshrss ``` ### Examples with external databases @@ -52,10 +52,10 @@ See https://hub.docker.com/_/mysql/ ```sh sudo docker run -d -v /path/to/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=freshrss -e MYSQL_USER=freshrss -e MYSQL_PASSWORD=pass --name mysql mysql sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ - -v $(pwd)/data:/var/www/FreshRSS/data \ - -e 'CRON_MIN=17,47' \ - --link mysql -p 8080:80 \ - --name freshrss freshrss/freshrss + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=17,47' \ + --link mysql -p 8080:80 \ + --name freshrss freshrss/freshrss ``` #### PostgreSQL @@ -64,10 +64,10 @@ See https://hub.docker.com/_/postgres/ ```sh sudo docker run -d -v /path/to/pgsql-data:/var/lib/postgresql/data -e POSTGRES_DB=freshrss -e POSTGRES_USER=freshrss -e POSTGRES_PASSWORD=pass --name postgres postgres sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ - -v $(pwd)/data:/var/www/FreshRSS/data \ - -e 'CRON_MIN=23,53' \ - --link postgres -p 8080:80 \ - --name freshrss freshrss/freshrss + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=23,53' \ + --link postgres -p 8080:80 \ + --name freshrss freshrss/freshrss ``` ## Update @@ -105,10 +105,10 @@ Not passing the `CRON_MIN` environment variable – or setting it to empty strin ```sh sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ - -v $(pwd)/data:/var/www/FreshRSS/data \ - -e 'CRON_MIN=13,43' \ - -p 8080:80 \ - --name freshrss freshrss/freshrss + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=13,43' \ + -p 8080:80 \ + --name freshrss freshrss/freshrss ``` ### Option 2) Cron on the host machine @@ -129,10 +129,10 @@ See cron option 1 for customising the cron schedule. ```sh sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ - -v $(pwd)/data:/var/www/FreshRSS/data \ - -e 'CRON_MIN=17,37' \ - --name freshrss_cron freshrss/freshrss \ - crond -f -d 6 + -v $(pwd)/data:/var/www/FreshRSS/data \ + -e 'CRON_MIN=17,37' \ + --name freshrss_cron freshrss/freshrss \ + crond -f -d 6 ``` -- cgit v1.2.3 From 0ccda74571fd314864ce0223ed1efaae26a11ca8 Mon Sep 17 00:00:00 2001 From: Upils Date: Wed, 9 May 2018 09:57:46 +0200 Subject: Add a docker compose example. (#1882) * Add a docker compose example. Using postgresql and with traefik specific labels. * Added docker-compose specific documentation. * Move docker-compose section at the end of the README.md. --- Docker/README.md | 17 ++++++++++++++++- Docker/docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Docker/docker-compose.yml (limited to 'Docker') diff --git a/Docker/README.md b/Docker/README.md index 1767ae85d..c333329d4 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -75,7 +75,7 @@ sudo docker run -d --restart unless-stopped --log-opt max-size=10m \ ```sh # Rebuild an image (see build section above) or get a new online version: sudo docker pull freshrss/freshrss -# And then +# And then sudo docker stop freshrss sudo docker rename freshrss freshrss_old # See the run section above for the full command @@ -155,3 +155,18 @@ ls /var/www/FreshRSS/ Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/) or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/), with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/). + +### Example with [docker-compose](https://docs.docker.com/compose/) + +A `docker-compose.yml` file is given as an example, using PostgreSQL. In order to use it, you have to adapt: +- In the `postgresql` service: + * the `volumes` section; + * the `POSTGRES_PASSWORD` in the `environment` section; +- In the `freshrss` service: + * the `volumes` section; + * options under the `labels` section are specific to [Træfik](https://traefik.io/), a reverse proxy. If you are not using it, feel free to delete this section. If you are using it, adapt accordingly to your config, especially the `traefik.frontend.rule` option. + +You can then launch the stack (postgres + freshrss) with: +```sh +docker-compose up -d +``` diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml new file mode 100644 index 000000000..a57f214da --- /dev/null +++ b/Docker/docker-compose.yml @@ -0,0 +1,36 @@ +version: '2.3' + +services: + postgresql: + image: postgres:latest + restart: unless-stopped + volumes: + - '/path/to/pgsql-data:/var/lib/postgresql/data:Z' + environment: + - POSTGRES_USER=freshrss + - POSTGRES_PASSWORD=password + - POSTGRES_DB=freshrss + + freshrss: + image: freshrss/freshrss:latest + restart: unless-stopped + depends_on: + - postgresql + networks: + - web + - default + volumes: + - '/your/local/directory/data:/var/www/FreshRSS/data:Z' + labels: + - "traefik.backend=freshrss" + - "traefik.docker.network=web" + - "traefik.frontend.rule=Host:rss.example.com" + - "traefik.enable=true" + - "traefik.default.protocol=http" + - "traefik.frontend.entryPoints=http,https" + - "traefik.port=80" + +networks: + web: + external: true + -- cgit v1.2.3 From fd7b0c1e7854b00f222cad96c376ef8a7d547d7d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 20 May 2018 12:04:12 +0200 Subject: Changelog 1882 https://github.com/FreshRSS/FreshRSS/pull/1882 --- CHANGELOG.md | 1 + Docker/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'Docker') diff --git a/CHANGELOG.md b/CHANGELOG.md index 660845ec2..09f389205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Example: `Hello intitle:World OR date:P1D example OR author:Else intitle:"This or that"` * Deployment * Includes an optional cron daemon in Docker to refresh feeds automatically [#1869](https://github.com/FreshRSS/FreshRSS/issues/1869) + * Docker Compose example [#1882](https://github.com/FreshRSS/FreshRSS/pull/1882) * Bug fixing * Fix Docker bug affecting Apache `CustomLog` (unwanted local copy of access logs), `ErrorLog`, `Listen` (IPv6 bug) [#1873](https://github.com/FreshRSS/FreshRSS/pull/1873) * Fix muted feeds that were not actually muted [#1844](https://github.com/FreshRSS/FreshRSS/issues/1844) diff --git a/Docker/README.md b/Docker/README.md index c333329d4..381adab38 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -158,7 +158,7 @@ with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/). ### Example with [docker-compose](https://docs.docker.com/compose/) -A `docker-compose.yml` file is given as an example, using PostgreSQL. In order to use it, you have to adapt: +A [docker-compose.yml](docker-compose.yml) file is given as an example, using PostgreSQL. In order to use it, you have to adapt: - In the `postgresql` service: * the `volumes` section; * the `POSTGRES_PASSWORD` in the `environment` section; -- cgit v1.2.3 From 66ff16294a2f5dc6a731e4e7a82409d4e3e4dee0 Mon Sep 17 00:00:00 2001 From: Upils Date: Tue, 29 May 2018 22:28:30 +0200 Subject: Correct docker-compose.yml file and add a corresponding note in the doc. (#1906) * Add a docker compose example. Using postgresql and with traefik specific labels. * Added docker-compose specific documentation. * Move docker-compose section at the end of the README.md. * Correct docker-compose.yml file and add a corresponding note in the doc. * Typo in doc. --- Docker/README.md | 3 ++- Docker/docker-compose.yml | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'Docker') diff --git a/Docker/README.md b/Docker/README.md index 381adab38..133e7c3b8 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -160,11 +160,12 @@ with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/). A [docker-compose.yml](docker-compose.yml) file is given as an example, using PostgreSQL. In order to use it, you have to adapt: - In the `postgresql` service: - * the `volumes` section; + * the `volumes` section. Be careful to keep the path `/var/lib/postgresql/data` for the container. If the path is wrong, you will not get any error but your db will be gone at the next run; * the `POSTGRES_PASSWORD` in the `environment` section; - In the `freshrss` service: * the `volumes` section; * options under the `labels` section are specific to [Træfik](https://traefik.io/), a reverse proxy. If you are not using it, feel free to delete this section. If you are using it, adapt accordingly to your config, especially the `traefik.frontend.rule` option. + * the `environment` section to adapt the strategy to update feeds. You can then launch the stack (postgres + freshrss) with: ```sh diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml index a57f214da..8a8ad270b 100644 --- a/Docker/docker-compose.yml +++ b/Docker/docker-compose.yml @@ -5,7 +5,7 @@ services: image: postgres:latest restart: unless-stopped volumes: - - '/path/to/pgsql-data:/var/lib/postgresql/data:Z' + - '/path/to/pgsql-data:/var/lib/postgresql/data' environment: - POSTGRES_USER=freshrss - POSTGRES_PASSWORD=password @@ -20,7 +20,7 @@ services: - web - default volumes: - - '/your/local/directory/data:/var/www/FreshRSS/data:Z' + - '/your/local/directory/data:/var/www/FreshRSS/data' labels: - "traefik.backend=freshrss" - "traefik.docker.network=web" @@ -29,6 +29,8 @@ services: - "traefik.default.protocol=http" - "traefik.frontend.entryPoints=http,https" - "traefik.port=80" + environment: + - CRON_MIN=*/20 networks: web: -- cgit v1.2.3