Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd6c1cf6fc | ||
|
|
ae8c2bbb1f |
+11
-8
@@ -1,17 +1,20 @@
|
||||
FROM debian:trixie-20260316
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
FROM alpine
|
||||
|
||||
# Install deps
|
||||
RUN apt-get update && apt-get install --yes --no-install-recommends \
|
||||
ca-certificates \
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
expect \
|
||||
git \
|
||||
libxml2 \
|
||||
libxslt1.1 \
|
||||
node-less \
|
||||
libxslt \
|
||||
minify \
|
||||
npm \
|
||||
openssh-client \
|
||||
rsync
|
||||
rsync \
|
||||
uv
|
||||
|
||||
# Install node deps
|
||||
RUN npm install -g less
|
||||
|
||||
# Set uv project env, to persist stuff moving dirs
|
||||
ENV UV_PROJECT_ENVIRONMENT=/root/.cache/uv/venv
|
||||
|
||||
@@ -10,10 +10,11 @@ import logging
|
||||
import shutil
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import minify
|
||||
from fsfe_website_build.lib.misc import run_command
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import multiprocessing.pool
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
from fsfe_website_build.lib.site_config import Deployment
|
||||
@@ -34,8 +35,30 @@ def _copy_file(target: Path, source_site: Path, source_file: Path) -> None:
|
||||
shutil.copymode(source_file, target_file)
|
||||
|
||||
|
||||
def _copy_minify_file(
|
||||
target: Path, source_site: Path, source_file: Path, mime: str
|
||||
def _cli_copy_minify_file(target: Path, source_dir: Path, source_file: Path) -> None:
|
||||
target_file = target.joinpath(source_file.relative_to(source_dir))
|
||||
if (
|
||||
not target_file.exists()
|
||||
or source_file.stat().st_mtime > target_file.stat().st_mtime
|
||||
):
|
||||
logger.debug("Copying minified %s to %s", source_file, target_file)
|
||||
target_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Do not minify pre minified files
|
||||
if ".min" not in source_file.suffixes:
|
||||
run_command(["minify", str(source_file), "-o", str(target_file)])
|
||||
else:
|
||||
# Instead just copy them into place
|
||||
shutil.copyfile(source_file, target_file)
|
||||
# preserve file modes
|
||||
shutil.copymode(source_file, target_file)
|
||||
|
||||
|
||||
def _module_copy_minify_file(
|
||||
target: Path,
|
||||
source_site: Path,
|
||||
source_file: Path,
|
||||
mime: str,
|
||||
minify_module: types.ModuleType,
|
||||
) -> None:
|
||||
target_file = target.joinpath(source_file.relative_to(source_site))
|
||||
if (
|
||||
@@ -46,7 +69,7 @@ def _copy_minify_file(
|
||||
target_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
# Do not minify pre minified files
|
||||
if ".min" not in source_file.suffixes:
|
||||
minify.file(mime, str(source_file), str(target_file))
|
||||
minify_module.file(mime, str(source_file), str(target_file))
|
||||
else:
|
||||
# Instead just copy them into place
|
||||
shutil.copyfile(source_file, target_file)
|
||||
@@ -109,11 +132,21 @@ def copy_files(
|
||||
]
|
||||
),
|
||||
)
|
||||
# This has to be single threaded as their is an upstream bug that
|
||||
# prevents multihreading the minifier
|
||||
# https://github.com/tdewolff/minify/issues/535
|
||||
for file_suffix, mime in minifiable_content.items():
|
||||
for file in [
|
||||
files = [
|
||||
path for path in source_site.glob(f"**/*{file_suffix}") if path.is_file()
|
||||
]:
|
||||
_copy_minify_file(target, source_site, file, mime)
|
||||
]
|
||||
# Use cli based minify if possible
|
||||
if shutil.which("minify"):
|
||||
pool.starmap(
|
||||
_cli_copy_minify_file, ((target, source_site, file) for file in files)
|
||||
)
|
||||
else:
|
||||
# fallback to python module
|
||||
# This has to be single threaded as there is an upstream bug that
|
||||
# prevents multihreading the minifier
|
||||
# https://github.com/tdewolff/minify/issues/535
|
||||
import minify # noqa: PLC0415
|
||||
|
||||
for file in files:
|
||||
_module_copy_minify_file(target, source_site, file, mime, minify)
|
||||
|
||||
+11
-10
@@ -1,24 +1,25 @@
|
||||
FROM debian:trixie-20260316
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv /uv /uvx /bin/
|
||||
FROM alpine
|
||||
|
||||
# Install deps
|
||||
RUN apt-get update && apt-get install --yes --no-install-recommends \
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
composer \
|
||||
file \
|
||||
git \
|
||||
libxml2 \
|
||||
libxml2-utils \
|
||||
libxslt1.1 \
|
||||
node-less \
|
||||
libxslt \
|
||||
mediainfo \
|
||||
minify \
|
||||
npm \
|
||||
php-zip \
|
||||
perl \
|
||||
php84-zip \
|
||||
rsync \
|
||||
shfmt \
|
||||
xsltproc
|
||||
uv
|
||||
|
||||
# Install prettier
|
||||
RUN npm install -g prettier
|
||||
# Install node deps
|
||||
RUN npm install -g prettier less
|
||||
# Install php cs fixer
|
||||
RUN composer global require friendsofphp/php-cs-fixer
|
||||
# Add composer to path
|
||||
|
||||
Reference in New Issue
Block a user