Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge libs #38

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 161 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ CPMFindPackage(
OPTIONS "JSON_Install ON")

CPMFindPackage(
NAME Boost COMPONENTS process
VERSION 1.74.0
# NOTE: 1.81.0 is the oldest release on gtihub
URL "https://github.com/boostorg/boost/releases/download/boost-1.81.0/boost-1.81.0.7z"
NAME Boost COMPONENTS headers
VERSION 1.64.0
URL "https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.7z"
EXCLUDE_FROM_ALL ON)

if(NOT TARGET Boost::process)
add_library(Boost::process ALIAS Boost::headers)
endif()

CPMFindPackage(
NAME fmt
VERSION 9.1.0
Expand Down Expand Up @@ -94,7 +97,159 @@ set(CMAKE_CXX_FLAGS_DEBUG "-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE")

include(./cmake/PFL.cmake)

set(OCPPI_LIBS common runtime cli)
pfl_init(ENABLE_TESTING ${OCPPI_ENABLE_TESTING} BUILD_EXAMPLES
${OCPPI_BUILD_EXAMPLES} INSTALL ${OCPPI_INSTALL})
pfl_add_libraries(VERSION ${PROJECT_VERSION} LIBS ${OCPPI_LIBS})

pfl_add_library(
SOVERSION
${OCPPI_SOVERSION}
VERSION
${PROJECT_VERSION}
TYPE
${OCPPI_LIBRARY_TYPE}
INS
include/ocppi/configure.hpp.in
include/ocppi/runtime/configure.hpp.in
SOURCES
src/ocppi/InvalidArgumentError.cpp
src/ocppi/cli/CLI.cpp
src/ocppi/cli/CommandFailedError.cpp
src/ocppi/cli/crun/Crun.cpp
src/ocppi/cli/runc/Runc.cpp
src/ocppi/cli/youki/Youki.cpp
src/ocppi/configure.cpp
src/ocppi/runtime/ContainerID.cpp
src/ocppi/runtime/CreateOption.cpp
src/ocppi/runtime/DeleteOption.cpp
src/ocppi/runtime/KillOption.cpp
src/ocppi/runtime/Option.cpp
src/ocppi/runtime/Runtime.cpp
src/ocppi/runtime/Signal.cpp
src/ocppi/runtime/StartOption.cpp
src/ocppi/runtime/config/ConfigLoader.cpp
src/ocppi/runtime/configure.cpp
src/ocppi/runtime/semver_range.cpp
src/ocppi/runtime/semver_range.hpp
HEADERS
include/ocppi/InvalidArgumentError.hpp
include/ocppi/cli/CLI.hpp
include/ocppi/cli/CommandFailedError.hpp
include/ocppi/cli/crun/Crun.hpp
include/ocppi/cli/runc/Runc.hpp
include/ocppi/cli/youki/Youki.hpp
include/ocppi/runtime/ContainerID.hpp
include/ocppi/runtime/CreateOption.hpp
include/ocppi/runtime/DeleteOption.hpp
include/ocppi/runtime/KillOption.hpp
include/ocppi/runtime/Option.hpp
include/ocppi/runtime/Runtime.hpp
include/ocppi/runtime/Signal.hpp
include/ocppi/runtime/StartOption.hpp
include/ocppi/runtime/StateOption.hpp
include/ocppi/runtime/config/ConfigLoader.hpp
include/ocppi/runtime/config/IncompatibleVersionError.hpp
include/ocppi/runtime/config/InvalidConfigError.hpp
include/ocppi/runtime/config/KeyMissingError.hpp
include/ocppi/runtime/config/WrongTypeError.hpp
include/ocppi/runtime/config/types/Anet.hpp
include/ocppi/runtime/config/types/BlockIO.hpp
include/ocppi/runtime/config/types/BlockIODeviceThrottle.hpp
include/ocppi/runtime/config/types/BlockIODeviceWeight.hpp
include/ocppi/runtime/config/types/BoottimeClass.hpp
include/ocppi/runtime/config/types/Capabilities.hpp
include/ocppi/runtime/config/types/CappedCPU.hpp
include/ocppi/runtime/config/types/CappedMemory.hpp
include/ocppi/runtime/config/types/Class.hpp
include/ocppi/runtime/config/types/Config.hpp
include/ocppi/runtime/config/types/ConsoleSize.hpp
include/ocppi/runtime/config/types/DeviceCgroup.hpp
include/ocppi/runtime/config/types/FluffyCPU.hpp
include/ocppi/runtime/config/types/FluffyMemory.hpp
include/ocppi/runtime/config/types/Generators.hpp
include/ocppi/runtime/config/types/Hook.hpp
include/ocppi/runtime/config/types/Hooks.hpp
include/ocppi/runtime/config/types/HugepageLimit.hpp
include/ocppi/runtime/config/types/Hyperv.hpp
include/ocppi/runtime/config/types/Hypervisor.hpp
include/ocppi/runtime/config/types/IdMapping.hpp
include/ocppi/runtime/config/types/IdType.hpp
include/ocppi/runtime/config/types/Image.hpp
include/ocppi/runtime/config/types/IntelRdt.hpp
include/ocppi/runtime/config/types/IoPriority.hpp
include/ocppi/runtime/config/types/Kernel.hpp
include/ocppi/runtime/config/types/Linux.hpp
include/ocppi/runtime/config/types/LinuxDevice.hpp
include/ocppi/runtime/config/types/LinuxResources.hpp
include/ocppi/runtime/config/types/Mount.hpp
include/ocppi/runtime/config/types/NamespaceReference.hpp
include/ocppi/runtime/config/types/NamespaceType.hpp
include/ocppi/runtime/config/types/NetworkInterfacePriority.hpp
include/ocppi/runtime/config/types/Personality.hpp
include/ocppi/runtime/config/types/PersonalityDomain.hpp
include/ocppi/runtime/config/types/Pids.hpp
include/ocppi/runtime/config/types/Process.hpp
include/ocppi/runtime/config/types/PurpleCPU.hpp
include/ocppi/runtime/config/types/PurpleMemory.hpp
include/ocppi/runtime/config/types/Rdma.hpp
include/ocppi/runtime/config/types/ResourcesNetwork.hpp
include/ocppi/runtime/config/types/Rlimit.hpp
include/ocppi/runtime/config/types/Root.hpp
include/ocppi/runtime/config/types/RootImageFormat.hpp
include/ocppi/runtime/config/types/RootfsPropagation.hpp
include/ocppi/runtime/config/types/Scheduler.hpp
include/ocppi/runtime/config/types/SchedulerFlag.hpp
include/ocppi/runtime/config/types/SchedulerPolicy.hpp
include/ocppi/runtime/config/types/Seccomp.hpp
include/ocppi/runtime/config/types/SeccompAction.hpp
include/ocppi/runtime/config/types/SeccompArch.hpp
include/ocppi/runtime/config/types/SeccompFlag.hpp
include/ocppi/runtime/config/types/SeccompOperators.hpp
include/ocppi/runtime/config/types/Solaris.hpp
include/ocppi/runtime/config/types/Storage.hpp
include/ocppi/runtime/config/types/Syscall.hpp
include/ocppi/runtime/config/types/SyscallArg.hpp
include/ocppi/runtime/config/types/TimeOffsets.hpp
include/ocppi/runtime/config/types/User.hpp
include/ocppi/runtime/config/types/Vm.hpp
include/ocppi/runtime/config/types/Windows.hpp
include/ocppi/runtime/config/types/WindowsDevice.hpp
include/ocppi/runtime/config/types/WindowsNetwork.hpp
include/ocppi/runtime/config/types/WindowsResources.hpp
include/ocppi/runtime/config/types/Zos.hpp
include/ocppi/runtime/config/types/ZosDevice.hpp
include/ocppi/runtime/config/types/helper.hpp
include/ocppi/runtime/features/types/Apparmor.hpp
include/ocppi/runtime/features/types/Cgroup.hpp
include/ocppi/runtime/features/types/Features.hpp
include/ocppi/runtime/features/types/Generators.hpp
include/ocppi/runtime/features/types/IntelRdt.hpp
include/ocppi/runtime/features/types/Linux.hpp
include/ocppi/runtime/features/types/NamespaceType.hpp
include/ocppi/runtime/features/types/Seccomp.hpp
include/ocppi/runtime/features/types/SeccompAction.hpp
include/ocppi/runtime/features/types/SeccompArch.hpp
include/ocppi/runtime/features/types/SeccompFlag.hpp
include/ocppi/runtime/features/types/SeccompOperators.hpp
include/ocppi/runtime/features/types/Selinux.hpp
include/ocppi/runtime/features/types/helper.hpp
include/ocppi/runtime/state/types/Generators.hpp
include/ocppi/runtime/state/types/State.hpp
include/ocppi/runtime/state/types/Status.hpp
include/ocppi/runtime/state/types/helper.hpp
include/ocppi/types/ContainerListItem.hpp
include/ocppi/types/Generators.hpp
include/ocppi/types/helper.hpp
EXAMPLES
parse-config
using-crun
LINK_LIBRARIES
PUBLIC
nlohmann_json::nlohmann_json
tl::expected
PRIVATE
spdlog::spdlog
semver::semver
Boost::process
COMPILE_FEATURES
PUBLIC
cxx_std_17)
46 changes: 46 additions & 0 deletions api/schema/ocppi-types-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"description": "Container list item, compatible wity crun.",
"$schema": "http://json-schema.org/draft-04/schema#",
"$defs": {
"ContainerListItem": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"pid": {
"type": "integer"
},
"status": {
"type": "string"
},
"bundle": {
"type": "string"
},
"created": {
"type": "string",
"format": "date-time"
},
"owner": {
"type": "string"
}
},
"required": [
"id",
"pid",
"status",
"bundle",
"created",
"owner"
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"containerListItem": {
"$ref": "#/$defs/ContainerListItem"
}
},
"additionalProperties": false
}
18 changes: 12 additions & 6 deletions cmake/PFL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function(pfl_init)
cmake_parse_arguments(PFL_INIT "" "INSTALL;ENABLE_TESTING;BUILD_EXAMPLES"
"EXTERNALS" ${ARGN})

message(STATUS "PFL: --==Version: v0.2.4==--")
message(STATUS "PFL: --==Version: v0.2.6==--")

set(PFL_ENABLE_TESTING
${PFL_INIT_ENABLE_TESTING}
Expand All @@ -50,10 +50,10 @@ function(__pfl_configure_files)

configure_file(${IN_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${OUT_FILE} @ONLY)

if(OUT_FILE MATCHES "^include\/.*\.h(h|pp)?$")
if(OUT_FILE MATCHES "^(./)?include\/.*\.h(h|pp)?$")
list(APPEND ${PFL_CONFIGURE_FILES_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/${OUT_FILE})
elseif(OUT_FILE MATCHES "^src\/.*\.(h(h|pp)?|cpp)$")
elseif(OUT_FILE MATCHES "^(./)?src\/.*\.(h(h|pp)?|cpp)$")
list(APPEND ${PFL_CONFIGURE_FILES_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/${OUT_FILE})
else()
Expand Down Expand Up @@ -166,6 +166,11 @@ function(pfl_add_library)

cmake_path(GET CMAKE_CURRENT_SOURCE_DIR FILENAME TARGET_DIR_NAME)

if(TARGET_DIR_NAME MATCHES ".*__.*")
message(
FATAL_ERROR "Invalid directory name ${TARGET_DIR_NAME} contains '__'.")
endif()

if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
set(TARGET_DIR_NAME ${PROJECT_NAME})
endif()
Expand All @@ -176,13 +181,14 @@ function(pfl_add_library)

if(TARGET_PREFIX)
set(TARGET_NAME "${TARGET_PREFIX}__${TARGET_NAME}")
string(REPLACE "__" "::" TARGET_EXPORT_NAME "${TARGET_NAME}")
else()
set(TARGET_EXPORT_NAME "${TARGET_DIR_NAME}::${TARGET_NAME}")
endif()

string(REPLACE "__" "::" TARGET_EXPORT_NAME "${TARGET_NAME}")

message(
STATUS
"PFL:${PFL_MESSAGE_INDENT} Adding library ${TARGET_EXPORT_NAME} at ${CMAKE_CURRENT_SOURCE_DIR}"
"PFL:${PFL_MESSAGE_INDENT} Adding library ${TARGET_NAME} as ${TARGET_EXPORT_NAME} at ${CMAKE_CURRENT_SOURCE_DIR}"
)
set(PFL_MESSAGE_INDENT "${PFL_MESSAGE_INDENT} ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pfl_add_executable(
cxx_std_17
LINK_LIBRARIES
PUBLIC
ocppi::runtime)
ocppi::ocppi)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <initializer_list> // for initializer_list
#include <iostream> // for endl, ostream, cout
#include <map> // for operator!=, operator==
#include <string> // for operator<<
#include <vector> // for vector
#include <iostream> // for basic_ostream, cout
#include <map> // for operator==, operator!=
#include <string> // for char_traits, operat...

#include <nlohmann/json.hpp> // for basic_json, operator<<
#include <nlohmann/json_fwd.hpp> // for json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pfl_add_executable(
src/main.cpp
LINK_LIBRARIES
PUBLIC
ocppi::cli
ocppi::ocppi
PRIVATE
PkgConfig::systemd)
PkgConfig::systemd
spdlog::spdlog)
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <stdio.h> // for FILE, stderr
#include <stdio.h> // for stderr
#include <unistd.h> // for isatty

#include <exception> // for exception, rethrow_exce...
#include <iostream> // for operator<<, char_traits
#include <algorithm> // for max
#include <exception> // for exception_ptr, exception
#include <filesystem> // for path
#include <iostream> // for basic_ostream, operator<<
#include <map> // for operator!=, operator==
#include <memory> // for shared_ptr, make_shared
#include <string> // for operator<<
#include <string> // for char_traits, basic_string
#include <string_view> // for operator<<, string_view
#include <utility> // for move
#include <vector> // for vector
Expand All @@ -15,15 +18,17 @@
#include "nlohmann/json_fwd.hpp" // for json
#include "ocppi/cli/CLI.hpp" // for CLI
#include "ocppi/cli/crun/Crun.hpp" // for Crun
#include "ocppi/runtime/ContainerID.hpp" // IWYU pragma: keep
#include "ocppi/runtime/Signal.hpp" // IWYU pragma: keep
#include "ocppi/runtime/list/types/Generators.hpp" // IWYU pragma: keep
#include "ocppi/runtime/ContainerID.hpp" // for ContainerID
#include "ocppi/runtime/Signal.hpp" // for Signal
#include "ocppi/runtime/state/types/Generators.hpp" // IWYU pragma: keep
#include "spdlog/common.h" // for trace
#include "spdlog/logger.h" // for logger
#include "spdlog/sinks/stdout_color_sinks.h" // for stderr_color_sink_mt
#include "spdlog/sinks/systemd_sink.h" // for systemd_sink_mt
#include "tl/expected.hpp" // for expected
#include "ocppi/types/ContainerListItem.hpp" // for ContainerListItem
#include "ocppi/types/Generators.hpp" // IWYU pragma: keep
#include "spdlog/common.h" // for level_enum, color_mode
#include "spdlog/logger.h" // for logger
#include "spdlog/sinks/ansicolor_sink.h" // for ansicolor_stderr_sink
#include "spdlog/sinks/stdout_color_sinks.h" // for stderr_color_sink_mt
#include "spdlog/sinks/systemd_sink.h" // for systemd_sink_mt, system...
#include "tl/expected.hpp" // for expected

namespace spdlog
{
Expand Down Expand Up @@ -78,9 +83,14 @@ auto main() -> int
return -1;
}

if (list->empty()) {
std::cerr << "No container exists." << std::endl;
return 0;
}

for (auto item : list.value()) {
nlohmann::json j = item;
std::cout << "exists container " << j.dump() << std::endl;
std::cerr << "exists container " << j.dump() << std::endl;
}

auto state = cli->state(list->front().id.c_str());
Expand Down
File renamed without changes.
Loading