Explorar o código

Merge pull request 'docker load values from env' (#21) from feature/docker_env into master

Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/21
lolcat %!s(int64=2) %!d(string=hai) anos
pai
achega
e9c6cce374
Modificáronse 6 ficheiros con 115 adicións e 7 borrados
  1. 2 2
      Dockerfile
  2. 12 3
      README.md
  3. 19 0
      apache/conf.d/ssl.conf
  4. 4 2
      docker-compose.yaml
  5. 4 0
      docker/docker-entrypoint.sh
  6. 74 0
      docker/gen_config.php

+ 2 - 2
Dockerfile

@@ -2,14 +2,14 @@ FROM alpine:latest
 WORKDIR /var/www/html/4get
 
 RUN apk update && apk upgrade
-RUN apk add   apache2-ssl php82-fileinfo php82-openssl php82-iconv php82-common php82-dom php82-curl curl php82-pecl-apcu php82-apache2 imagemagick php82-pecl-imagick
+RUN apk add php apache2-ssl php82-fileinfo php82-openssl php82-iconv php82-common php82-dom php82-curl curl php82-pecl-apcu php82-apache2 imagemagick php82-pecl-imagick php-mbstring
 
 COPY ./apache/httpd.conf /etc/apache2/httpd.conf
+COPY ./apache/conf.d/ssl.conf /etc/apache2/conf.d/ssl.conf
 COPY . .
 
 RUN chmod 777 /var/www/html/4get/icons
 
-VOLUME ["/etc/4get/certs"]
 EXPOSE 80
 EXPOSE 443
 

+ 12 - 3
README.md

@@ -163,13 +163,21 @@ docker run -d -p 443:443 -e FOURGET_SERVER_NAME="4get.ca" -e FOURGET_SERVER_ADMI
 replace enviroment variables FOURGET_SERVER_NAME and FOURGET_SERVER_ADMIN_EMAIL with relevant values
 
 if the certificate files are not mounted to /etc/4get/certs the service listens to port 80
+
 the certificate directory expects files named `cert.pem`, `chain.pem`, `privkey.pem`
 
+
 ## Install using Docker Compose 
+
 copy `docker-compose.yaml`
 
-create a directory with images named `banners` for example and mount to `/var/www/html/4get/banner`
-to serve custom banners
+to serve custom banners create a directory named `banners` for example with images and mount to `/var/www/html/4get/banner`
+
+to serve captcha images create a directory named `captchas` for example containing subfolders with images and mount to `/var/www/html/4get/data/captcha`
+
+any environment variables prefixed with `FOURGET_` will be added to the generated config
+the entrypoint will automatically set the `CAPTCHA_DATASET` value for you based on directory names and number of files in each
+
 
 ```
 version: "3.7"
@@ -189,9 +197,10 @@ services:
     volumes:
       - /etc/letsencrypt/live/domain.tld:/etc/4get/certs
       - ./banners:/var/www/html/4get/banner
+      - ./captchas:/var/www/html/4get/data/captcha
 ```
 
-Replace relevant values and start with `docker-compose up -d`
+Replace relevant values and start with `docker compose up -d`
 
 ## Install on Caddy
 

+ 19 - 0
apache/conf.d/ssl.conf

@@ -0,0 +1,19 @@
+LoadModule ssl_module modules/mod_ssl.so
+LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
+
+SSLRandomSeed startup file:/dev/urandom 512
+SSLRandomSeed connect builtin
+
+Listen 443
+
+SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES:!ADH
+SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES:!ADH
+SSLHonorCipherOrder on
+
+SSLProtocol all -SSLv3
+SSLProxyProtocol all -SSLv3
+
+SSLPassPhraseDialog  builtin
+
+SSLSessionCache        "shmcb:/var/cache/mod_ssl/scache(512000)"
+SSLSessionCacheTimeout  300

+ 4 - 2
docker-compose.yaml

@@ -1,3 +1,4 @@
+# example docker-compose.yaml
 version: "3.7"
 
 services:
@@ -5,8 +6,8 @@ services:
     image: luuul/4get:latest
     restart: always
     environment:
-      - FOURGET_SERVER_NAME=beak.chat
-      - FOURGET_SERVER_ADMIN_EMAIL="you@example.com"
+      - FOURGET_VERSION=6
+      - FOURGET_SERVER_NAME=4get.ca
 
     ports:
       - "80:80"
@@ -15,3 +16,4 @@ services:
     volumes:
       - /etc/letsencrypt/live/domain.tld:/etc/4get/certs
       - ./banners:/var/www/html/4get/banner
+      - ./captcha:/var/www/html/4get/data/captcha

+ 4 - 0
docker/docker-entrypoint.sh

@@ -14,6 +14,10 @@ if [ ! -f /etc/4get/certs/cert.pem ] || [ ! -f /etc/4get/certs/chain.pem ] || [
         mv /etc/apache2/httpd.conf_temp /etc/apache2/httpd.conf
 fi
 
+
+php82 ./docker/gen_config.php
+
+
 echo "4get is running"
 exec httpd -DFOREGROUND
 

+ 74 - 0
docker/gen_config.php

@@ -0,0 +1,74 @@
+ <?php
+
+include "/var/www/html/4get/data/config.php";
+
+$refl = new ReflectionClass('config');
+$config = ($refl->getConstants());
+
+$env = getenv();
+$fourget_env = array_filter($env, function($v, $k) {
+        return str_starts_with($k, "FOURGET");
+}, ARRAY_FILTER_USE_BOTH);
+
+
+foreach($fourget_env as $key => $val)  {
+        $target_key = preg_replace('/^FOURGET_/', '', $key);
+        $config[$target_key] = $val;
+};
+
+function type_to_string($n) {
+        $type = gettype($n);
+        if ($type === "NULL") {
+                return "null";
+        }
+        if ($type === "boolean") {
+                return $n ? 'true' : 'false';
+        }
+        if ($type === "string") {
+                return "\"$n\"";
+        }
+        if ($type === "array") {
+                return json_encode($n);
+        }
+        return $n;
+}
+
+
+function detect_captcha_dirs() {
+        $captcha_dir = "/var/www/html/4get/data/captcha/";
+        $categories = (array_map(function ($n) {
+                return explode("/", $n)[7];
+        }, glob($captcha_dir . "*")));
+
+
+        $result = array_map(function($category) {
+                return [$category, count(glob("/var/www/html/4get/data/captcha/" . $category . "/*" ))];
+        }, $categories);
+
+        return $result;
+}
+
+
+$special_keys = ["CAPTCHA_DATASET"];
+
+$output = "<?php\n // This file was generated by docker/gen_config.php\n";
+
+$output = $output . "class config {\n";
+foreach(($config) as $key => $val){
+        if(!in_array($key, $special_keys)) {
+$output = $output . "\tconst " . $key . " = " . type_to_string($val) . ";\n";
+continue;
+        }
+
+
+if($key === "CAPTCHA_DATASET") {
+        $output = $output . "\tconst " . $key . " = " . type_to_string(detect_captcha_dirs()) . ";\n";
+        }
+
+}
+
+$output = $output . "}\n";
+$output = $output . "?>";
+
+file_put_contents("./data/config.php", $output);
+?>