From 17a33a00c21ef162db39ef66ba9d6360ff743f01 Mon Sep 17 00:00:00 2001 From: Alexander Reichert Date: Thu, 11 Apr 2024 11:46:47 +0200 Subject: [PATCH] Refactor package and Docker builds --- .github/workflows/build.yml | 22 ++- .github/workflows/deploy-cr.yml | 4 +- .github/workflows/deploy-dl.yml | 8 +- CMakeLists.txt | 11 +- docker/CMakeLists.txt | 89 ++++++++++++ docker/flecs-slim/CMakeLists.txt | 31 +++++ .../docker => docker}/flecs-slim/Dockerfile | 10 +- .../flecs-slim/fs/entrypoint.sh | 2 +- docker/flecs/CMakeLists.txt | 31 +++++ {flecs/docker => docker}/flecs/Dockerfile | 3 +- .../docker => docker}/flecs/fs/entrypoint.sh | 2 +- flecs-build | 2 +- flecs/CMakeLists.txt | 128 ++---------------- pkg/CMakeLists.txt | 82 +++++++++++ {flecs/pkg/debian => pkg}/DEBIAN/postinst | 4 +- {flecs/pkg/debian => pkg}/DEBIAN/postrm | 0 {flecs/pkg/debian => pkg}/DEBIAN/prerm | 0 .../fs/opt/flecsd => pkg/fs}/bin/flecsd.sh | 0 .../fs/etc}/flecs/docker-compose.yml | 0 {flecs/pkg/tar => pkg/fs}/etc/init.d/flecs | 2 +- .../fs}/lib/systemd/system/flecs.service | 8 +- 21 files changed, 278 insertions(+), 161 deletions(-) create mode 100644 docker/CMakeLists.txt create mode 100644 docker/flecs-slim/CMakeLists.txt rename {flecs/docker => docker}/flecs-slim/Dockerfile (88%) rename {flecs/docker => docker}/flecs-slim/fs/entrypoint.sh (91%) create mode 100644 docker/flecs/CMakeLists.txt rename {flecs/docker => docker}/flecs/Dockerfile (80%) rename {flecs/docker => docker}/flecs/fs/entrypoint.sh (92%) create mode 100644 pkg/CMakeLists.txt rename {flecs/pkg/debian => pkg}/DEBIAN/postinst (67%) rename {flecs/pkg/debian => pkg}/DEBIAN/postrm (100%) rename {flecs/pkg/debian => pkg}/DEBIAN/prerm (100%) rename {flecs/pkg/fs/opt/flecsd => pkg/fs}/bin/flecsd.sh (100%) rename {flecs/pkg/tar/etc/opt => pkg/fs/etc}/flecs/docker-compose.yml (100%) rename {flecs/pkg/tar => pkg/fs}/etc/init.d/flecs (98%) rename {flecs/pkg/fs/usr => pkg/fs}/lib/systemd/system/flecs.service (65%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e554b7341..64484651b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,34 +34,31 @@ jobs: - name: "CMake: Configure" run: | - cmake -G Ninja -B build/${{ inputs.arch }} ${{ inputs.cmake_args }} -DARCH=${{ inputs.arch }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DCMAKE_INSTALL_PREFIX=out/${{ inputs.arch }} + cmake -G Ninja -B build/${{ inputs.arch }} ${{ inputs.cmake_args }} -DARCH=${{ inputs.arch }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} - name: "CMake: Build" run: | cmake --build build/${{ inputs.arch }} - - name: "CMake: Install" - run: | - cmake --build build/${{ inputs.arch }} --target install - - name: "CMake: Docker" run: | + cmake --install build/${{ inputs.arch }} --component docker cmake --build build/${{ inputs.arch }} --target docker - name: "CMake: Package" run: | - cmake --build build/${{ inputs.arch }} --target packages + cmake --build build/${{ inputs.arch }} --target package - - name: "CMake: Version" + - name: "CMake: Latest" run: | - cmake --build build/${{ inputs.arch }} --target version | tail -n 1 > out/${{ inputs.arch }}.core_version + cmake --build build/${{ inputs.arch }} --target version -- --quiet >build/${{ inputs.arch }}/latest_flecs_${{ inputs.arch }} - name: Archive Docker image archives uses: actions/upload-artifact@v4 with: name: docker_${{ inputs.arch }} path: | - out/${{ inputs.arch }}/docker/*.tar + build/${{ inputs.arch }}/docker/**/*.tar retention-days: 1 - name: Archive packages @@ -69,8 +66,7 @@ jobs: with: name: packages_${{ inputs.arch }} path: | - out/${{ inputs.arch }}/pkg/*.deb - out/${{ inputs.arch }}/pkg/*.tar - out/${{ inputs.arch }}/latest_flecs_${{ inputs.arch }} - out/${{ inputs.arch }}.core_version + build/${{ inputs.arch }}/pkg/flecs_*_${{ inputs.arch }}.deb + build/${{ inputs.arch }}/pkg/flecs_*_${{ inputs.arch }}.tar + build/${{ inputs.arch }}/latest_flecs_${{ inputs.arch }} retention-days: 1 diff --git a/.github/workflows/deploy-cr.yml b/.github/workflows/deploy-cr.yml index 0057e73f7..d10674597 100644 --- a/.github/workflows/deploy-cr.yml +++ b/.github/workflows/deploy-cr.yml @@ -17,7 +17,7 @@ jobs: uses: actions/download-artifact@v4 with: pattern: docker_* - path: out/ + path: deploy/ - name: Login to Registry uses: docker/login-action@v3 @@ -28,7 +28,7 @@ jobs: - name: Push Docker images run: | - for archive in `find out/ -name "*.tar"`; do \ + for archive in `find deploy/ -name "*.tar"`; do \ DOCKER_IMAGE=$(docker load --quiet --input ${archive} | cut -f2- -d ':'); \ DOCKER_IMAGES="${DOCKER_IMAGES} `echo ${DOCKER_IMAGE} | sed -E 's/(.*)-.+$/\1/p'`"; \ docker push ${DOCKER_IMAGE}; \ diff --git a/.github/workflows/deploy-dl.yml b/.github/workflows/deploy-dl.yml index 7f1dbc0d4..444947473 100644 --- a/.github/workflows/deploy-dl.yml +++ b/.github/workflows/deploy-dl.yml @@ -19,7 +19,7 @@ jobs: uses: actions/download-artifact@v4 with: name: packages_${{ inputs.arch }} - path: out/ + path: deploy/ - name: Azure Login uses: azure/login@v1 @@ -31,8 +31,8 @@ jobs: with: azcliversion: 2.53.0 inlineScript: | - export CORE_VERSION=$(find out/ -name ${{ inputs.arch }}.core_version -exec head -n1 {} \;) - find out/ -name latest_flecs_${{ inputs.arch }} -exec \ + export CORE_VERSION=$(find deploy/ -name latest_flecs_* -exec head -n1 {} \;) + find deploy/ -name latest_flecs_${{ inputs.arch }} -exec \ bash -c 'export FILE={}; export BASE_FILE=$(basename "${FILE}"); echo "Uploading ${FILE}"; az storage blob upload --account-name flecs --container-name flecs-dl --name ${{ inputs.deploy_dir }}/flecs/${BASE_FILE} --file "${FILE}" --overwrite' \; - find out/ \( -name "*.deb" -o -name "*.tar" \) -exec \ + find deploy/ \( -name "*.deb" -o -name "*.tar" \) -exec \ bash -c 'export FILE={}; export BASE_FILE=$(basename "${FILE}"); echo "Uploading ${FILE}"; az storage blob upload --account-name flecs --container-name flecs-dl --name ${{ inputs.deploy_dir }}/flecs/${CORE_VERSION}/${BASE_FILE##*.}/${BASE_FILE} --file "${FILE}" --overwrite' \; diff --git a/CMakeLists.txt b/CMakeLists.txt index a258c688a..945776a7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,12 +53,11 @@ add_subdirectory(flecs-external) add_subdirectory(flunder) add_subdirectory(flecs) -include(flecs-rules) - -add_custom_command(TARGET packages POST_BUILD - COMMAND echo -n ${FLECS_VERSION_FULL} >${CMAKE_INSTALL_PREFIX}/latest_flecs_${ARCH} -) - add_custom_target(version COMMAND echo "${FLECS_VERSION_FULL}" ) + +add_subdirectory(docker) +add_subdirectory(pkg) + +include(flecs-rules) diff --git a/docker/CMakeLists.txt b/docker/CMakeLists.txt new file mode 100644 index 000000000..4217c6c58 --- /dev/null +++ b/docker/CMakeLists.txt @@ -0,0 +1,89 @@ +# Copyright 2021-2024 FLECS Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function(install_external lib dest cmp) + # try to resolve aliased target + get_property(aliased_target TARGET ${lib} PROPERTY ALIASED_TARGET) + if("${aliased_target}" STREQUAL "") + # use original target if not aliased + set(aliased_target ${lib}) + endif() + + get_property(library_type TARGET ${lib} PROPERTY TYPE) + if ("${library_type}" STREQUAL "UNKNOWN_LIBRARY") + get_property(library_location TARGET ${lib} PROPERTY IMPORTED_LOCATION) + if ("${library_location}" STREQUAL "") + message(FATAL_ERROR "Could not determine IMPORTED_LOCATION of ${lib}") + endif() + install( + CODE "file ( + INSTALL ${library_location} + DESTINATION ${dest} + FOLLOW_SYMLINK_CHAIN + )" + ) + else() + get_property(library_artifacts TARGET ${lib} PROPERTY IMPORTED_RUNTIME_ARTIFACTS) + install( + IMPORTED_RUNTIME_ARTIFACTS ${aliased_target} + DESTINATION ${dest} + COMPONENT ${cmp} + EXCLUDE_FROM_ALL + ) + endif() +endfunction() + +function(stage_docker_fs) + install( + TARGETS daemon RUNTIME + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fs/opt/flecs/bin + ) + install( + TARGETS lib flunder.shared LIBRARY + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib + ) + get_property(curl_target TARGET CURL::libcurl PROPERTY ALIASED_TARGET) + install( + IMPORTED_RUNTIME_ARTIFACTS ${curl_target} + DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/fs/usr/local/lib + ) + install_external(cpr::cpr ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(CURL::libcurl ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(Libusb::Libusb ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(OpenSSL::Crypto ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(OpenSSL::SSL ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(yaml-cpp::yaml-cpp ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + install_external(zenohc::lib ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib docker) + + # Installing LibArchive this way won't work, as: + # lrwxrwxrwx libarchive.so -> libarchive.so.13.x.y + # lrwxrwxrwx libarchive.so.13 -> libarchive.so.13.x.y + # -rwxr-xr-x libarchive.so.13.x.y + # As LibArchive's IMPORTED_LOCATION points to the .so file, libarchive.so and + # libarchive.so.13.x.y would be installed, while libarchive.so.13 is the one we + # need during runtime. + get_property(archive_lib TARGET LibArchive::LibArchive PROPERTY IMPORTED_LOCATION) + file(GLOB archive_libs "${archive_lib}*") + install( + CODE "file ( + INSTALL ${archive_libs} + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fs/usr/local/lib + )" + COMPONENT docker + EXCLUDE_FROM_ALL + ) +endfunction() + +add_subdirectory(flecs) +add_subdirectory(flecs-slim) diff --git a/docker/flecs-slim/CMakeLists.txt b/docker/flecs-slim/CMakeLists.txt new file mode 100644 index 000000000..f58bff1db --- /dev/null +++ b/docker/flecs-slim/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2021-2024 FLECS Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +install(PROGRAMS fs/entrypoint.sh + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fs/opt/flecs/bin + COMPONENT docker + EXCLUDE_FROM_ALL +) +install(FILES Dockerfile + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + COMPONENT docker + EXCLUDE_FROM_ALL +) + +stage_docker_fs() + +set(DOCKER_REGISTRY "flecspublic.azurecr.io") +set(DOCKER_IMAGE "flecs-slim") +set(DOCKER_TAG "${FLECS_VERSION_FULL}") +include(flecs-docker) diff --git a/flecs/docker/flecs-slim/Dockerfile b/docker/flecs-slim/Dockerfile similarity index 88% rename from flecs/docker/flecs-slim/Dockerfile rename to docker/flecs-slim/Dockerfile index ef79359cd..95981901f 100644 --- a/flecs/docker/flecs-slim/Dockerfile +++ b/docker/flecs-slim/Dockerfile @@ -1,15 +1,13 @@ FROM debian:bookworm-slim AS docker-downloader -ARG ARCH - -ENV BASE_URL=dl.flecs.tech - RUN apt-get update && \ apt-get --yes --no-install-recommends install \ ca-certificates wget && \ apt-get --yes clean && \ rm -rf /var/lib/apt/lists/* +ARG ARCH + RUN [ "${ARCH}" = "amd64" ] && wget https://download.docker.com/linux/static/stable/x86_64/docker-24.0.6.tgz || true RUN [ "${ARCH}" = "armhf" ] && wget https://download.docker.com/linux/static/stable/armhf/docker-24.0.6.tgz || true RUN [ "${ARCH}" = "arm64" ] && wget https://download.docker.com/linux/static/stable/aarch64/docker-24.0.6.tgz || true @@ -19,13 +17,13 @@ RUN mkdir -p /fs/usr/local/bin && tar -C /fs/usr/local/bin --strip-components=1 FROM debian:bookworm-slim RUN apt-get update && \ - apt-get --yes --no-install-recommends install ca-certificates && \ + apt-get --yes --no-install-recommends install \ + ca-certificates && \ apt-get --yes clean && \ rm -rf /var/lib/apt/lists/* COPY --from=docker-downloader /fs / ADD fs/ / -ADD flecs-slim/fs/ / RUN ldconfig diff --git a/flecs/docker/flecs-slim/fs/entrypoint.sh b/docker/flecs-slim/fs/entrypoint.sh similarity index 91% rename from flecs/docker/flecs-slim/fs/entrypoint.sh rename to docker/flecs-slim/fs/entrypoint.sh index 1905564b6..f17721a13 100755 --- a/flecs/docker/flecs-slim/fs/entrypoint.sh +++ b/docker/flecs-slim/fs/entrypoint.sh @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -PATH=${PATH}:/opt/flecs/bin +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin # verify docker socket is ready while ! docker version >/dev/null 2>&1; do diff --git a/docker/flecs/CMakeLists.txt b/docker/flecs/CMakeLists.txt new file mode 100644 index 000000000..6ec4f5656 --- /dev/null +++ b/docker/flecs/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2021-2024 FLECS Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +install(PROGRAMS fs/entrypoint.sh + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fs/opt/flecs/bin + COMPONENT docker + EXCLUDE_FROM_ALL +) +install(FILES Dockerfile + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + COMPONENT docker + EXCLUDE_FROM_ALL +) + +stage_docker_fs() + +set(DOCKER_REGISTRY "flecspublic.azurecr.io") +set(DOCKER_IMAGE "flecs") +set(DOCKER_TAG "${FLECS_VERSION_FULL}") +include(flecs-docker) diff --git a/flecs/docker/flecs/Dockerfile b/docker/flecs/Dockerfile similarity index 80% rename from flecs/docker/flecs/Dockerfile rename to docker/flecs/Dockerfile index da097cac0..6bdc00bdd 100644 --- a/flecs/docker/flecs/Dockerfile +++ b/docker/flecs/Dockerfile @@ -2,7 +2,7 @@ FROM debian:bookworm-slim RUN apt-get update && \ apt-get --yes --no-install-recommends install \ - ca-certificates docker.io git iptables libusb-1.0-0 procps && \ + ca-certificates docker.io git iptables procps && \ apt-get --yes clean && \ rm -rf /var/lib/apt/lists/* @@ -10,7 +10,6 @@ RUN update-alternatives --set iptables /usr/sbin/iptables-legacy && \ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy ADD fs/ / -ADD flecs/fs/ / RUN ldconfig diff --git a/flecs/docker/flecs/fs/entrypoint.sh b/docker/flecs/fs/entrypoint.sh similarity index 92% rename from flecs/docker/flecs/fs/entrypoint.sh rename to docker/flecs/fs/entrypoint.sh index ffe5da6ed..40faca190 100755 --- a/flecs/docker/flecs/fs/entrypoint.sh +++ b/docker/flecs/fs/entrypoint.sh @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/flecs/bin +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin containerd >/tmp/containerd.log 2>&1 & dockerd >/tmp/dockerd.log 2>&1 & diff --git a/flecs-build b/flecs-build index 638299367..02df3aa97 160000 --- a/flecs-build +++ b/flecs-build @@ -1 +1 @@ -Subproject commit 63829936701e25e2e49fc5eaca682f495dd9196e +Subproject commit 02df3aa971af38fe874b1582f6bb788027d6acd3 diff --git a/flecs/CMakeLists.txt b/flecs/CMakeLists.txt index ef9ca4332..4715f0278 100644 --- a/flecs/CMakeLists.txt +++ b/flecs/CMakeLists.txt @@ -46,126 +46,18 @@ target_link_libraries(daemon PRIVATE yaml-cpp::yaml-cpp ) -# Get all propreties that cmake supports -if(NOT CMAKE_PROPERTY_LIST) - execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) +include(GNUInstallDirs) - # Convert command output into a CMake list - string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") - string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") - list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST) -endif() - -function(print_properties) - message("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") -endfunction() - -function(print_target_properties target) - if(NOT TARGET ${target}) - message(STATUS "There is no target named '${target}'") - return() - endif() - - foreach(property ${CMAKE_PROPERTY_LIST}) - string(REPLACE "" "${CMAKE_BUILD_TYPE}" property ${property}) - - # Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i - #if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_" OR property MATCHES "_LOCATION$") - # continue() - #endif() - - get_property(was_set TARGET ${target} PROPERTY ${property} SET) - if(was_set) - get_target_property(value ${target} ${property}) - message("${target} ${property} = ${value}") - endif() - endforeach() -endfunction() - -#print_target_properties(LibArchive::LibArchive) -#message(FATAL_ERROR) - -# install executable flecsd for packaging -install( - TARGETS daemon RUNTIME - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/opt/flecs/bin -) - -# install shared objects for packaging -install( - TARGETS lib flunder.shared LIBRARY - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/usr/local/lib/${MACHINE} -) - -# Alias targets cannot be installed, so retrieve the aliased targets first -get_property(curl_target TARGET CURL::libcurl PROPERTY ALIASED_TARGET) -get_property(zenohc_target TARGET zenohc::lib PROPERTY ALIASED_TARGET) -install( - IMPORTED_RUNTIME_ARTIFACTS - cpr::cpr - ${curl_target} - yaml-cpp::yaml-cpp - ${zenohc_target} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/usr/local/lib/${MACHINE} +install(TARGETS daemon + RUNTIME + COMPONENT native ) - -# These libs are of type "UNKNOWN", and cannot be installed with IMPORTED_RUNTIME_ARTIFACTS -get_property(openssl_crypto_lib TARGET OpenSSL::Crypto PROPERTY IMPORTED_LOCATION) -get_property(openssl_ssl_lib TARGET OpenSSL::SSL PROPERTY IMPORTED_LOCATION) -install( - CODE "file ( - INSTALL ${openssl_crypto_lib} ${openssl_ssl_lib} ${pkgcfg_lib_libusb_usb-1.0} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/usr/local/lib/${MACHINE} - FOLLOW_SYMLINK_CHAIN - )" +install(FILES ${FLECS_SOURCE_DIR}/pkg/fs/lib/systemd/system/flecs.service + DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/system/ + COMPONENT native ) - -# Installing LibArchive this way won't work, however, as: -# lrwxrwxrwx libarchive.so -> libarchive.so.13.x.y -# lrwxrwxrwx libarchive.so.13 -> libarchive.so.13.x.y -# -rwxr-xr-x libarchive.so.13.x.y -# As LibArchive's IMPORTED_LOCATION points to the .so file, libarchive.so and -# libarchive.so.13.x.y would be installed, while libarchive.so.13 is the one we -# need during runtime. -get_property(archive_lib TARGET LibArchive::LibArchive PROPERTY IMPORTED_LOCATION) -file(GLOB archive_libs "${archive_lib}*") -install( - CODE "file ( - INSTALL ${archive_libs} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/usr/local/lib/${MACHINE} - )" -) - -# install helper scripts for packaging install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/docker/fs/opt/flecs/bin - USE_SOURCE_PERMISSIONS -) - -# configure Docker image flecs -set(DOCKER_REGISTRY "flecspublic.azurecr.io") -set(DOCKER_IMAGE "flecs") -set(DOCKER_TAG "${FLECS_VERSION_FULL}") -include(flecs-docker) - -# configure Docker image flecs-slim -set(DOCKER_REGISTRY "flecspublic.azurecr.io") -set(DOCKER_IMAGE "flecs-slim") -set(DOCKER_TAG "${FLECS_VERSION_FULL}") -include(flecs-docker) - -# configure package -set(PACKAGE flecs) -set(PACKAGE_VERSION ${FLECS_VERSION_FULL}) -set(PACKAGE_DESC FLECS) -set(PACKAGE_DEPENDS "docker-ce (>= 20.10.5) | docker.io (>= 20.10.5)") - -add_custom_target( - flecs_deb-pkg-copy - WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/pkg - COMMAND pwd - COMMAND sed -i 's/^DOCKER_TAG.*/DOCKER_TAG=${DOCKER_TAG}/g' */opt/flecsd/bin/flecsd.sh + TARGETS lib flunder.shared LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT native ) - -include(flecs-package) \ No newline at end of file diff --git a/pkg/CMakeLists.txt b/pkg/CMakeLists.txt new file mode 100644 index 000000000..1df355fc5 --- /dev/null +++ b/pkg/CMakeLists.txt @@ -0,0 +1,82 @@ +# Copyright 2021-2024 FLECS Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# configure packages + +set(CPACK_GENERATOR DEB TGZ) + +set(CPACK_DEB_COMPONENT_INSTALL 1) +set(CPACK_ARCHIVE_COMPONENT_INSTALL 1) + +set(CPACK_PACKAGE_NAME "flecs") +set(CPACK_PACKAGE_VERSION "${FLECS_VERSION_FULL}") + +set(CPACK_PACKAGE_ARCHITECTURE "${ARCH}") +set(CPACK_PACKAGE_CONTACT "FLECS Technologies GmbH ") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "FLECS is the ultimate open marketplace for industrial automation") +set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") + +set(CPACK_ARCHIVE_FLECS-TAR-PKG_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}) +set(CPACK_DEBIAN_FLECS-DEB-PKG_PACKAGE_NAME ${CPACK_PACKAGE_NAME}) + +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_PACKAGE_ARCHITECTURE}") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "docker-ce (>= 20.10.5) | docker.io (>= 20.10.5)") +list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/postinst") +list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/postrm") +list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/prerm") + +include(GNUInstallDirs) + +# Functions to install common components +function(install_common_files cmp) + install(CODE + "execute_process( + COMMAND sed s/^DOCKER_TAG.*/DOCKER_TAG=${FLECS_VERSION_FULL}/g ${CMAKE_CURRENT_SOURCE_DIR}/fs/bin/flecsd.sh + OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/flecsd.sh + )" + COMPONENT ${cmp} + EXCLUDE_FROM_ALL + ) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/flecsd.sh + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${cmp} + EXCLUDE_FROM_ALL + ) + install(FILES fs/lib/systemd/system/flecs.service + DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/system + COMPONENT ${cmp} + EXCLUDE_FROM_ALL + ) +endfunction() + +# Install .deb package contents +install_common_files(flecs-deb-pkg) + +# Install .tar.gz package contents +install_common_files(flecs-tar-pkg) +install(PROGRAMS fs/etc/init.d/flecs + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d/ + COMPONENT flecs-tar-pkg + EXCLUDE_FROM_ALL +) +install(FILES fs/etc/flecs/docker-compose.yml + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/flecs/ + COMPONENT flecs-tar-pkg + EXCLUDE_FROM_ALL +) + +set(CPACK_COMPONENTS_ALL "flecs-deb-pkg" "flecs-tar-pkg") + +include(CPack) diff --git a/flecs/pkg/debian/DEBIAN/postinst b/pkg/DEBIAN/postinst similarity index 67% rename from flecs/pkg/debian/DEBIAN/postinst rename to pkg/DEBIAN/postinst index 4c0364e98..77fe2d1b7 100755 --- a/flecs/pkg/debian/DEBIAN/postinst +++ b/pkg/DEBIAN/postinst @@ -1,12 +1,12 @@ #!/bin/bash -PATH=/sbin:/bin:/usr/sbin:/usr/bin +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin case $1 in abort-upgrade) ;; configure|abort-remove) - /opt/flecsd/bin/flecsd.sh migrate || exit 1 + flecsd.sh migrate || exit 1 systemctl preset ##PACKAGE## systemctl is-enabled ##PACKAGE## >/dev/null && systemctl start ##PACKAGE## ;; diff --git a/flecs/pkg/debian/DEBIAN/postrm b/pkg/DEBIAN/postrm similarity index 100% rename from flecs/pkg/debian/DEBIAN/postrm rename to pkg/DEBIAN/postrm diff --git a/flecs/pkg/debian/DEBIAN/prerm b/pkg/DEBIAN/prerm similarity index 100% rename from flecs/pkg/debian/DEBIAN/prerm rename to pkg/DEBIAN/prerm diff --git a/flecs/pkg/fs/opt/flecsd/bin/flecsd.sh b/pkg/fs/bin/flecsd.sh similarity index 100% rename from flecs/pkg/fs/opt/flecsd/bin/flecsd.sh rename to pkg/fs/bin/flecsd.sh diff --git a/flecs/pkg/tar/etc/opt/flecs/docker-compose.yml b/pkg/fs/etc/flecs/docker-compose.yml similarity index 100% rename from flecs/pkg/tar/etc/opt/flecs/docker-compose.yml rename to pkg/fs/etc/flecs/docker-compose.yml diff --git a/flecs/pkg/tar/etc/init.d/flecs b/pkg/fs/etc/init.d/flecs similarity index 98% rename from flecs/pkg/tar/etc/init.d/flecs rename to pkg/fs/etc/init.d/flecs index 636fd74bd..a8937e16f 100755 --- a/flecs/pkg/tar/etc/init.d/flecs +++ b/pkg/fs/etc/init.d/flecs @@ -15,7 +15,7 @@ PATH=${PATH}:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin SCRIPTNAME=$(readlink -f ${0}) SERVICE=flecsd -BINARY=/opt/flecsd/bin/flecsd.sh +BINARY=/usr/local/bin/flecsd.sh [ ! -x "${DAEMON}" ] && exit 5 diff --git a/flecs/pkg/fs/usr/lib/systemd/system/flecs.service b/pkg/fs/lib/systemd/system/flecs.service similarity index 65% rename from flecs/pkg/fs/usr/lib/systemd/system/flecs.service rename to pkg/fs/lib/systemd/system/flecs.service index c6d598741..77b39d873 100644 --- a/flecs/pkg/fs/usr/lib/systemd/system/flecs.service +++ b/pkg/fs/lib/systemd/system/flecs.service @@ -11,12 +11,12 @@ Wants=containerd.service Type=exec TimeoutStartSec=infinity TimeoutStopSec=infinity -ExecStartPre=/bin/bash -x /opt/flecsd/bin/flecsd.sh pull -ExecStartPre=/bin/bash -x /opt/flecsd/bin/flecsd.sh remove -ExecStartPre=/bin/bash -x /opt/flecsd/bin/flecsd.sh create +ExecStartPre=/bin/bash -x /usr/local/bin/flecsd.sh pull +ExecStartPre=/bin/bash -x /usr/local/bin/flecsd.sh remove +ExecStartPre=/bin/bash -x /usr/local/bin/flecsd.sh create ExecStart=/usr/bin/docker start -a flecs-flecsd ExecStop=/usr/bin/docker stop --time 120 flecs-flecsd -ExecStopPost=/bin/bash -x /opt/flecsd/bin/flecsd.sh remove +ExecStopPost=/bin/bash -x /usr/local/bin/flecsd.sh remove Restart=on-failure RestartPreventExitStatus=SIGKILL