diff --git a/.gitignore b/.gitignore index 4c481b13..f2818ed7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ cmd/manager/img dist/ results.zip *.spec +*.tar diff --git a/test/manual/algo/Dockerfile b/test/manual/algo/Dockerfile new file mode 100644 index 00000000..c46f74a9 --- /dev/null +++ b/test/manual/algo/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.9-slim + +# set the working directory in the container +WORKDIR /cocos +RUN mkdir /cocos/results +RUN mkdir /cocos/datasets + +COPY ./requirements.txt /cocos/requirements.txt +COPY ./lin_reg.py /cocos/lin_reg.py + +# install dependencies +RUN pip install -r requirements.txt + +# command to be run when the docker container is started +CMD ["python3", "/cocos/lin_reg.py"] diff --git a/test/manual/algo/README.md b/test/manual/algo/README.md index e416556f..8534d413 100644 --- a/test/manual/algo/README.md +++ b/test/manual/algo/README.md @@ -49,7 +49,17 @@ This command is run from the root directory of the project. This will start the In another window, you can run the following command: ```bash -sudo MANAGER_QEMU_SMP_MAXCPUS=4 MANAGER_GRPC_URL=localhost:7001 MANAGER_LOG_LEVEL=debug MANAGER_QEMU_USE_SUDO=false MANAGER_QEMU_ENABLE_SEV=false MANAGER_QEMU_SEV_CBITPOS=51 MANAGER_QEMU_ENABLE_SEV_SNP=false MANAGER_QEMU_OVMF_CODE_FILE=/usr/share/edk2/x64/OVMF_CODE.fd MANAGER_QEMU_OVMF_VARS_FILE=/usr/share/edk2/x64/OVMF_VARS.fd go run main.go +sudo \ +MANAGER_QEMU_SMP_MAXCPUS=4 \ +MANAGER_GRPC_URL=localhost:7001 \ +MANAGER_LOG_LEVEL=debug \ +MANAGER_QEMU_USE_SUDO=false \ +MANAGER_QEMU_ENABLE_SEV=false \ +MANAGER_QEMU_SEV_CBITPOS=51 \ +MANAGER_QEMU_ENABLE_SEV_SNP=false \ +MANAGER_QEMU_OVMF_CODE_FILE=/usr/share/edk2/x64/OVMF_CODE.fd \ +MANAGER_QEMU_OVMF_VARS_FILE=/usr/share/edk2/x64/OVMF_VARS.fd \ +go run main.go ``` This command is run from the [manager main directory](../../../cmd/manager/). This will start the manager. Make sure you have already built the [qemu image](../../../hal/linux/README.md). @@ -99,6 +109,7 @@ For addition example, you can use the following command: ## Docker Example Here we will use the docker with the linear regression example (`lin_reg.py`). Throughout the example, we assume that our current working directory is the directory in which the `cocos` repository is cloned. For example: + ```bash # ls cocos @@ -106,36 +117,34 @@ cocos The docker image must have a `cocos` directory containing the `datasets` and `results` directories. The Agent will run this image inside the SVM and will mount the datasets and results onto the `/cocos/datasets` and `/cocos/results` directories inside the image. The docker image must also contain the command that will be run when the docker container is run. -The first step is to create a docker file. Use your favorite editor to create a file named `Dockerfile` in the current working directory and write in it the following code: +Run the build command and then save the docker image as a `tar` file. ```bash -FROM python:3.9-slim - -# set the working directory in the container -WORKDIR /cocos -RUN mkdir /cocos/results -RUN mkdir /cocos/datasets - -COPY ./cocos/test/manual/algo/requirements.txt /cocos/requirements.txt -COPY ./cocos/test/manual/algo/lin_reg.py /cocos/lin_reg.py - -# install dependencies -RUN pip install -r requirements.txt - -# command to be run when the docker container is started -CMD ["python3", "/cocos/lin_reg.py"] +cd test/manual/algo/ +docker build -t linreg . +docker save linreg > linreg.tar ``` -Next, run the build command and then save the docker image as a `tar` file. +To run the examples in the secure VM (SVM) by the Agent, you can use the following command in cocos root directory `/cocos`: + ```bash -docker build -t linreg . -docker save linreg > linreg.tar +go run ./test/computations/main.go ./test/manual/algo/linreg.tar public.pem false ./test/manual/data/iris.csv ``` -In another window, you can run the following command: +In another window, you can run the following command in the `cmd/manager` directory: ```bash -sudo MANAGER_QEMU_SMP_MAXCPUS=4 MANAGER_GRPC_URL=localhost:7001 MANAGER_LOG_LEVEL=debug MANAGER_QEMU_USE_SUDO=false MANAGER_QEMU_ENABLE_SEV=false MANAGER_QEMU_SEV_CBITPOS=51 MANAGER_QEMU_ENABLE_SEV_SNP=false MANAGER_QEMU_OVMF_CODE_FILE=/usr/share/edk2/x64/OVMF_CODE.fd MANAGER_QEMU_OVMF_VARS_FILE=/usr/share/edk2/x64/OVMF_VARS.fd go run main.go +sudo \ +MANAGER_QEMU_SMP_MAXCPUS=4 \ +MANAGER_GRPC_URL=localhost:7001 \ +MANAGER_LOG_LEVEL=debug \ +MANAGER_QEMU_USE_SUDO=false \ +MANAGER_QEMU_ENABLE_SEV=false \ +MANAGER_QEMU_SEV_CBITPOS=51 \ +MANAGER_QEMU_ENABLE_SEV_SNP=false \ +MANAGER_QEMU_OVMF_CODE_FILE=/usr/share/edk2/x64/OVMF_CODE.fd \ +MANAGER_QEMU_OVMF_VARS_FILE=/usr/share/edk2/x64/OVMF_VARS.fd \ +go run main.go ``` This command is run from the [manager main directory](../../../cmd/manager/). This will start the manager. Make sure you have already built the [qemu image](../../../hal/linux/README.md). @@ -143,7 +152,7 @@ This command is run from the [manager main directory](../../../cmd/manager/). Th In another window, specify what kind of algorithm you want the Agent to run (docker): ```bash -./cocos/build/cocos-cli algo ./linreg.tar ./cocos/private.pem -a docker +./cocos/build/cocos-cli algo ./test/manual/algo/linreg.tar ./cocos/private.pem -a docker ``` make sure you have built the cocos-cli. This will upload the docker image. @@ -151,21 +160,27 @@ make sure you have built the cocos-cli. This will upload the docker image. Next we need to upload the dataset ```bash -./cocos/build/cocos-cli data ./cocos/test/manual/data/iris.csv ./cocos/private.pem +./cocos/build/cocos-cli data ./test/manual/data/iris.csv ./cocos/private.pem ``` After some time when the results are ready, you can run the following command to get the results: ```bash -./cocos/build/cocos-cli results ./cocos/private.pem +./cocos/build/cocos-cli results ./private.pem ``` This will return the results of the algorithm. +Unzip the results + +```bash +unzip results.zip -d results +``` + To make inference on the results, you can use the following command: ```bash -python3 ./cocos/test/manual/algo/lin_reg.py predict result.zip ./cocos/test/manual/data +python3 ./test/manual/algo/lin_reg.py predict results/model.bin test/manual/data/ ``` ## Wasm Example