Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ _deps
*_CPack_Packages/
*.deb
out/

# Ubuntu Snap files
*.snap
snap/
29 changes: 29 additions & 0 deletions build/build-snaps.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions sdk-cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 9 additions & 3 deletions sdk-cpp/tests/test_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
{
Expand Down
15 changes: 13 additions & 2 deletions snap/snapcraft.yaml → snapcraft-options/snapcraft-agent.yaml
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -64,7 +64,7 @@ parts:
- libwind0-heimdal

apps:
deliveryoptimization-client:
agent:
command: bin/deliveryoptimization-agent
daemon: simple
refresh-mode: restart
Expand All @@ -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
75 changes: 75 additions & 0 deletions snapcraft-options/snapcraft-sdk.yaml
Original file line number Diff line number Diff line change
@@ -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