diff --git a/.gitignore b/.gitignore index f75b3862..9d6e843b 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,7 @@ _deps *_CPack_Packages/ *.deb out/ + +# Ubuntu Snap files +*.snap +snap/ diff --git a/build/build-snaps.sh b/build/build-snaps.sh new file mode 100755 index 00000000..c0d6de34 --- /dev/null +++ b/build/build-snaps.sh @@ -0,0 +1,29 @@ +#! /bin/bash + +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +set -e + +if [ $1 == "agent" -o $1 == "sdk-tests" ] +then + echo "Building $1 snap..." + + if [ ! -d "./snap" ] + then + mkdir ./snap + fi + + if [ $1 == "agent" ] + then + cp ./snapcraft-options/snapcraft-agent.yaml ./snap/snapcraft.yaml + + else + cp ./snapcraft-options/snapcraft-sdk.yaml ./snap/snapcraft.yaml + fi + + snapcraft + +else + echo "$1 is not a valid snap option, valid options are 'agent' or 'sdk-tests'" +fi \ No newline at end of file diff --git a/sdk-cpp/tests/CMakeLists.txt b/sdk-cpp/tests/CMakeLists.txt index e5d3fccc..7d1978cd 100644 --- a/sdk-cpp/tests/CMakeLists.txt +++ b/sdk-cpp/tests/CMakeLists.txt @@ -69,6 +69,10 @@ add_executable(deliveryoptimization-sdk-tests ${test_source}) target_compile_definitions(deliveryoptimization-sdk-tests PRIVATE DO_ENABLE_EXCEPTIONS) add_platform_interface_definitions(deliveryoptimization-sdk-tests) +if (DO_BUILD_FOR_SNAP) + target_compile_definitions(deliveryoptimization-sdk-tests PRIVATE DO_BUILD_FOR_SNAP) +endif () + target_include_directories(deliveryoptimization-sdk-tests PRIVATE ${dosdkcpp_private_includes} diff --git a/sdk-cpp/tests/test_data.cpp b/sdk-cpp/tests/test_data.cpp index e0604e13..577c2b0b 100644 --- a/sdk-cpp/tests/test_data.cpp +++ b/sdk-cpp/tests/test_data.cpp @@ -10,11 +10,17 @@ const uint64_t g_smallFileSizeBytes = 1837u; const uint64_t g_largeFileSizeBytes = 536870440u; const uint64_t g_prodFileSizeBytes = 25006511u; +#ifdef DO_BUILD_FOR_SNAP + std::string downloadPath = "/var/lib/deliveryoptimization-snap-downloads-root"; +#else + std::string downloadPath = (boost::filesystem::temp_directory_path()).string(); +#endif + const std::string g_largeFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/ReplacementDCATFile.txt"; const std::string g_malformedFilePath = "?f309adfasdf///dfasdfj39fjasldfjasdf/// ///.1"; -const std::string g_tmpFileName = (boost::filesystem::temp_directory_path() / boost::filesystem::path("docsdk_testfile.txt")).string(); -const std::string g_tmpFileName2 = (boost::filesystem::temp_directory_path() / boost::filesystem::path("docsdk_testfile2.txt")).string(); -const std::string g_tmpFileName3 = (boost::filesystem::temp_directory_path() / boost::filesystem::path("docsdk_testfile3.txt")).string(); +const std::string g_tmpFileName = (downloadPath / boost::filesystem::path("docsdk_testfile.txt")).string(); +const std::string g_tmpFileName2 = (downloadPath / boost::filesystem::path("docsdk_testfile2.txt")).string(); +const std::string g_tmpFileName3 = (downloadPath / boost::filesystem::path("docsdk_testfile3.txt")).string(); const std::string g_smallFileUrl = "http://main.oremdl.microsoft.com.nsatc.net/dotc/49c591d405d307e25e72a19f7e79b53d69f19954/43A54FC03C6A979E9AAEAE2493757D1429A5C8A8D093FB7B8103E8CC8DF7B6B6"; const std::string g_smallFilePhfInfoJson = R"( { diff --git a/snap/snapcraft.yaml b/snapcraft-options/snapcraft-agent.yaml similarity index 87% rename from snap/snapcraft.yaml rename to snapcraft-options/snapcraft-agent.yaml index 768e730a..ba61fcd0 100644 --- a/snap/snapcraft.yaml +++ b/snapcraft-options/snapcraft-agent.yaml @@ -1,7 +1,7 @@ name: deliveryoptimization-client base: core20 # the base snap is the execution environment for this snap version: '0.1' -summary: Ubuntu Core 20.04 DO +summary: Ubuntu Core 20.04 DO Agent description: | A proof-of-concept for the Delivery Optimization Client Ubuntu Core snap. @@ -64,7 +64,7 @@ parts: - libwind0-heimdal apps: - deliveryoptimization-client: + agent: command: bin/deliveryoptimization-agent daemon: simple refresh-mode: restart @@ -84,3 +84,14 @@ slots: interface: content content: config-file write: [ $SNAP_DATA/etc/deliveryoptimization-agent/sdk-config.json ] + +plugs: + client-downloads-folder: + interface: content + content: client-downloads-folder + target: $SNAP_DATA/deliveryoptimization-snap-downloads-root + +layout: +# adu_data_dir + /var/lib/deliveryoptimization-snap-downloads-root: + symlink: $SNAP_DATA/deliveryoptimization-snap-downloads-root \ No newline at end of file diff --git a/snapcraft-options/snapcraft-sdk.yaml b/snapcraft-options/snapcraft-sdk.yaml new file mode 100644 index 00000000..a2ee89d0 --- /dev/null +++ b/snapcraft-options/snapcraft-sdk.yaml @@ -0,0 +1,75 @@ +name: deliveryoptimization-sdk-tests +base: core20 # the base snap is the execution environment for this snap +version: '0.1' +summary: Ubuntu Core 20.04 DO SDK Tests +description: | + SDK snap (consumer) to test communication with the DO agent snap (producer). + +grade: devel # must be 'stable' to release into candidate/stable channels +confinement: devmode # use 'strict' once you have the right plugs and slots + +##### +# +# Keywords +# +# after - Specifies part's dependencies. +# See https://snapcraft.io/docs/parts-lifecycle#heading--step-dependencies +# https://snapcraft.io/docs/parts-lifecycle +# plugin - Specifies a plugin required for building the part. +# +# slot - Specifies a code section to be shared with other snaps using Content Interface. [PROVIDER] +# See https://snapcraft.io/docs/content-interface +# plug - Specifies a target folder to access the files shared by the provider (or providers). [CONSUMER] +# See https://snapcraft.io/docs/content-interface +# +#### + +parts: + installdeps: + plugin: nil + source: . + override-build: | + ./build/scripts/bootstrap.sh --platform ubuntu2004 --install build + + sdk: + plugin: python + source: . + override-build: | + python3 ./build/build.py --project sdk --build-for-snap + mkdir -p ../install/bin + mkdir -p ../install/lib + cp /tmp/build-deliveryoptimization-sdk/linux-debug/sdk-cpp/tests/deliveryoptimization-sdk-tests ../install/bin/deliveryoptimization-sdk-tests + cp /tmp/build-deliveryoptimization-sdk/linux-debug/sdk-cpp/libdeliveryoptimization* ../install/lib + + after: + - installdeps + + stage-packages: + - libboost-program-options1.71.0 + - libboost-filesystem1.71.0 + +apps: + sdk-tests: + command: bin/deliveryoptimization-sdk-tests + +plugs: + do-port-number: + interface: content + content: do-port-number + target: $SNAP_DATA/do-port-number + + do-config-file: + interface: content + content: do-config-file + target: $SNAP_DATA/do-config-file + +slots: + downloads-folder: + interface: content + content: downloads-folder + write: + - $SNAP_DATA/var/lib/deliveryoptimization-snap-downloads-root + +layout: + /var/lib/deliveryoptimization-snap-downloads-root: + symlink: $SNAP_DATA/var/lib/deliveryoptimization-snap-downloads-root \ No newline at end of file