Skip to content
New issue

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

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

Already on GitHub? # to your account

Refactor package and Docker builds #765

Merged
merged 1 commit into from
Apr 11, 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
22 changes: 9 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,39 @@ 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
uses: actions/upload-artifact@v4
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
4 changes: 2 additions & 2 deletions .github/workflows/deploy-cr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/download-artifact@v4
with:
pattern: docker_*
path: out/
path: deploy/

- name: Login to Registry
uses: docker/#-action@v3
Expand All @@ -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}; \
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy-dl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/download-artifact@v4
with:
name: packages_${{ inputs.arch }}
path: out/
path: deploy/

- name: Azure Login
uses: azure/#@v1
Expand All @@ -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' \;
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
89 changes: 89 additions & 0 deletions docker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions docker/flecs-slim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions docker/flecs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions flecs/docker/flecs/Dockerfile → docker/flecs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ 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/*

RUN update-alternatives --set iptables /usr/sbin/iptables-legacy && \
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

ADD fs/ /
ADD flecs/fs/ /

RUN ldconfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
Loading