Merge pull request 'Pin base images and add end-to-end tests' (#6) from ci-cd into main
CI / build-and-scan (push) Successful in 1m50s

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
Djeex committed 2026-11-21 18:46:29 +01:00
commit 7378de15ec
3 files changed
+98 -6

No files matched your search

+10 -5
View File
@@ -1,23 +1,28 @@
# syntax=docker/dockerfile:1
# ---- Stage 1: compile libultrahdr (ultrahdr_app) --------------------------
FROM alpine:3.24 AS uhdr-build
FROM alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf AS uhdr-build
RUN apk add --no-cache \
git cmake make g++ nasm pkgconf libjpeg-turbo-dev
WORKDIR /build
# Pin to a commit once you've confirmed it works for you — HEAD can move.
RUN git clone --depth 1 https://github.com/google/libultrahdr.git
# Pinned to an exact commit (v2.0.2 + fixes) for reproducible, auditable builds.
ARG UHDR_COMMIT=c6fd15cdb2d05d3aaed84b817e4c4a274a4ce600
RUN git init libultrahdr \
&& git -C libultrahdr fetch --depth 1 https://github.com/google/libultrahdr.git "$UHDR_COMMIT" \
&& git -C libultrahdr checkout --detach FETCH_HEAD
RUN cmake -G "Unix Makefiles" -DUHDR_WRITE_XMP=ON \
-S libultrahdr -B libultrahdr/build \
&& cmake --build libultrahdr/build -j"$(nproc)"
# ---- Stage 2: runtime -------------------------------------------------------
FROM python:3.11-alpine AS base
FROM python:3.11.18-alpine@sha256:7fbad8e4652eae0186429a6f26cf5b23e27e8c6fd7ac4d0cfd7a6988cdeea1e1 AS base
RUN apk add --no-cache exiftool libjpeg-turbo libstdc++
# apk upgrade pulls Alpine security fixes released after the base image was built.
RUN apk upgrade --no-cache \
&& apk add --no-cache exiftool libjpeg-turbo libstdc++
COPY --from=uhdr-build /build/libultrahdr/build/ultrahdr_app /usr/local/bin/ultrahdr_app
RUN chmod +x /usr/local/bin/ultrahdr_app
+11 -1
View File
@@ -1,7 +1,8 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"],
"extends": ["config:recommended", "docker:pinDigests"],
"timezone": "Europe/Paris",
"minimumReleaseAge": "3 days",
"labels": ["bot"],
"vulnerabilityAlerts": {
"addLabels": ["bug"]
@@ -18,6 +19,10 @@
}
],
"packageRules": [
{
"matchManagers": ["pip_requirements"],
"minimumReleaseAge": "7 days"
},
{
"matchManagers": ["pip_requirements"],
"matchUpdateTypes": ["patch", "minor"],
@@ -28,6 +33,11 @@
"matchUpdateTypes": ["patch"],
"automerge": true
},
{
"matchManagers": ["dockerfile"],
"matchUpdateTypes": ["pin", "digest"],
"automerge": true
},
{
"matchUpdateTypes": ["major"],
"addLabels": ["major"]
+77
View File
@@ -0,0 +1,77 @@
"""End-to-end: runs the real ultrahdr_app + exiftool (present in the Docker
image, skipped elsewhere) to catch regressions from dependency or base image
updates that the mocked unit tests cannot see."""
import shutil
import numpy as np
import pytest
import tifffile
from PIL import Image
from app import assembler
pytestmark = pytest.mark.skipif(
bool(assembler.check_dependencies()) or not shutil.which("exiftool"),
reason="ultrahdr_app/exiftool not installed",
)
SIZE = 128
def gradient():
"""A horizontal ramp 0..1 with a bright highlight block, as float values."""
ramp = np.tile(np.linspace(0.05, 1.0, SIZE, dtype=np.float32), (SIZE, 1))
img = np.stack([ramp, ramp, ramp], axis=-1)
return img
@pytest.fixture
def sdr(tmp_path):
arr = (np.clip(gradient() ** (1 / 2.2), 0, 1) * 255).astype(np.uint8)
path = tmp_path / "sdr.jpg"
Image.fromarray(arr).save(path, "JPEG", quality=95)
return path
@pytest.fixture
def hdr_tiff(tmp_path):
hdr = gradient()
hdr[:32, :32] *= 3.0 # highlight brighter than SDR white
path = tmp_path / "hdr.tif"
tifffile.imwrite(path, hdr.astype(np.float32), photometric="rgb")
return path
def assert_valid_ultrahdr(out, log):
assert out.exists() and out.stat().st_size > 0
with Image.open(out) as img:
assert img.format == "JPEG" and img.size == (SIZE, SIZE)
assert "Validation report" in log # gain map found and readable
assert "XMP-hdrgm:GainMapMax" in log
def test_tiff_pipeline_produces_ultrahdr_jpeg(tmp_path, sdr, hdr_tiff):
out = tmp_path / "out.jpg"
ok, log, warning = assembler.run(sdr, hdr_tiff, out)
assert ok, log
assert_valid_ultrahdr(out, log)
assert warning is False # GainMapMin must not be negative (Instagram rejects it)
def test_jpeg_pipeline_round_trip(tmp_path, sdr, hdr_tiff):
first = tmp_path / "first.jpg"
ok, log, _ = assembler.run(sdr, hdr_tiff, first)
assert ok, log
second = tmp_path / "second.jpg"
ok, log, warning = assembler.run(sdr, first, second) # existing gain-map JPEG as HDR input
assert ok, log
assert_valid_ultrahdr(second, log)
assert warning is False
def test_invalid_hdr_jpeg_fails_cleanly(tmp_path, sdr):
not_hdr = tmp_path / "plain.jpg"
shutil.copy(sdr, not_hdr) # a JPEG without any gain map
ok, log, warning = assembler.run(sdr, not_hdr, tmp_path / "out.jpg")
assert ok is False and warning is False
assert log.splitlines()[-1].startswith("Error:")