mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
NOISSUE - Add Dockerfile For IRIS Example (#220)
* feat(Docker): Add Dockerfile for testing Add Dockerfile for testing linear regression algorithm Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> * fix(docs): Update docker linear regression example Resolves https://github.com/ultravioletrs/cocos/pull/220#discussion_r1732974631 --------- Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
This commit is contained in:
@@ -10,3 +10,4 @@ cmd/manager/img
|
||||
dist/
|
||||
results.zip
|
||||
*.spec
|
||||
*.tar
|
||||
|
||||
@@ -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"]
|
||||
+42
-27
@@ -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"]
|
||||
```
|
||||
|
||||
Next, run the build command and then save the docker image as a `tar` file.
|
||||
```bash
|
||||
cd test/manual/algo/
|
||||
docker build -t linreg .
|
||||
docker save linreg > linreg.tar
|
||||
```
|
||||
|
||||
In another window, you can run the following command:
|
||||
To run the examples in the secure VM (SVM) by the Agent, you can use the following command in cocos root directory `/cocos`:
|
||||
|
||||
```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
|
||||
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 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
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user