From e88dddac49a37aca8669658e7d649d7f2554b6fa Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 22 Jul 2024 10:46:49 +0100 Subject: [PATCH] Update to ccf 5.0.0 (#25) --- .devcontainer/Dockerfile | 2 +- .github/workflows/ci.yml | 6 +++--- README.md | 25 +++++++++++++------------ cpp/app/app.cpp | 18 +++++++++--------- docker/ccf_app_cpp.enclave | 4 ++-- docker/ccf_app_cpp.virtual | 4 ++-- docker/ccf_app_js.enclave | 4 ++-- docker/ccf_app_js.virtual | 4 ++-- js/package.json | 2 +- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e0cd6ec..a799538 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,3 @@ -FROM mcr.microsoft.com/ccf/app/dev:4.0.14-virtual +FROM ghcr.io/microsoft/ccf/app/dev/virtual:ccf-5.0.0 RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - && sudo apt-get install -y nodejs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bb5c52..ca34bd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: build-cpp-app-sgx: runs-on: ubuntu-20.04 - container: mcr.microsoft.com/ccf/app/dev:4.0.14-sgx + container: ghcr.io/microsoft/ccf/app/dev/sgx:ccf-5.0.0 steps: - name: Checkout repository @@ -21,7 +21,7 @@ jobs: build-cpp-app-virtual: runs-on: ubuntu-20.04 - container: mcr.microsoft.com/ccf/app/dev:4.0.14-virtual + container: ghcr.io/microsoft/ccf/app/dev/virtual:ccf-5.0.0 steps: - name: Checkout repository @@ -33,7 +33,7 @@ jobs: build-containers: runs-on: ubuntu-20.04 - container: mcr.microsoft.com/ccf/app/dev:4.0.14-sgx + container: ghcr.io/microsoft/ccf/app/dev/sgx:ccf-5.0.0 steps: - name: Checkout repository diff --git a/README.md b/README.md index 8698fad..0e2003e 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Template repository for JavaScript and C++ CCF applications. -Note: For complete sample apps, see https://github.com/microsoft/ccf-app-samples. +Note: For complete sample apps, see https://github.com/microsoft/ccf-app-samples. ## Quickstart -The quickest way to build and run this sample CCF app is to checkout this repository locally in its development container by clicking: +The quickest way to build and run this sample CCF app is to checkout this repository locally in its development container by clicking: [![Open in VSCode](https://img.shields.io/static/v1?label=Open+in&message=VSCode&logo=visualstudiocode&color=007ACC&logoColor=007ACC&labelColor=2C2C32)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/ccf-app-template) All dependencies will be automatically installed (takes ~2 mins on first checkout). @@ -85,10 +85,10 @@ To start a test CCF network on a Linux environment, it requires [CCF to be intal # Start the CCF network using the cchost in # Enclave mode - /opt/ccf/bin/cchost --config ./config/cchost_config_enclave_js.json + /opt/ccf_sgx/bin/cchost --config ./config/cchost_config_enclave_js.json # Or Virtual mode -/opt/ccf/bin/cchost --config ./config/cchost_config_virtual_js.json +/opt/ccf_virtual/bin/cchost --config ./config/cchost_config_virtual_js.json ... # Now the CCF network is started and further initialization needed before the interaction with the service @@ -96,10 +96,9 @@ To start a test CCF network on a Linux environment, it requires [CCF to be intal The CCF network is started with one node and one member, please follow the [same governance steps as Docker](#network-governance) to initialize the network and check [CCF node config file documentation](https://microsoft.github.io/CCF/main/operations/configuration.html) - ### Managed CCF -The application can be tested using [Azure Managed CCF](https://techcommunity.microsoft.com/t5/azure-confidential-computing/microsoft-introduces-preview-of-azure-managed-confidential/ba-p/3648986) ``(Pre-release phase)``, you can create Azure Managed CCF service on your subscription, that will give you a ready CCF network +The application can be tested using [Azure Managed CCF](https://techcommunity.microsoft.com/t5/azure-confidential-computing/microsoft-introduces-preview-of-azure-managed-confidential/ba-p/3648986) `(Pre-release phase)`, you can create Azure Managed CCF service on your subscription, that will give you a ready CCF network - First, create the network's initial member certificate, please check [Certificates generation](https://microsoft.github.io/CCF/main/governance/adding_member.html) - Create a new Azure Managed CCF service (the initial member certificate required as input) @@ -107,7 +106,7 @@ The application can be tested using [Azure Managed CCF](https://techcommunity.mi - Deploy the application proposal, [using governance calls](https://microsoft.github.io/CCF/main/governance/proposals.html#creating-a-proposal) - Create and submit [an add users proposal](https://microsoft.github.io/CCF/main/governance/proposals.html#creating-a-proposal) -## C++ +## C++ CCF apps can also be written in C++. This offers better performance than JavaScript apps but requires a compilation step and a restart of the CCF node for deployment. @@ -175,13 +174,15 @@ $ docker run ccf-app-template:cpp-virtual If this repository is checked out on a bare VM (e.g. [for SGX deployments](https://docs.microsoft.com/en-us/azure/confidential-computing/quick-create-portal)), the dependencies required to build and run the C++ app can be installed as follows: ```bash -$ wget https://github.com/microsoft/CCF/releases/download/ccf-4.0.14/ccf_virtual_4.0.14_amd64.deb -$ sudo dpkg -i ccf_virtual_4.0.14_amd64.deb # Install CCF under /opt/ccf -$ cat /opt/ccf_virtual/share/VERSION_LONG -ccf-4.0.14 -$ /opt/ccf/getting_started/setup_vm/run.sh /opt/ccf/getting_started/setup_vm/app-dev.yml # Install dependencies +$ wget https://github.com/microsoft/CCF/releases/download/ccf-5.0.0/ccf_sgx_5.0.0_amd64.deb +$ sudo dpkg -i ccf_sgx_5.0.0_amd64.deb # Install CCF under /opt/ccf_sgx +$ cat /opt/ccf_sgx/share/VERSION_LONG +ccf-5.0.0 +$ /opt/ccf_sgx/getting_started/setup_vm/run.sh /opt/ccf_sgx/getting_started/setup_vm/app-dev.yml # Install dependencies ``` +For a non-SGX VM, replace `ccf_sgx` in all the commands above with `ccf_virtual`. + See the [CCF official docs](https://microsoft.github.io/CCF/main/build_apps/install_bin.html#install-ccf) for more info and [Modern JavaScript application development](https://microsoft.github.io/CCF/main/build_apps/js_app_bundle.html). ## Code Tour diff --git a/cpp/app/app.cpp b/cpp/app/app.cpp index 5693bbc..62e392e 100644 --- a/cpp/app/app.cpp +++ b/cpp/app/app.cpp @@ -12,7 +12,7 @@ namespace app { // Key-value store types - using Map = kv::Map; + using Map = ccf::kv::Map; static constexpr auto RECORDS = "records"; // API types @@ -31,7 +31,7 @@ namespace app class AppHandlers : public ccf::UserEndpointRegistry { public: - AppHandlers(ccfapp::AbstractNodeContext& context) : + AppHandlers(ccf::AbstractNodeContext& context) : ccf::UserEndpointRegistry(context) { openapi_info.title = "CCF Sample C++ App"; @@ -42,11 +42,11 @@ namespace app auto write = [this](auto& ctx, nlohmann::json&& params) { const auto parsed_query = - http::parse_query(ctx.rpc_ctx->get_request_query()); + ccf::http::parse_query(ctx.rpc_ctx->get_request_query()); std::string error_reason; size_t id = 0; - if (!http::get_query_value(parsed_query, "id", id, error_reason)) + if (!ccf::http::get_query_value(parsed_query, "id", id, error_reason)) { return ccf::make_error( HTTP_STATUS_BAD_REQUEST, @@ -76,11 +76,11 @@ namespace app auto read = [this](auto& ctx, nlohmann::json&& params) { const auto parsed_query = - http::parse_query(ctx.rpc_ctx->get_request_query()); + ccf::http::parse_query(ctx.rpc_ctx->get_request_query()); std::string error_reason; size_t id = 0; - if (!http::get_query_value(parsed_query, "id", id, error_reason)) + if (!ccf::http::get_query_value(parsed_query, "id", id, error_reason)) { return ccf::make_error( HTTP_STATUS_BAD_REQUEST, @@ -112,11 +112,11 @@ namespace app }; } // namespace app -namespace ccfapp +namespace ccf { std::unique_ptr make_user_endpoints( - ccfapp::AbstractNodeContext& context) + ccf::AbstractNodeContext& context) { return std::make_unique(context); } -} // namespace ccfapp \ No newline at end of file +} // namespace ccf \ No newline at end of file diff --git a/docker/ccf_app_cpp.enclave b/docker/ccf_app_cpp.enclave index f459b2a..2c32804 100644 --- a/docker/ccf_app_cpp.enclave +++ b/docker/ccf_app_cpp.enclave @@ -1,12 +1,12 @@ # Build -FROM mcr.microsoft.com/ccf/app/dev:4.0.14-sgx as builder +FROM ghcr.io/microsoft/ccf/app/dev/sgx:ccf-5.0.0 as builder COPY ./cpp /cpp RUN mkdir -p /build/ WORKDIR /build/ RUN CC="clang-11" CXX="clang++-11" cmake -DCOMPILE_TARGET=sgx -GNinja /cpp && ninja # Run -FROM mcr.microsoft.com/ccf/app/run:4.0.14-sgx +FROM ghcr.io/microsoft/ccf/app/run/sgx:ccf-5.0.0 COPY --from=builder /build/libccf_app.enclave.so.signed /app/ COPY --from=builder /opt/ccf_sgx/bin/*.js /app/ diff --git a/docker/ccf_app_cpp.virtual b/docker/ccf_app_cpp.virtual index 6b2e238..e74847f 100644 --- a/docker/ccf_app_cpp.virtual +++ b/docker/ccf_app_cpp.virtual @@ -1,12 +1,12 @@ # Build -FROM mcr.microsoft.com/ccf/app/dev:4.0.14-virtual as builder +FROM ghcr.io/microsoft/ccf/app/dev/virtual:ccf-5.0.0 as builder COPY ./cpp /cpp RUN mkdir -p /build/ WORKDIR /build/ RUN CC="clang-15" CXX="clang++-15" cmake -GNinja -DCOMPILE_TARGET=virtual /cpp && ninja # Run -FROM mcr.microsoft.com/ccf/app/run:4.0.14-virtual +FROM ghcr.io/microsoft/ccf/app/run/virtual:ccf-5.0.0 COPY --from=builder /build/libccf_app.virtual.so /app/ COPY --from=builder /opt/ccf_virtual/bin/*.js /app/ diff --git a/docker/ccf_app_js.enclave b/docker/ccf_app_js.enclave index ff3e3ea..bc95504 100644 --- a/docker/ccf_app_js.enclave +++ b/docker/ccf_app_js.enclave @@ -1,8 +1,8 @@ # Build -FROM mcr.microsoft.com/ccf/app/dev:4.0.14-sgx as builder +FROM ghcr.io/microsoft/ccf/app/dev/sgx:ccf-5.0.0 as builder # Run -FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-sgx +FROM ghcr.io/microsoft/ccf/app/run-js/sgx:ccf-5.0.0 COPY --from=builder /opt/ccf_sgx/bin/*.js /app/ COPY --from=builder /opt/ccf_sgx/bin/keygenerator.sh /app/ diff --git a/docker/ccf_app_js.virtual b/docker/ccf_app_js.virtual index f757691..f503b63 100644 --- a/docker/ccf_app_js.virtual +++ b/docker/ccf_app_js.virtual @@ -1,8 +1,8 @@ # Build -FROM mcr.microsoft.com/ccf/app/dev:4.0.14-virtual as builder +FROM ghcr.io/microsoft/ccf/app/dev/virtual:ccf-5.0.0 as builder # Run -FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-virtual +FROM ghcr.io/microsoft/ccf/app/run-js/virtual:ccf-5.0.0 # Note: libjs_generic.virtual is not included in run-js container COPY --from=builder /opt/ccf_virtual/lib/libjs_generic.virtual.so /usr/lib/ccf diff --git a/js/package.json b/js/package.json index 9e575dc..84a3329 100644 --- a/js/package.json +++ b/js/package.json @@ -10,7 +10,7 @@ "node": ">=14" }, "dependencies": { - "@microsoft/ccf-app": "^4.0.14" + "@microsoft/ccf-app": "^5.0.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^17.1.0",