diff --git a/CHANGELOG.md b/CHANGELOG.md index 28eef2641..88ed40102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ * Pull Minio images from the SeBS archive `spcleth/serverless-benchmarks:minio-reproducibility-archive-`, as MinIO no longer publishes images on Docker Hub or quay.io. +* 220.video-processing: use a static, glibc-based ffmpeg 9.0.2 from [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds), archived as `spcleth/serverless-benchmarks:ffmpeg-reproducibility-archive-` by `tools/ffmpeg_archive.py`. + * Fix restoring the cached configuration of self-hosted storage (Minio, ScyllaDB), and make the OpenWhisk `shutdownStorage` option work again. * OpenWhisk: store the Docker image of newly created actions in the function cache, and download provider metrics of invocations through the library trigger, which did not record the activation ID. diff --git a/README.md b/README.md index 69b13641e..f6911e824 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Or do you want to use SeBS in your work and you need new features? ## Installation Requirements: -- Docker (at least 19) +- Docker (at least 23) - Python 3.10+ with `pip` + `venv` or `uv` - `libcurl` and its headers must be available on your system to install `pycurl` - Standard Linux tools and `zip` installed diff --git a/benchmarks/200.multimedia/220.video-processing/README.md b/benchmarks/200.multimedia/220.video-processing/README.md index 11e20b25b..c4704e918 100644 --- a/benchmarks/200.multimedia/220.video-processing/README.md +++ b/benchmarks/200.multimedia/220.video-processing/README.md @@ -6,6 +6,6 @@ ## Description -The benchmark implements two operations on video files: adding a watermark and creating a gif. Both input and output media are passed through the cloud storage. To process the video, the benchmark uses `ffmpeg`. The benchmark installs the most recent static binary of `ffmpeg` provided by [John van Sickle](https://johnvansickle.com/ffmpeg/). +The benchmark implements two operations on video files: adding a watermark and creating a gif. Both input and output media are passed through the cloud storage. To process the video, the benchmark uses `ffmpeg`. The benchmark ships a static, glibc-based `ffmpeg` binary from [BtbN/FFmpeg-Builds](https://github.com/BtbN/FFmpeg-Builds). Since upstream builds expire, we archive it as the `spcleth/serverless-benchmarks:ffmpeg-reproducibility-archive-` image with `tools/ffmpeg_archive.py`, which either copies a pinned BtbN release or, once that has expired, rebuilds the FFmpeg release tag with BtbN's scripts (tagged `-rebuild`). The image is pinned by digest in `init.sh`. We avoid musl-based builds: musl's `qsort` makes the `palettegen` filter used by `extract-gif` about 20-40% slower. While 512 MB is technically sufficient and works well for the watermark operations, the `large` input converts the video into a gif which is more computationally intensive. On AWS, you should expect around ~30 seconds runtime on 1024 MiB allocation. diff --git a/benchmarks/200.multimedia/220.video-processing/init.sh b/benchmarks/200.multimedia/220.video-processing/init.sh index 64a64c937..6ca313228 100644 --- a/benchmarks/200.multimedia/220.video-processing/init.sh +++ b/benchmarks/200.multimedia/220.video-processing/init.sh @@ -9,34 +9,25 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" set -euo pipefail -# This currently points to 7.0.2 - will likely change in the future, but we do not have -# a persistent link. -if [[ "${TARGET_ARCHITECTURE}" == "arm64" ]]; then - FFMPEG_URL="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz" -else - FFMPEG_URL="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" +# Static glibc-based ffmpeg build (https://github.com/BtbN/FFmpeg-Builds), archived +# by tools/ffmpeg_archive.py and pinned by digest of the multi-arch index +# so that every deployment gets the exact same binary. +# TODO: append "@sha256:" printed by tools/ffmpeg_archive.py --push. +FFMPEG_IMAGE="spcleth/serverless-benchmarks:ffmpeg-reproducibility-archive-9.0.2" + +# SeBS calls the x86_64 architecture "x64", Docker calls it "amd64". +DOCKER_ARCH="${TARGET_ARCHITECTURE}" +if [[ "${DOCKER_ARCH}" == "x64" ]]; then + DOCKER_ARCH="amd64" fi -if command -v wget &>/dev/null; then - wget "${FFMPEG_URL}" -P "${DIR}" -elif command -v curl &>/dev/null; then - curl -fsL "${FFMPEG_URL}" -o "${DIR}/$(basename ${FFMPEG_URL})" -else - echo "ERROR: neither wget nor curl available" >&2 - exit 1 -fi +docker build --quiet --platform "linux/${DOCKER_ARCH}" \ + --output "type=local,dest=${DIR}/ffmpeg" - </dev/null -tar -xf ffmpeg-release-*-static.tar.xz -rm *.tar.xz -mv ffmpeg-* ffmpeg -rm -f ffmpeg/ffprobe -# make the binary executable -chmod 755 ffmpeg/ffmpeg -popd >/dev/null - -# Fail loudly if the binary isn't actually there. -# Sanity check - avoid issues where download silently fails. +# Sanity check - avoid issues where extraction silently fails. if [ ! -x "${DIR}/ffmpeg/ffmpeg" ]; then echo "ERROR: ffmpeg binary missing after packaging" >&2 exit 1 diff --git a/docs/build.md b/docs/build.md index c6c7f4bab..248e0e388 100644 --- a/docs/build.md +++ b/docs/build.md @@ -26,7 +26,7 @@ sequenceDiagram **Prepare Environment** - benchmark code with data is copied to the build location. -**Add Benchmark Data** - optional step of adding additional, external dependencies. An example is downloading `ffmpeg` release into `220.video-processing` benchmark. +**Add Benchmark Data** - optional step of adding additional, external dependencies. An example is extracting a pinned static `ffmpeg` binary into `220.video-processing` benchmark. **Add Platform-Specific Wrappers** - we add lightweight shims to implement the cloud-specific API and keep benchmark applications generic and portable. diff --git a/tools/ffmpeg_archive.py b/tools/ffmpeg_archive.py new file mode 100755 index 000000000..c8616db7e --- /dev/null +++ b/tools/ffmpeg_archive.py @@ -0,0 +1,193 @@ +#!/usr/bin/env python3 +# Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved. +"""Archive a static ffmpeg build as a SeBS image for the 220.video-processing benchmark. + +The benchmark uses a static, glibc-based ffmpeg from BtbN/FFmpeg-Builds. Upstream only +keeps its builds for a limited time, so we archive them as a multi-arch image, +spcleth/serverless-benchmarks:ffmpeg-reproducibility-archive-, similar to the +Minio archive. + +The binaries come from one of two sources: + +* download (default): the pinned BtbN release tarballs, verified against their sha256. +* build: BtbN's build scripts at a pinned commit, for when the release has been + deleted upstream. This takes several hours per architecture. BtbN can only build + a git tag or branch, so this builds the FFmpeg release tag, not the exact snapshot + of the downloaded build. It is pushed under a separate -rebuild tag. + +Building needs a buildx builder that supports multi-platform images, e.g., +`docker buildx create --use`; pushing also needs `docker login` with access to the +repository. After pushing, copy the printed FFMPEG_IMAGE line into +benchmarks/200.multimedia/220.video-processing/init.sh. +""" + +import argparse +import hashlib +import json +import os +import shutil +import subprocess +import sys +import tarfile +import tempfile +import urllib.request +from pathlib import Path + +REPOSITORY = "spcleth/serverless-benchmarks" +TAG_PREFIX = "ffmpeg-reproducibility-archive" +# The build context contains dist//{ffmpeg,LICENSE.txt,SOURCE}. +DOCKERFILE = """FROM scratch +ARG TARGETARCH +COPY dist/${TARGETARCH}/ / +""" +BTBN_REPO = "https://github.com/BtbN/FFmpeg-Builds" + +# Docker architecture -> BtbN target. +TARGETS = {"amd64": "linux64", "arm64": "linuxarm64"} + +RELEASES = { + "9.0.2": { + # Month-end autobuilds are retained upstream for two years. + "btbn_release": "autobuild-2026-10-31-12-59", + "build_name": "ffmpeg-n9.0.2-39-g7adfbe40dc", + "sha256": { + "amd64": "73e29a56974ae5a651133a04584c7483b21afe941e17dc91d79814a758b608d3", + "arm64": "6cad88ae5bcec356cfc5d7979a036cc4007128201928a0cf243df3db483276cc", + }, + # Used only for --source build: the commit of btbn_release, and the FFmpeg tag + # to build (the downloaded build is 39 commits ahead of it on release/9.0). + "btbn_commit": "5031c6f1082414e53688d39e521849905071070d", + "ffmpeg_ref": "n9.0.2", + "addin": "9.0", + }, +} + + +def run(cmd: list, **kwargs) -> None: + """Run a command, echoing it first, and fail on a non-zero exit code.""" + print("+", " ".join(str(c) for c in cmd), flush=True) + subprocess.run(cmd, check=True, **kwargs) + + +def sha256sum(path: Path) -> str: + """Compute the sha256 digest of a file.""" + digest = hashlib.sha256() + with open(path, "rb") as f: + for chunk in iter(lambda: f.read(1 << 20), b""): + digest.update(chunk) + return digest.hexdigest() + + +def download(release: dict, arch: str, work: Path) -> tuple: + """Download and verify the BtbN release tarball; return its path and source note.""" + name = f"{release['build_name']}-{TARGETS[arch]}-gpl-{release['addin']}.tar.xz" + url = f"{BTBN_REPO}/releases/download/{release['btbn_release']}/{name}" + tarball = work / name + print(f"Downloading {url}", flush=True) + with urllib.request.urlopen(url) as response, open(tarball, "wb") as f: + shutil.copyfileobj(response, f) + + actual = sha256sum(tarball) + if actual != release["sha256"][arch]: + raise RuntimeError( + f"Checksum mismatch for {name}: expected {release['sha256'][arch]}, got {actual}" + ) + return tarball, f"{BTBN_REPO}/releases/tag/{release['btbn_release']} {name}" + + +def build(release: dict, arch: str, work: Path) -> tuple: + """Rebuild with BtbN's scripts at the pinned commit; return the tarball and source note.""" + repo = work / f"btbn-{arch}" + run(["git", "clone", "--quiet", BTBN_REPO, repo]) + run(["git", "-C", repo, "checkout", "--quiet", release["btbn_commit"]]) + + target = TARGETS[arch] + env = dict(os.environ, GIT_BRANCH_OVERRIDE=release["ffmpeg_ref"]) + run(["./makeimage.sh", target, "gpl", release["addin"]], cwd=repo, env=env) + run(["./build.sh", target, "gpl", release["addin"]], cwd=repo, env=env) + + tarballs = list((repo / "artifacts").glob("*.tar.xz")) + if len(tarballs) != 1: + raise RuntimeError(f"Expected one build artifact, found {tarballs}") + note = f"{BTBN_REPO}/commit/{release['btbn_commit']} built from FFmpeg {release['ffmpeg_ref']}" + return tarballs[0], note + + +def extract(tarball: Path, source_note: str, dest: Path) -> None: + """Place ffmpeg, its license, and a note on its source into dest.""" + dest.mkdir(parents=True) + with tarfile.open(tarball) as tar: + for member in tar.getmembers(): + # Layout: /bin/ffmpeg and /LICENSE.txt + parts = Path(member.name).parts[1:] + if parts in (("bin", "ffmpeg"), ("LICENSE.txt",)): + member.name = parts[-1] + tar.extract(member, dest, filter="data") + + if not (dest / "ffmpeg").is_file() or not (dest / "LICENSE.txt").is_file(): + raise RuntimeError(f"{tarball} does not contain bin/ffmpeg and LICENSE.txt") + (dest / "ffmpeg").chmod(0o755) + (dest / "SOURCE").write_text( + f"FFmpeg source: https://github.com/FFmpeg/FFmpeg\n{source_note}\n" + ) + + +def main() -> int: + """Fetch or build the binaries for all architectures and build the archive image.""" + parser = argparse.ArgumentParser( + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter + ) + parser.add_argument("version", nargs="?", default="9.0.2", choices=sorted(RELEASES)) + parser.add_argument("--source", choices=["download", "build"], default="download") + parser.add_argument( + "--push", action="store_true", help="push the image; otherwise only build it" + ) + parser.add_argument("--keep", action="store_true", help="keep the working directory") + args = parser.parse_args() + + release = RELEASES[args.version] + image = f"{REPOSITORY}:{TAG_PREFIX}-{args.version}" + if args.source == "build": + image += "-rebuild" + fetch = download if args.source == "download" else build + + work = Path(tempfile.mkdtemp(prefix="sebs-ffmpeg-")) + try: + for arch in TARGETS: + tarball, note = fetch(release, arch, work) + extract(tarball, note, work / "context" / "dist" / arch) + + metadata = work / "metadata.json" + cmd = [ + "docker", + "buildx", + "build", + "--platform", + ",".join(f"linux/{arch}" for arch in TARGETS), + "--provenance=false", + "--file", + "-", + "--tag", + image, + "--metadata-file", + metadata, + ] + if args.push: + cmd.append("--push") + run(cmd + [work / "context"], input=DOCKERFILE.encode()) + + if args.push: + digest = json.loads(metadata.read_text())["containerimage.digest"] + print(f'\nFFMPEG_IMAGE="{image}@{digest}"') + else: + print(f"\nBuilt {image} without pushing; rerun with --push to publish it.") + finally: + if args.keep: + print(f"Working directory: {work}") + else: + shutil.rmtree(work) + return 0 + + +if __name__ == "__main__": + sys.exit(main())