]> jfr.im git - uguu.git/commitdiff
Dockerize Uguu to work with the default SQLite DB
authorr4jeshwar <redacted>
Thu, 7 Apr 2022 09:37:49 +0000 (15:07 +0530)
committerr4jeshwar <redacted>
Wed, 13 Apr 2022 06:08:13 +0000 (11:38 +0530)
.gitignore
Makefile
docker/.env [new file with mode: 0644]
docker/Dockerfile [new file with mode: 0644]
docker/dist.json [new file with mode: 0644]
docker/docker-entrypoint.sh [new file with mode: 0644]
docker/uguu.conf [new file with mode: 0644]

index b5b86be8dcc93aa7e9a8867c46d113b9dd094e1b..fdfaefa77f08bc89a2cc1c808749babbd4a69d96 100644 (file)
@@ -7,3 +7,4 @@ uguu.sq3
 *.xml
 .idea
 .phpdoc
+.vscode
\ No newline at end of file
index 391362c571ce1ff3d78f16329fc07ab3cbe09659..14c6e94ba1e07964042e7624e78d092b20d2e1ea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,9 @@ NPM="npm"
 DESTDIR="./dist"
 PKG_VERSION := $( $(GREP) -Po '(?<="version": ")[^"]*' )
 TMPDIR := $(shell mktemp -d)
+DOCKER_IMAGE = "$(shell basename $(CURDIR) | tr [:upper:] [:lower:])"
+DOCKER_TAG="$(DOCKER_TAG)"
+CONTAINER_NAME="$(CONTAINER_NAME)"
 # default modules
 MODULES="php"
 
@@ -79,6 +82,18 @@ uninstall:
 npm_dependencies:
        $(NPM) install
 
+
+build-image:
+               docker build -f docker/Dockerfile --build-arg VERSION=$(UGUU_RELEASE_VER) --no-cache -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
+
+run-container:
+               docker run --name $(CONTAINER_NAME) -d -p 8080:80 --env-file docker/.env $(DOCKER_IMAGE):$(DOCKER_TAG)
+
+purge-container:
+       if docker images | grep $(DOCKER_IMAGE); then \
+               docker rm -f $(CONTAINER_NAME) && docker rmi $(DOCKER_IMAGE):$(DOCKER_TAG) || true;\
+       fi;             
+
 builddirs:
        mkdir -p $(CURDIR)/build $(CURDIR)/build/img 
 ifneq (,$(findstring php,$(MODULES)))
diff --git a/docker/.env b/docker/.env
new file mode 100644 (file)
index 0000000..267b647
--- /dev/null
@@ -0,0 +1,23 @@
+GEN_ROBOTS_TXT=false
+GEN_SITE_MAP=false
+MAX_UPLOAD_SIZE=128
+PROD=false
+SITE_NAME=DEVOPS
+SITE_URL=https://yoursite.com
+ABUSE_CONTACT=abuse@example.com
+INFO_CONTACT=info@example.com
+SERVER_CN_LOC=Sweden
+SITE_META_INFO=SITENAME is a temporary file hosting service, upload files up to 128MiB for 24 hours.
+PAYPAL_URL=
+BTC_ADDR=
+FLATTR_URL=
+DB_PATH=/var/www/db/uguu.sq3
+FILES_ROOT=/var/www/files/
+LOG_IP=false
+DB_USER=NULL
+DB_PASS=NULL
+ANTI_DUPE=false
+FILES_RETRIES=15
+SSL=true
+NAME_LENGTH=8
+URL=
\ No newline at end of file
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644 (file)
index 0000000..fe8724e
--- /dev/null
@@ -0,0 +1,42 @@
+FROM ubuntu:latest
+
+ARG VERSION
+
+RUN apt-get update && \
+    apt install -y software-properties-common && \
+    add-apt-repository ppa:ondrej/php && \
+    apt-get install -y build-essential nginx-full php8.0-fpm php8.0 sqlite3 php8.0-sqlite3 nodejs certbot git npm cron gettext-base && \
+    apt clean 
+
+WORKDIR  /var/www/
+
+COPY docker/docker-entrypoint.sh .
+
+ADD https://github.com/nokonoko/Uguu/archive/refs/tags/v${VERSION}.tar.gz v${VERSION}.tar.gz
+
+RUN tar xvf v${VERSION}.tar.gz && \
+    mv Uguu-${VERSION}/ uguu
+
+RUN mkdir /var/www/uguu/dist && \
+    mkdir /var/www/db && \
+    mkdir /var/www/files
+    
+RUN sqlite3 /var/www/db/uguu.sq3 -init /var/www/uguu/sqlite_schema.sql && \
+    chown -R www-data:www-data /var/www/db /var/www/files && \
+    chmod -R 775 /var/www/
+
+RUN chmod a+x /var/www/uguu/checkdb.sh && \
+    chmod a+x /var/www/uguu/checkfiles.sh && \
+    sed -i 's#/path/to/files/#/var/www/uguu/files/#g' /var/www/uguu/checkfiles.sh && \
+    sed -i 's#/path/to/db/uguu.sq3#/var/www/db/uguu.sq3#g' /var/www/uguu/checkdb.sh 
+
+RUN echo "0,30 * * * * bash /var/www/uguu/checkfiles.sh" >> /var/spool/cron/crontabs/root && \
+    echo "0,30 * * * * bash /var/www/uguu/checkdb.sh" >> /var/spool/cron/crontabs/root
+      
+COPY docker/uguu.conf /etc/nginx/conf.d/
+     
+COPY dist.json /var/www/uguu/_dist.json 
+
+EXPOSE 80
+
+ENTRYPOINT [ "bash", "/var/www/docker-entrypoint.sh" ]
diff --git a/docker/dist.json b/docker/dist.json
new file mode 100644 (file)
index 0000000..6741a2a
--- /dev/null
@@ -0,0 +1,70 @@
+{
+  "init": {
+    "allowErrors": false
+  },
+  "dest": "dist",
+  "pkgVersion": "1.5.2",
+  "banners": [
+    "banners/malware_scans.swig",
+    "banners/donations.swig"
+  ],
+  "src": [
+    "templates/index.swig",
+    "templates/faq.swig",
+    "templates/tools.swig"
+  ],
+
+  "generateRobotstxt": "${GEN_ROBOTS_TXT}",
+  "generateSitemap": "${GEN_SITE_MAP}",
+  "max_upload_size": "${MAX_UPLOAD_SIZE}",
+  "production": "${PROD}",
+  "siteName": "${SITE_NAME}",
+  "siteUrl": "${SITE_URL}",
+  "abuseContact": "${ABUSE_CONTACT}",
+  "infoContact": "${INFO_CONTACT}",
+  "ServerCountryLocation": "${SERVER_CN_LOC}",
+  "SiteMetaInfo": "${SITE_META_INFO}",
+  "ToolsDesc": "The following tools might need editing to work on this clone of Uguu, usually editing the URL works.",
+  "paypalUrl": "${PAYPAL_URL}",
+  "bitcoinAddress": "${BTC_ADDR}",
+  "flattrUrl": "${FLATTR_URL}",
+  "DB_MODE": "sqlite",
+  "DB_PATH": "${DB_PATH}",
+  "DB_USER": "${DB_USER}",
+  "DB_PASS": "${DB_PASS}",
+  "LOG_IP": "${LOG_IP}",
+  "ANTI_DUPE": "${ANTI_DUPE}",
+  "BLACKLIST_DB": true,
+  "FILTER_MODE": true,
+  "FILES_ROOT": "${FILES_ROOT}",
+  "FILES_RETRIES": "${FILES_RETRIES}",
+  "SSL": "${SSL}",
+  "URL": "${URL}",
+  "NAME_LENGTH": "${NAME_LENGTH}",
+  "ID_CHARSET": "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ",
+  "BLOCKED_EXTENSIONS": [
+    "exe",
+    "scr",
+    "com",
+    "vbs",
+    "bat",
+    "cmd",
+    "htm",
+    "html",
+    "jar",
+    "msi",
+    "apk",
+    "phtml",
+    "svg"
+  ],
+  "BLOCKED_MIME": [
+    "application/msword",
+    "text/html",
+    "application/x-dosexec",
+    "application/java",
+    "application/java-archive",
+    "application/x-executable",
+    "application/x-mach-binary",
+    "image/svg+xml"
+  ]
+}
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
new file mode 100644 (file)
index 0000000..6f3fe68
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+envsubst < /var/www/uguu/_dist.json > /var/www/uguu/dist.json 
+cd /var/www/uguu/
+make
+make install
+service php8.0-fpm start
+service cron start
+nginx -g 'daemon off;'
diff --git a/docker/uguu.conf b/docker/uguu.conf
new file mode 100644 (file)
index 0000000..46d9e7e
--- /dev/null
@@ -0,0 +1,44 @@
+server{
+
+    listen          80;
+    server_name     localhost;
+   # ssl on;
+   # ssl_certificate /path/to/fullchain.pem;
+   # ssl_certificate_key /path/to/privkey.pem;
+   # ssl_protocols TLSv1.2 TLSv1.3;
+   # ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
+   # ssl_ecdh_curve secp384r1;
+
+    root /var/www/uguu/dist/;
+    autoindex       on;
+    access_log      on;
+    index index.html index.php;
+
+    location ~* \.(css|js|jpg|jpeg|gif|png|ico|xml|eot|woff|woff2|ttf|svg|otf|x-icon|avif|webp|apng)$ {
+    expires 30d;
+    }
+
+    location ^~ /files/ {
+     alias /var/www/files/;
+     index index.html index.htm;
+     autoindex off;
+     include mime.types;
+     types {
+     text/plain php;
+    }
+ }
+    gzip on;
+    gzip_min_length 1000;
+    gzip_comp_level 6;
+    gzip_proxied any;
+    gzip_types text/css text/js text/javascript application/javascript application/x-javascript;
+
+    location ~* \.php$ {
+    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
+    fastcgi_intercept_errors on;
+    fastcgi_index index.php;
+    fastcgi_split_path_info ^(.+\.php)(.*)$;
+    include fastcgi_params;
+    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+    }
+}
\ No newline at end of file