From be326a5211d35d94ff72857f2a8c6a59d5e7b81d Mon Sep 17 00:00:00 2001 From: Talmai Oliveira Date: Sun, 30 Sep 2018 03:31:16 -0400 Subject: [PATCH] Grocy docker patch (#78) * typo corrections * more typos * initial work towards dockerized version of grocy * placeholder for future README * fully working dockerized grocy * updated final size of docker images --- .dockerignore | 6 ++++ Dockerfile-grocy | 58 ++++++++++++++++++++++++++++++++ Dockerfile-grocy-nginx | 32 ++++++++++++++++++ README.md | 12 ++++++- config-dist.php | 2 +- docker-compose.yml | 30 +++++++++++++++++ docker_nginx/common.conf | 28 +++++++++++++++ docker_nginx/conf.d/default.conf | 8 +++++ docker_nginx/conf.d/ssl.conf | 20 +++++++++++ docker_nginx/nginx.conf | 42 +++++++++++++++++++++++ info.php | 6 ++++ 11 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile-grocy create mode 100644 Dockerfile-grocy-nginx create mode 100644 docker-compose.yml create mode 100644 docker_nginx/common.conf create mode 100644 docker_nginx/conf.d/default.conf create mode 100644 docker_nginx/conf.d/ssl.conf create mode 100644 docker_nginx/nginx.conf create mode 100644 info.php diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3aa67ef9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.vscode +.gitignore +build.bat +Dockerfile +.DS_store \ No newline at end of file diff --git a/Dockerfile-grocy b/Dockerfile-grocy new file mode 100644 index 00000000..2f30b4e0 --- /dev/null +++ b/Dockerfile-grocy @@ -0,0 +1,58 @@ +FROM php:7.2-fpm-alpine +MAINTAINER Talmai Oliveira + +RUN apk update && \ + apk upgrade && \ + apk add --update yarn git &&\ + mkdir -p /www && \ + # Set environments + sed -i "s|;*daemonize\s*=\s*yes|daemonize = no|g" /usr/local/etc/php-fpm.conf && \ + sed -i "s|;*listen\s*=\s*127.0.0.1:9000|listen = 9000|g" /usr/local/etc/php-fpm.conf && \ + sed -i "s|;*listen\s*=\s*/||g" /usr/local/etc/php-fpm.conf && \ +# sed -i "s|;*log_level\s*=\s*notice|log_level = debug|g" /usr/local/etc/php-fpm.conf && \ + sed -i "s|;*chdir\s*=\s*/var/www|chdir = /www|g" /usr/local/etc/php-fpm.d/www.conf && \ +# sed -i "s|;*access.log\s*=\s*log/\$pool.access.log|access.log = \$pool.access.log|g" /usr/local/etc/php-fpm.d/www.conf && \ +# sed -i "s|;*pm.status_path\s*=\s*/status|pm.status_path = /status|g" /usr/local/etc/php-fpm.d/www.conf && \ +# sed -i "s|;*memory_limit =.*|memory_limit = ${PHP_MEMORY_LIMIT}|i" /usr/local/etc/php.ini && \ +# sed -i "s|;*upload_max_filesize =.*|upload_max_filesize = ${MAX_UPLOAD}|i" /usr/local/etc/php.ini && \ +# sed -i "s|;*max_file_uploads =.*|max_file_uploads = ${PHP_MAX_FILE_UPLOAD}|i" /usr/local/etc/php.ini && \ +# sed -i "s|;*post_max_size =.*|post_max_size = ${PHP_MAX_POST}|i" /usr/local/etc/php.ini && \ +# sed -i "s|;*cgi.fix_pathinfo=.*|cgi.fix_pathinfo= 0|i" /usr/local/etc/php.ini && \ + wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet && \ + # Cleaning up + rm -rf /var/cache/apk/* + +COPY public /www/public +COPY info.php /www/public +COPY controllers /www/controllers +COPY data /www/data +COPY helpers /www/helpers +COPY localization/ /www/localization +COPY middleware/ /www/middleware +COPY migrations/ /www/migrations +COPY publication_assets/ /www/publication_assets +COPY services/ /www/services +COPY views/ /www/views +COPY .yarnrc /www/ +COPY *.php /www/ +COPY *.json /www/ +COPY composer.* /root/.composer/ +COPY *yarn* /www/ +COPY *.sh /www/ + +# run php composer.phar with -vvv for extra debug information +RUN cd /var/www/html && \ + php composer.phar --working-dir=/www/ -n install && \ + cp /www/config-dist.php /www/data/config.php && \ + cd /www && \ + yarn install && \ + chown www-data:www-data -R /www/ + +# Set Workdir +WORKDIR /www/public + +# Expose volumes +VOLUME ["/www"] + +# Expose ports +EXPOSE 9000 \ No newline at end of file diff --git a/Dockerfile-grocy-nginx b/Dockerfile-grocy-nginx new file mode 100644 index 00000000..727fffb2 --- /dev/null +++ b/Dockerfile-grocy-nginx @@ -0,0 +1,32 @@ +FROM alpine:latest +MAINTAINER Talmai Oliveira + +RUN apk update && \ + apk upgrade && \ + apk add --update openssl nginx && \ + mkdir -p /etc/nginx/certificates && \ + mkdir -p /var/run/nginx && \ + mkdir -p /usr/share/nginx/html && \ + openssl req \ + -x509 \ + -newkey rsa:2048 \ + -keyout /etc/nginx/certificates/key.pem \ + -out /etc/nginx/certificates/cert.pem \ + -days 365 \ + -nodes \ + -subj /CN=localhost && \ + rm -rf /var/cache/apk/* + +COPY docker_nginx/nginx.conf /etc/nginx/nginx.conf +COPY docker_nginx/common.conf /etc/nginx/common.conf +COPY docker_nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf +COPY docker_nginx/conf.d/ssl.conf /etc/nginx/conf.d/ssl.conf + +# Expose volumes +VOLUME ["/etc/nginx/conf.d", "/var/log/nginx"] + +# Expose ports +EXPOSE 80 443 + +# Entry point +ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/README.md b/README.md index 191d80a2..1dfd3165 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ERP beyond your fridge - Public demo of the latest pre-release version (current master branch) → [https://demo-prerelease.grocy.info](https://demo-prerelease.grocy.info) ## Motivation -A household needs to be managed. I did this so far (almost 10 years) with my first self written software (a C# windows forms application) and with a bunch of Excel sheets. The software is a pain to use and Excel is Excel. So I searched for and tried different things for a (very) long time, nothing 100 % fitted, so this is my aim for a "complete houshold management"-thing. ERP your fridge! +A household needs to be managed. I did this so far (almost 10 years) with my first self written software (a C# windows forms application) and with a bunch of Excel sheets. The software is a pain to use and Excel is Excel. So I searched for and tried different things for a (very) long time, nothing 100 % fitted, so this is my aim for a "complete household management"-thing. ERP your fridge! ## How to install > **NEW** @@ -23,6 +23,16 @@ If you use nginx as your webserver, please include `try_files $uri /index.php;` If, however, your webserver does not support URL rewriting, set `DISABLE_URL_REWRITING` in `data/config.php` (`Setting('DISABLE_URL_REWRITING', true);`). +## How to run using Docker + +The docker images build are based on [Alpine](https://hub.docker.com/_/alpine/), with an extremelly low footprint (less than 10 MB for nginx, and less than 70MB for grocy with php-fm. That number is eventually bumped up to 353MB after all the dependencies are downloaded, however). Anyhow, to run using docker just do the following: + +``` +> docker-compose up +``` + +And grocy should be accessible via `http(s)://localhost/`. The https option will work. However, since the certificate is self-signed, most browsers will complain. + ## How to update Just overwrite everything with the latest release while keeping the `data` directory, check `config-dist.php` for new configuration options and add them to your `data/config.php` (the default from values `config-dist.php` will be used for not in `data/config.php` defined settings). Just to be sure, please empty `data/viewcache`. diff --git a/config-dist.php b/config-dist.php index 9428a092..24c4007a 100644 --- a/config-dist.php +++ b/config-dist.php @@ -7,7 +7,7 @@ Setting('MODE', 'production'); # one of the other available localization files in the "/localization" directory Setting('CULTURE', 'en'); -# To keep it simpel, grocy does not handle any currency conversions, +# To keep it simple: grocy does not handle any currency conversions, # this here is used to format all money values, # so can be anything (e. g. "USD" OR "$", doesn't matter...) Setting('CURRENCY', '$'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..11845672 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +# Usage: +# docker-compose build && docker-compose up +version: '2' + +services: + grocy-nginx: + build: + context: . + dockerfile: Dockerfile-grocy-nginx + depends_on: + - grocy + ports: + - '80:80' + - '443:443' + volumes_from: + - grocy + container_name: grocy-nginx + + grocy: + build: + context: . + dockerfile: Dockerfile-grocy + expose: + - 9000 + environment: + PHP_MEMORY_LIMIT: 512M + MAX_UPLOAD: 50M + PHP_MAX_FILE_UPLOAD: 200 + PHP_MAX_POST: 100M + container_name: grocy \ No newline at end of file diff --git a/docker_nginx/common.conf b/docker_nginx/common.conf new file mode 100644 index 00000000..34c75204 --- /dev/null +++ b/docker_nginx/common.conf @@ -0,0 +1,28 @@ +index index.php index.html index.htm; + +charset utf-8; + +location / { + try_files $uri $uri/ /index.php?$query_string; +} + +location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { + expires 365d; +} + +error_page 404 /404.html; +error_page 500 502 503 504 /50x.html; +location = /50x.html { + root /usr/share/nginx/html; +} + +location ~ \.php$ { + fastcgi_pass grocy:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; +} + +location ~ /\.ht { + deny all; +} \ No newline at end of file diff --git a/docker_nginx/conf.d/default.conf b/docker_nginx/conf.d/default.conf new file mode 100644 index 00000000..40b8b2b2 --- /dev/null +++ b/docker_nginx/conf.d/default.conf @@ -0,0 +1,8 @@ +server { + listen 80 default_server; + server_name _; + + root /www/public; # see: volumes_from + + include /etc/nginx/common.conf; +} \ No newline at end of file diff --git a/docker_nginx/conf.d/ssl.conf b/docker_nginx/conf.d/ssl.conf new file mode 100644 index 00000000..65385444 --- /dev/null +++ b/docker_nginx/conf.d/ssl.conf @@ -0,0 +1,20 @@ +server { + listen 443 ssl; + server_name _; + + root /www/public; # see: volumes_from + + ssl_certificate /etc/nginx/certificates/cert.pem; + ssl_certificate_key /etc/nginx/certificates/key.pem; + + error_log /var/log/nginx/error.log; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + include /etc/nginx/common.conf; + +} \ No newline at end of file diff --git a/docker_nginx/nginx.conf b/docker_nginx/nginx.conf new file mode 100644 index 00000000..32b74a43 --- /dev/null +++ b/docker_nginx/nginx.conf @@ -0,0 +1,42 @@ +user nobody; +worker_processes 1; + +pid /var/run/nginx/nginx.pid; + +error_log /var/log/nginx/error.log; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + sendfile on; + #tcp_nopush on; + + client_body_timeout 12; + client_header_timeout 12; + keepalive_timeout 15; + send_timeout 10; + + client_body_buffer_size 10K; + client_header_buffer_size 1k; + client_max_body_size 50M; + large_client_header_buffers 2 1k; + + gzip on; + gzip_comp_level 2; + gzip_min_length 1000; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain application/x-javascript text/xml text/css application/xml; + + access_log on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/info.php b/info.php new file mode 100644 index 00000000..976ac140 --- /dev/null +++ b/info.php @@ -0,0 +1,6 @@ + \ No newline at end of file