diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9f5f879 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.gitea +utils/xor-enc.py \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5562372..4160c21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,20 @@ -FROM nginx:alpine-slim +FROM node:alpine AS build + +WORKDIR /src + +COPY . /src + +# Install terser to minify JS files +RUN npm install -g terser +RUN if [ -d "js" ]; then find js -type f -name "*.js" -exec sh -c 'for f; do terser "$f" -c -m -o "$f"; done' sh {} +; fi + +FROM nginx:alpine-slim AS final -# Copy custom nginx configuration COPY nginx.conf /etc/nginx/nginx.conf -# Copy website files COPY . /usr/share/nginx/html -# Copy minify script and make it executable -COPY ./utils/minify.sh /tmp/minify.sh -RUN chmod +x /tmp/minify.sh - -# Minify all JavaScript files in-place -RUN find /usr/share/nginx/html -name "*.js" -type f -exec sh /tmp/minify.sh {} \; && \ - rm -r /tmp && \ - rm -r /usr/share/nginx/html/.git && \ - rm -r /usr/share/nginx/html/utils +COPY --from=build /src/js /usr/share/nginx/html/js EXPOSE 80 diff --git a/utils/minify.sh b/utils/minify.sh deleted file mode 100644 index 6fc37d6..0000000 --- a/utils/minify.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# Minify a JavaScript file in-place -# Usage: ./minify.sh - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -FILE="$1" - -if [ ! -f "$FILE" ]; then - echo "Error: File '$FILE' not found" - exit 1 -fi - -# Check if the file is a JavaScript file -if [[ ! "$FILE" =~ \.js$ ]]; then - echo "Error: File must have .js extension" - exit 1 -fi - -# Minify the file using a simple approach with sed and tr -# This removes comments, extra whitespace, and newlines -TMP_FILE="${FILE}.tmp" - -# Remove single-line comments, multi-line comments, and compress whitespace -sed 's|//.*$||g' "$FILE" | \ - tr '\n' ' ' | \ - sed 's|/\*.*\*/||g' | \ - sed 's/[[:space:]]\+/ /g' | \ - sed 's/[[:space:]]*\([{};,=()[\]<>+\-*/%!&|?:]\)[[:space:]]*/\1/g' | \ - sed 's/^[[:space:]]*//;s/[[:space:]]*$//' > "$TMP_FILE" - -# Replace original file with minified version -mv "$TMP_FILE" "$FILE" - -echo "Minified: $FILE"