From 224891d2b5ab6301db49415316ad49385d0fef77 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 16 Feb 2023 20:40:42 +0000 Subject: [PATCH] Update deployment types --- conf/deploy.sh | 43 +++++++++++++++++++++++++++++++++++ nginx.conf => conf/nginx.conf | 9 ++++---- downloads/vcard.vcf | 3 +-- nginx.Dockerfile | 14 +++++++++--- 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 conf/deploy.sh rename nginx.conf => conf/nginx.conf (88%) diff --git a/conf/deploy.sh b/conf/deploy.sh new file mode 100644 index 0000000..5a72429 --- /dev/null +++ b/conf/deploy.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +ROOTIN="/data/in" +ROOTOUT="/data/out" + +echo "Running UglifyJS on /data/in folder" +uglifyjs-folder "$ROOTIN" -x ".js" -eo "$ROOTOUT" + +echo "Running UglifyCSS" +CSSIN="/data/in/style/" +CSSOUT="/data/out/style" + +cd $CSSIN +echo "Changed directory" +for f in * +do + if [ -f "$f" ]; then + uglifycss "$f" --output "$f"; + fi +done + +echo "Moving 'styles' to 'out'" +cp -r $CSSIN $CSSOUT + +echo "Running html-minifier-terser on /folder" +HTMLIN="/data/in/" +HTMLOUT="/data/out" +html-minifier-terser --collapse-whitespace --remove-comments --file-ext html --input-dir /data/in/ --output-dir /data/out/ + +#echo "Moving JSON Manifest file from root to output" +#cat /data/in/manifest.json | jq -c > /data/out/manifest.json + +echo "Moving other files folder from in/ to out/" +cp -r /data/in/images /data/out/images +cp -r /data/in/error-pages/*.php /data/out/error-pages/ +cp -r /data/in/downloads /data/out/downloads +cp -r /data/in/*.php /data/out/ +cp -r /data/in/*.ico /data/out/ +cp -r /data/in/page-blocks /data/out/page-blocks +cp -r /data/in/php /data/out/php + +echo "Running GZIP & Brotli on all HTML, JS, CSS, JSON, SVG, TTF, VCF, PUB files" +find /data/out -type f -name \*.html -or -name \*.vcf -or -name \*.pub -or -name \*.js -or -name \*.css -or -name \*.json -or -name \*.svg -or -name \*.ttf | while read file; do gzip -k -9 $file; brotli -k -q 11 $file; done \ No newline at end of file diff --git a/nginx.conf b/conf/nginx.conf similarity index 88% rename from nginx.conf rename to conf/nginx.conf index a2d882c..5de48a0 100644 --- a/nginx.conf +++ b/conf/nginx.conf @@ -1,12 +1,12 @@ user nginx; -worker_processes auto; +worker_processes 1; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { - worker_connections 1024; + worker_connections 128; } http { @@ -19,8 +19,7 @@ http { sendfile on; keepalive_timeout 65; gzip_static on; - gzip on; - gzip_types text/html text/css application/json text/javascript text/plain font/ttf; + brotli_static on; server { listen 80; @@ -37,7 +36,7 @@ http { index index.php; try_files $uri $uri/ $uri/index.php &uri/index.html =404; break; - expires 4320; + expires 7d; } location ~ \.php$ { diff --git a/downloads/vcard.vcf b/downloads/vcard.vcf index 9125c0b..5ac49c0 100644 --- a/downloads/vcard.vcf +++ b/downloads/vcard.vcf @@ -7,6 +7,5 @@ EMAIL;CHARSET=UTF-8;type=HOME,INTERNET:fred@fjla.uk TEL;TYPE=HOME,VOICE:03331126831 ADR;CHARSET=UTF-8;TYPE=HOME:;;;Bath;;;United Kingdom URL;CHARSET=UTF-8:https://fredboniface.co.uk -NOTE;CHARSET=UTF-8:vCard generated at vcardmaker.com REV:2022-10-06T21:38:40.052Z -END:VCARD +END:VCARD \ No newline at end of file diff --git a/nginx.Dockerfile b/nginx.Dockerfile index cf8bd58..74f3f91 100644 --- a/nginx.Dockerfile +++ b/nginx.Dockerfile @@ -1,4 +1,12 @@ -FROM nginx:mainline-alpine-slim +FROM fedora:latest as compressor +RUN dnf install brotli nodejs npm jq -y +RUN npm i uglifyjs-folder uglifycss html-minifier-terser -g +COPY . /data/in +RUN bash /data/in/conf/deploy.sh + +FROM fholzer/nginx-brotli:latest RUN rm /etc/nginx/nginx.conf -COPY ./nginx.conf /etc/nginx/nginx.conf -COPY . /site \ No newline at end of file +RUN apk update +RUN apk add --upgrade libxml2 libxslt +COPY ./conf/nginx.conf /etc/nginx/nginx.conf +COPY --from=compressor /data/out/ /site/ \ No newline at end of file