From 3f66b8bf862fa217443bf4f6fca8ec3122e4599a Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 19 Mar 2023 20:22:58 +0000 Subject: [PATCH] Dockerize --- .dockerignore | 5 +++++ conf/deploy.sh | 40 +++++++++++++++++++++++++++++++++ conf/nginx.conf | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ nginx.Dockerfile | 12 ++++++++++ php.Dockerfile | 3 +++ 5 files changed, 117 insertions(+) create mode 100644 .dockerignore create mode 100644 conf/deploy.sh create mode 100644 conf/nginx.conf create mode 100644 nginx.Dockerfile create mode 100644 php.Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ca56b1d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +nginx.Dockerfile +php.Dockerfile +.dockerignore +.gitignore +LICENSE \ No newline at end of file diff --git a/conf/deploy.sh b/conf/deploy.sh new file mode 100644 index 0000000..fc6790b --- /dev/null +++ b/conf/deploy.sh @@ -0,0 +1,40 @@ +#!/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/styles/" +CSSOUT="/data/out/styles" + +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/assets /data/out/assets +cp -r /data/in/error-pages /data/out/error-pages +cp -r /data/in/page-blocks /data/out/page-blocks +cp -r /data/in/*.php /data/out + +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/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..cc182c3 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,57 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 128; +} + +http { + include /etc/nginx/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"'; + access_log /var/log/nginx/access.log main; + sendfile on; + keepalive_timeout 65; + gzip_static on; + brotli_static on; + + server { + listen 80; + server_name localhost; + + access_log /var/log/nginx/access.log; + root /site; + + location ~ /(.git|php|page-blocks) { + deny all; + } + + location / { + index index.php; + try_files $uri $uri/ $uri/index.php &uri/index.html =404; + break; + expires 7d; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass localhost:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + error_page 403 /error-pages/403.php; + error_page 404 /error-pages/404.php; + error_page 500 501 502 503 504 /error-pages/50x.php; + + } +} \ No newline at end of file diff --git a/nginx.Dockerfile b/nginx.Dockerfile new file mode 100644 index 0000000..74f3f91 --- /dev/null +++ b/nginx.Dockerfile @@ -0,0 +1,12 @@ +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 +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 diff --git a/php.Dockerfile b/php.Dockerfile new file mode 100644 index 0000000..ee86046 --- /dev/null +++ b/php.Dockerfile @@ -0,0 +1,3 @@ +FROM php:8.2.1-fpm-alpine + +COPY . /site \ No newline at end of file