From dea0fd00ecf60511b4de81631c36748a9527b8ff Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 23 Dec 2019 21:07:34 +0100 Subject: [PATCH] adding docker-compose files and docker documentation --- README.md | 31 ++++---- docker/README.md | 75 +++++++++++++++--- docker/alpine/Dockerfile.build | 2 + docker/debian-stretch/Dockerfile.build | 2 + .../debian-stretch/selfcontained/Dockerfile | 18 ++--- .../docker-compose/default/docker-compose.yml | 31 ++++++++ docker/docker-compose/default/nginx.conf | 76 +++++++++++++++++++ .../pigallery2-only/docker-compose.yml | 18 +++++ 8 files changed, 221 insertions(+), 32 deletions(-) create mode 100644 docker/docker-compose/default/docker-compose.yml create mode 100644 docker/docker-compose/default/nginx.conf create mode 100644 docker/docker-compose/pigallery2-only/docker-compose.yml diff --git a/README.md b/README.md index f30caa16..407f796d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![npm version](https://badge.fury.io/js/pigallery2.svg)](https://badge.fury.io/js/pigallery2) [![Build Status](https://travis-ci.org/bpatrik/pigallery2.svg?branch=master)](https://travis-ci.org/bpatrik/pigallery2) [![Heroku](https://heroku-badge.herokuapp.com/?app=pigallery2&style=flat)](https://pigallery2.herokuapp.com) -[![Docker Build Status](https://img.shields.io/docker/build/bpatrik/pigallery2.svg)](https://hub.docker.com/r/bpatrik/pigallery2/) +![](https://github.com/bpatrik/pigallery2/workflows/docker-buildx/badge.svg) [![dependencies Status](https://david-dm.org/bpatrik/pigallery2/status.svg)](https://david-dm.org/bpatrik/pigallery2) [![devDependencies Status](https://david-dm.org/bpatrik/pigallery2/dev-status.svg)](https://david-dm.org/bpatrik/pigallery2?type=dev) @@ -27,19 +27,27 @@ Live Demo @ heroku: https://pigallery2.herokuapp.com/ -## 1. Getting started (on Raspberry Pi) -### 1.1 Direct Install -### 1.1.0 [Install NodeJs](https://nodejs.org/en/download/) +## 1. Getting started (also works on Raspberry Pi) + +### 1.1 Run with Docker +If you have `docker` and don't want to install all the dependencies, you can use one of our docker build. +For configuration and docker-compose files read more [here](docker/README.md) or check all builds: https://hub.docker.com/r/bpatrik/pigallery2/tags/ + +**Note**: You dont need to do the installation steps if you are using docker. + + +### 1.2 Direct Install +### 1.2.0 [Install NodeJs](https://nodejs.org/en/download/) Download and extract ```bash -curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - +curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs ``` Full node install on raspberry pi description: https://www.w3schools.com/nodejs/nodejs_raspberrypi.asp -### 1.1.1 Install PiGallery2 -#### 1.1.1-a Install from release +### 1.2.1 Install PiGallery2 +#### 1.2.1-a Install from release ```bash cd ~ @@ -48,7 +56,7 @@ unzip pigallery2.zip -d pigallery2 cd pigallery2 npm install ``` -#### 1.1.1-b Install from source +#### 1.2.1-b Install from source ```bash cd ~ wget https://github.com/bpatrik/pigallery2/archive/master.zip @@ -61,7 +69,7 @@ npm build **Note2**: you can use `npm run create-release -- --languages=fr,ro` to restrict building to the listed languages (english is added by default) -#### 1.1.2 Run PiGallery2 +#### 1.2.2 Run PiGallery2 ```bash npm start ``` @@ -69,11 +77,6 @@ To configure it, run `PiGallery2` first to create `config.json` file, then edit The app has a nice UI for settings, you may use that too. Default user: `admin` pass: `admin` -### 1.2 Run with Docker -If you have `docker` and don't want to install all the dependencies, you can use one of our docker build. -For configuration read more [here](docker/README.md) or check all builds: https://hub.docker.com/r/bpatrik/pigallery2/tags/ - -**Note**: You dont need to do the installation steps if you are using docker. ### 1.3 Advanced configuration diff --git a/docker/README.md b/docker/README.md index 637b317a..76b5a964 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,16 +1,71 @@ -# PiGallery2 docker installation [![Docker Build Status](https://img.shields.io/docker/build/bpatrik/pigallery2.svg)](https://hub.docker.com/r/bpatrik/pigallery2/) +# PiGallery2 docker installation ![](https://github.com/bpatrik/pigallery2/workflows/docker-buildx/badge.svg) -You can use [docker](https://docs.docker.com/install/) to run PiGallery2. +You can use [docker](https://docs.docker.com/install/) to run PiGallery2. See all available docker tags here: https://hub.docker.com/r/bpatrik/pigallery2/tags/ -## all docker tags -https://hub.docker.com/r/bpatrik/pigallery2/tags/ -## Usage -If you have `docker` and don't want to install all the dependencies, use this: +###0. Install docker +Official installation guide [here](https://docs.docker.com/install/), +but this will most likely do the trick ([source](https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl)): +```bash +curl -sSL https://get.docker.com | sh +``` + +## I. Docker compose +It is recommended to use [docker-compose](https://docs.docker.com/compose/) to run pigallery2. + +### I.0 Install docker-compose +Official dokcer-compose installation guide [here](https://docs.docker.com/compose/install/), +but this will most likely do the trick ([source](https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl)): +Install dependencies: +```bash +sudo apt-get install libffi-dev libssl-dev +sudo apt-get install -y python python-pip +sudo apt-get remove python-configparser +``` +Install docker-compose: +```bash +sudo pip install docker-compose +``` +You can check if it was successful with `docker-compose --version`. + +### I.1 get docker-compose.yml file +Download [docker-compose/default/docker-compose.yml](docker-compose/default/docker-compose.yml) and +[docker-compose/default/nginx.conf](docker-compose/default/nginx.conf). + +Edit `docker-compose.yml` to point the volumes to the right `image` and `tmp` directories. +Edit `nginx.conf` by replacing `yourdomain.com` to you domain address. + +**Note:** We are using nginx as reverse proxy to handle https and do proper HTTP queuing, gzipping, etc. Full nginx-based docker-compose tutorial [here](https://www.domysee.com/blogposts/reverse-proxy-nginx-docker-compose). + +**Note 2:** You can skip nginx, by using [docker-compose/pigallery2-only/docker-compose.yml](docker-compose/pigallery2-only/docker-compose.yml). + +#### I.1.a get SSL certificate with certbot +Install certbot: https://certbot.eff.org/. (Certbot uses letsencrypt to get free certificate). +Than get your certificate: +```bash +certbot certonly --standalone -d yourdomain.com +``` + +#### I.1.a start docker-compose +In the folder that has `docker-compose.yml`: +```bash +docker-compose up -d +``` +`-d` runs it as a daemon. Remove it, so you will see the logs. + +After the containers are up and running, you go to `yourdomain.com` and log in with user: `admin` pass: `admin` and set up the page in the settings. + +**Note:** `docker-compose.yml` contains `restart:always`, so the containers will be automatically started after reboot ([read more here](https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up)). + + +## II. Without docker-compose +If you want to run the container by yourself, here you go: + ```bash docker run \ -p 80:80 \ + -e NODE_ENV=production \ -v /config.json:/app/data/config/config.json \ -v :/app/data/db \ -v :/app/data/images \ @@ -22,7 +77,7 @@ After the container is up and running, you go to `http://localhost` and log in w **Note**: even with `memory` db, pigallery2 creates a db file for storing user credentials (if enabled), so mounting (with `-v`) the `/app/data/db` folder is recommended. -### before v1.7.0 +### II.a before v1.7.0 There was a breaking change in Docker files after v1.7.0. Use this to run earlier versions: ```bash @@ -40,6 +95,8 @@ Make sure that a file at `/config.json` and `sq You do not need the `/sqlite.db` line if you don't use the sqlite database. - ### Build the Docker image on your own +## Build the Docker image on your own - You can clone the repository and build the image, or you can just use the 'self-contained' Dockerfile: [debian-stretch/selfcontained/Dockerfile](debian-stretch/selfcontained/Dockerfile) +You can clone the repository and build the image, or you can just use the 'self-contained' Dockerfile: [debian-stretch/selfcontained/Dockerfile](debian-stretch/selfcontained/Dockerfile) + + diff --git a/docker/alpine/Dockerfile.build b/docker/alpine/Dockerfile.build index 28647da3..c873d840 100644 --- a/docker/alpine/Dockerfile.build +++ b/docker/alpine/Dockerfile.build @@ -13,6 +13,8 @@ FROM node:12-alpine WORKDIR /app # command line arg orverride the config.json with these settings ENTRYPOINT ["npm", "start", "--", \ + # after a extensive job (like video converting), pigallery calls gc, to clean up everthing as fast as possible + "--expose-gc", \ "--config-path=/app/data/config/config.json", \ "--Server-Database-sqlite-storage=/app/data/db/sqlite.db", \ "--Server-Database-memory-usersFile=/app/data/db/users.db", \ diff --git a/docker/debian-stretch/Dockerfile.build b/docker/debian-stretch/Dockerfile.build index aaa022b7..04ec5a8f 100644 --- a/docker/debian-stretch/Dockerfile.build +++ b/docker/debian-stretch/Dockerfile.build @@ -12,6 +12,8 @@ FROM node:12-stretch-slim WORKDIR /app # command line arg orverride the config.json with these settings ENTRYPOINT ["npm", "start", "--", \ + # after a extensive job (like video converting), pigallery calls gc, to clean up everthing as fast as possible + "--expose-gc", \ "--config-path=/app/data/config/config.json", \ "--Server-Database-sqlite-storage=/app/data/db/sqlite.db", \ "--Server-Database-memory-usersFile=/app/data/db/users.db", \ diff --git a/docker/debian-stretch/selfcontained/Dockerfile b/docker/debian-stretch/selfcontained/Dockerfile index d53fa731..8ea09c77 100644 --- a/docker/debian-stretch/selfcontained/Dockerfile +++ b/docker/debian-stretch/selfcontained/Dockerfile @@ -9,22 +9,22 @@ RUN set -x && npm install --unsafe-perm && \ mkdir -p /build/release/data/images && \ mkdir -p /build/release/data/tmp && \ npm run create-release && \ - cd /build/release && npm install --unsafe-perm && \ - npm start -- --config-only --force-rewrite-config \ - --config-path=/app/data/config/config.json \ - --Server-Database-sqlite-storage='/app/data/db/sqlite.db' \ - --Server-Database-memory-usersFile='/app/data/db/users.db' \ - --Server-Media-folder='/app/data/images' \ - --Server-Media-tempFolder='/app/data/tmp' + cd /build/release && npm install --unsafe-perm FROM node:12-stretch-slim WORKDIR /app -ENTRYPOINT ["npm", "start"] +ENTRYPOINT ["npm", "start", "--", \ + # after a extensive job (like video converting), pigallery calls gc, to clean up everthing as fast as possible + "--expose-gc", \ + "--config-path=/app/data/config/config.json", \ + "--Server-Database-sqlite-storage=/app/data/db/sqlite.db", \ + "--Server-Database-memory-usersFile=/app/data/db/users.db", \ + "--Server-Media-folder=/app/data/images", \ + "--Server-Media-tempFolder=/app/data/tmp"] EXPOSE 80 ENV NODE_ENV=production COPY --from=BUILDER /build/release /app -RUN ln -s /app/data/config/config.json config.json VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/tmp"] HEALTHCHECK --interval=30s --timeout=10s --retries=4 --start-period=60s \ CMD wget --quiet --tries=1 --no-check-certificate --spider \ diff --git a/docker/docker-compose/default/docker-compose.yml b/docker/docker-compose/default/docker-compose.yml new file mode 100644 index 00000000..75246c71 --- /dev/null +++ b/docker/docker-compose/default/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3' +services: + nginx: + image: nginx:latest + container_name: production_nginx + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./nginx/error.log:/etc/nginx/error_log.log + - ./nginx/cache/:/etc/nginx/cache + - /etc/letsencrypt/:/etc/letsencrypt/ + ports: + - 80:80 + - 443:443 + restart: always + + pigallery2: + image: bpatrik/pigallery2:nightly-stretch + container_name: pigallery2 + environment: + - NODE_ENV=production + volumes: + - "./pigallery2/config:/app/data/config" + - "db-data:/app/data/db" + - "./pigallery2/images:/app/data/images" + - "./pigallery2/tmp:/app/data/tmp" + expose: + - "80" + restart: always + +volumes: + db-data: diff --git a/docker/docker-compose/default/nginx.conf b/docker/docker-compose/default/nginx.conf new file mode 100644 index 00000000..6dc96b7c --- /dev/null +++ b/docker/docker-compose/default/nginx.conf @@ -0,0 +1,76 @@ +events { + +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + + + ## + # Virtual Host Configs + ## + + server { + listen 80 default_server; + listen [::]:80 default_server; + + server_name yourdomain.com www.yourdomain.com; + return 301 https://$server_name$request_uri; + } + + server { + server_name yourdomain.com; + + gzip on; + + + location / { + proxy_pass http://pigallery2:80; # forwarding to the other container, named 'pigallery2' + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + + listen 443 ssl default_server; + listen [::]:443 ssl default_server; + + ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + } +} diff --git a/docker/docker-compose/pigallery2-only/docker-compose.yml b/docker/docker-compose/pigallery2-only/docker-compose.yml new file mode 100644 index 00000000..112d06b1 --- /dev/null +++ b/docker/docker-compose/pigallery2-only/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3' +services: + pigallery2: + image: bpatrik/pigallery2:nightly-stretch + container_name: pigallery2 + environment: + - NODE_ENV=production + volumes: + - "./pigallery2/config:/app/data/config" + - "db-data:/app/data/db" + - "./pigallery2/images:/app/data/images" + - "./pigallery2/tmp:/app/data/tmp" + ports: + - 80:80 + restart: always + +volumes: + db-data: