diff --git a/apps/dolibarr/deployment.yaml b/apps/dolibarr/deployment.yaml new file mode 100644 index 0000000..b331a92 --- /dev/null +++ b/apps/dolibarr/deployment.yaml @@ -0,0 +1,105 @@ +#we use postgresql: +#create database dolibarr; +#create user dolibarr with encrypted password 'secret'; +#grant all privileges on database dolibarr to dolibarr; +apiVersion: apps/v1 +kind: Deployment +metadata: + name: dolibarr + labels: + app: dolibarr + release: latest +spec: + replicas: 1 + selector: + matchLabels: + app: dolibarr + release: latest + template: + metadata: + labels: + app: dolibarr + release: latest + spec: + volumes: + - name: dolibarr-nginx-site + configMap: + name: dolibarr-nginx-site + - name: www-data + emptyDir: {} + containers: + - name: nginx-proxy + image: nginx + volumeMounts: + - name: dolibarr-nginx-site + mountPath: /etc/nginx/conf.d + - name: www-data + mountPath: /var/www/html + ports: + - name: http + containerPort: 80 + protocol: TCP + - name: dolibarr + image: cr.lan/dolibarr:latest + lifecycle: + postStart: + exec: + command: + - /post-start.sh + volumeMounts: + - name: www-data + mountPath: /var/www/html + env: + - name: TZ + value: "Europe/Berlin" + - name: POSTGRES_HOST + value: postgres.live-env.svc.cluster.local:5432 + - name: POSTGRES_DB + value: dolibarr + - name: POSTGRES_USER + value: dolibarr + - name: POSTGRES_PASSWORD + value: Vb7yHzmE5HIjfU4hf89aXAmEEmxAnMdB + ports: + - name: php-fpm + containerPort: 9000 + protocol: TCP + resources: + requests: + memory: "512Mi" + cpu: "250m" + limits: + memory: "768Mi" + cpu: "3000m" + +--- +apiVersion: v1 +kind: Service +metadata: + name: dolibarr +spec: + ports: + - name: http + port: 80 + selector: + app: dolibarr +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: dolibarr + annotations: + kubernetes.io/ingress.class: nginx + ingress.kubernetes.io/whitelist-x-forwarded-for: "true" +spec: + rules: + - host: dolibarr.lan + http: + paths: + - backend: + service: + name: dolibarr + port: + name: http + path: / + pathType: Prefix diff --git a/apps/dolibarr/entrypoint.sh b/apps/dolibarr/entrypoint.sh new file mode 100644 index 0000000..5f4f699 --- /dev/null +++ b/apps/dolibarr/entrypoint.sh @@ -0,0 +1,271 @@ +#!/bin/sh +set -e + +log() { + echo "[$0] [$(date +%Y-%m-%dT%H:%M:%S)] $*" +} + +# version_greater A B returns whether A > B +version_greater() { + [ "$(printf '%s\n' "$@" | sort -t '.' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1)" != "$1" ] +} + +# return true if specified directory is empty +directory_empty() { + [ -z "$(ls -A "$1/")" ] +} + +run_as() { + if [ "$(id -u)" = 0 ]; then + su - www-data -s /bin/sh -c "$1" + else + sh -c "$1" + fi +} + + +if [ ! -f /usr/local/etc/php/php.ini ]; then + log "Initializing PHP configuration..." + cat < /usr/local/etc/php/php.ini +date.timezone = "${PHP_INI_DATE_TIMEZONE}" +memory_limit = ${PHP_MEMORY_LIMIT} +file_uploads = On +upload_max_filesize = ${PHP_MAX_UPLOAD} +post_max_size = ${PHP_MAX_UPLOAD} +max_execution_time = ${PHP_MAX_EXECUTION_TIME} +sendmail_path = /usr/sbin/sendmail -t -i +extension = calendar.so +EOF +fi + + +if [ ! -d /var/www/documents ]; then + log "Initializing Dolibarr documents directory..." + mkdir -p /var/www/documents +fi + +log "Updating Dolibarr users and group..." +usermod -u "$WWW_USER_ID" www-data +groupmod -g "$WWW_GROUP_ID" www-data + +log "Updating Dolibarr folder ownership..." +chown -R www-data:www-data /var/www + + +if [ ! -d /var/www/html/conf/ ]; then + log "Initializing Dolibarr HTML configuration directory..." + mkdir -p /var/www/html/conf/ +fi + +# Create a default config if autoconfig enabled +if [ -n "$DOLI_AUTO_CONFIGURE" ] && [ ! -f /var/www/html/conf/conf.php ]; then + log "Initializing Dolibarr HTML configuration..." + cat < /var/www/html/conf/conf.php + /var/www/documents/install.lock + chown www-data:www-data /var/www/documents/install.lock + chmod 400 /var/www/documents/install.lock + elif [ -n "$DOLI_AUTO_CONFIGURE" ] && [ ! -f /var/www/documents/install.lock ]; then + log "Create forced values for first Dolibarr install..." + cat < /var/www/html/install/install.forced.php + /var/www/documents/.docker-container-version +fi + +log "Serving Dolibarr..." +exec "$@" \ No newline at end of file diff --git a/apps/dolibarr/nginx-site.configmap.conf b/apps/dolibarr/nginx-site.configmap.conf new file mode 100644 index 0000000..c1f6748 --- /dev/null +++ b/apps/dolibarr/nginx-site.configmap.conf @@ -0,0 +1,60 @@ +server { + listen 80; + listen [::]:80; + + add_header Referrer-Policy origin; # make sure outgoing links don't show the URL to the Matomo instance + root /var/www/html; + index index.php index.html; + try_files $uri $uri/ =404; + + ## only allow accessing the following php files + location ~ \.php$ { + # regex to split $uri to $fastcgi_script_name and $fastcgi_path + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_index index.php; + + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + + proxy_connect_timeout 3600; + proxy_send_timeout 3600; + proxy_read_timeout 3600; + send_timeout 3600; + + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param HTTP_PROXY ""; # prohibit httpoxy: https://httpoxy.org/ + fastcgi_pass ${NGINX_PHP_CGI}; + } + + ## disable all access to the following directories + location ~ /\.ht { + deny all; + return 403; + } + location ~ /\.git { + deny all; + } + + location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ { + allow all; + ## Cache images,CSS,JS and webfonts for an hour + ## Increasing the duration may improve the load-time, but may cause old files to show after an Matomo upgrade + expires 1h; + add_header Pragma public; + add_header Cache-Control "public"; + } + + location ~ /(libs|vendor|plugins|misc/user) { + deny all; + return 403; + } + + ## properly display textfiles in root directory + location ~/(.*\.md|LEGALNOTICE|LICENSE) { + default_type text/plain; + } +} + +# vim: filetype=nginx \ No newline at end of file