erofs-utils: add OCI registry support
PATCH v9 1/1 erofs-utils: add OCI registry support
From: Chengyu Zhu <[email protected]>
This patch adds support for creating EROFS filesystems directly from OCI-compliant container registries, enabling users to generate EROFS images from container images stored in registries such as Docker Hub and Quay.io, and more.
Key features:
- OCI remote backend with registry authentication support
- Manifest parsing for Docker v2 and OCI v1 formats
- Layer extraction and tar processing integration
- Multi-platform image selection capability
- Both anonymous and authenticated registry access
- Comprehensive build system integration
Configuration: ./configure --enable-oci
New mkfs.erofs option: --oci=[option] TARGET NAME[:TAG]
Supported options:
- platform=os/arch (default: linux/amd64)
- layer=N (extract specific layer, default: all layers)
- username/password (basic authentication)
Example:
$ mkfs.erofs --oci=platform=linux/amd64 ubuntu-22.04.erofs ubuntu:22.04
---
v8: https://lore.kernel.org/r/[email protected]
v9:
- code styling fixes.
- remove unnecessary malloc() and dup().
configure.ac | 47 ++ lib/Makefile.am | 8 +- lib/liberofs_oci.h | 95 ++++ lib/remotes/oci.c | 1068 ++++++++++++++++++++++++++++++++++++++++++++ mkfs/main.c | 258 ++++++++++- 5 files changed, 1474 insertions(+), 2 deletions(-) create mode 100644 lib/liberofs_oci.h create mode 100644 lib/remotes/oci.c
configure.ac +47 -0
@@ -177,10 +177,19 @@ AC_ARG_WITH(libxml2, [AS_HELP_STRING([--with-libxml2], [Enable and build with libxml2 support @<:@default=auto@:>@])]) +AC_ARG_WITH(json_c, + [AS_HELP_STRING([--with-json-c], + [Enable and build with json-c support @<:@default=auto@:>@])]) + AC_ARG_ENABLE(s3, [AS_HELP_STRING([--enable-s3], [enable s3 image generation support @<:@default=no@:>@])], [enable_s3="$enableval"], [enable_s3="no"]) +AC_ARG_ENABLE(oci, + AS_HELP_STRING([--enable-oci], + [enable OCI registry based input support @<:@default=no@:>@]), + [enable_oci="$enableval"],[enable_oci="no"]) + AC_ARG_ENABLE(fuse, [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])], [enable_fuse="$enableval"], [enable_fuse="no"])
@@ -625,6 +634,39 @@ AS_IF([test "x$with_libcurl" != "xno"], [ ]) ]) +# Configure json-c +have_json_c="no" +AS_IF([test "x$with_json_c" != "xno"], [ + PKG_CHECK_MODULES([json_c], [json-c], [ + saved_LIBS="$LIBS" + saved_CPPFLAGS=${CPPFLAGS} + CPPFLAGS="${json_c_CFLAGS} ${CPPFLAGS}" + LIBS="${json_c_LIBS} $LIBS" + AC_CHECK_HEADERS([json-c/json.h],[ + AC_CHECK_DECL(json_tokener_parse, [have_json_c="yes"], + [AC_MSG_ERROR([json-c doesn't work properly])], [[ +#include <json-c/json.h> + ]]) + ]) + LIBS="${saved_LIBS}" + CPPFLAGS="${saved_CPPFLAGS}" + ], [ + AS_IF([test "x$with_json_c" = "xyes"], [ + AC_MSG_ERROR([Cannot find proper json-c]) + ]) + ]) +]) + +# Validate dependencies for OCI registry +AS_IF([test "x$enable_oci" = "xyes"], [ + AS_IF([test "x$have_libcurl" = "xyes" -a "x$have_json_c" = "xyes"], [ + have_oci="yes" + ], [ + have_oci="no" + AC_MSG_ERROR([OCI registry disabled: missing libcurl or json-c]) + ]) +], [have_oci="no"]) + # Configure openssl have_openssl="no" AS_IF([test "x$with_openssl" != "xno"], [
@@ -714,6 +756,7 @@ AM_CONDITIONAL([ENABLE_OPENSSL], [test "x${have_openssl}" = "xyes"]) AM_CONDITIONAL([ENABLE_LIBXML2], [test "x${have_libxml2}" = "xyes"]) AM_CONDITIONAL([ENABLE_S3], [test "x${have_s3}" = "xyes"]) AM_CONDITIONAL([ENABLE_STATIC_FUSE], [test "x${enable_static_fuse}" = "xyes"]) +AM_CONDITIONAL([ENABLE_OCI], [test "x${have_oci}" = "xyes"]) if test "x$have_uuid" = "xyes"; then AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
@@ -786,6 +829,10 @@ if test "x$have_s3" = "xyes"; then AC_DEFINE([S3EROFS_ENABLED], 1, [Define to 1 if s3 is enabled]) fi +if test "x$have_oci" = "xyes"; then + AC_DEFINE([OCIEROFS_ENABLED], 1, [Define to 1 if OCI registry is enabled]) +fi + # Dump maximum block size AS_IF([test "x$erofs_cv_max_block_size" = "x"], [$erofs_cv_max_block_size = 4096], [])
lib/Makefile.am +7 -1
@@ -43,6 +43,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ vmdk.c metabox.c global.c importer.c liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include +liberofs_la_LDFLAGS = if ENABLE_LZ4 liberofs_la_CFLAGS += ${liblz4_CFLAGS} liberofs_la_SOURCES += compressor_lz4.c
@@ -74,9 +75,14 @@ if ENABLE_S3 liberofs_la_SOURCES += remotes/s3.c endif if ENABLE_EROFS_MT -liberofs_la_LDFLAGS = -lpthread +liberofs_la_LDFLAGS += -lpthread liberofs_la_SOURCES += workqueue.c endif if OS_LINUX liberofs_la_SOURCES += backends/nbd.c endif +if ENABLE_OCI +liberofs_la_SOURCES += remotes/oci.c +liberofs_la_CFLAGS += ${libcurl_CFLAGS} ${json_c_CFLAGS} +liberofs_la_LDFLAGS += ${libcurl_LIBS} ${json_c_LIBS} +endif
lib/liberofs_oci.h new file +95 -0
95 lines not on this page · raw message
lib/remotes/oci.c new file +1068 -0
1,068 lines not on this page · raw message
mkfs/main.c +257 -1
324 lines not on this page · raw message
Signature · 1 line
2.43.5