+
Skip to content

Conversation

danko-miladinovic
Copy link
Contributor

@danko-miladinovic danko-miladinovic commented Jul 22, 2024

What type of PR is this?

This is a feature because it enables the Agent to run Docker images inside the VM.

What does this do?

This PR introduces a new way of executing algorithms by using Docker.

Which issue(s) does this PR fix/relate to?

Resolves #165

Have you included tests for your changes?

The agent-config/main.go has been changed to create an option for the Agent to run docker.

Did you document any new/modified feature?

The official documentation will be updated in a separate PR. The manual testing documentation has been updated.

Notes

@danko-miladinovic danko-miladinovic marked this pull request as ready for review July 22, 2024 22:36
@danko-miladinovic danko-miladinovic force-pushed the docker branch 2 times, most recently from 656d428 to 78d7204 Compare July 31, 2024 11:07
# 2023/09/21 10:43:53 Uploading algorithm binary: test/manual/algo/lin_reg.bin

# In order to run the Docker image, run the CLI program with the algorithm docker option
go run ./cmd/cli/main.go algo -a docker -d "python3 /cocos/lin_reg.py" <path_to_docker_image.tar> <private_key_file_path>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add the docker file to test/algo for the example used, also add docs there on how to build and output the docker image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added an README file for the docker.

Copy link
Contributor

@SammyOina SammyOina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

results fails

go run ./cmd/cli/main.go result private.pem                                                                                                                                                            ✔  10s2024/08/02 16:57:50 Retrieving computation result file
2024/08/02 16:58:00 Error retrieving computation result: rpc error: code = Unknown desc = could not copy from the Docker container: failed to copy from container: Error response from daemon: Could not find the file /result/result.bin in container agent_container
exit status 1

@danko-miladinovic
Copy link
Contributor Author

results fails

go run ./cmd/cli/main.go result private.pem                                                                                                                                                            ✔  10s2024/08/02 16:57:50 Retrieving computation result file
2024/08/02 16:58:00 Error retrieving computation result: rpc error: code = Unknown desc = could not copy from the Docker container: failed to copy from container: Error response from daemon: Could not find the file /result/result.bin in container agent_container
exit status 1

Fixed, the problem was in the lin_reg.py file. My mistake was that I left the dataset path be /datasets/iris.csv but the datasets are renamed when the Agent saves them, so it did not work.

agent/service.go Outdated
return
}
} else if err != nil {
fmt.Printf("Could not create result dir\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Printf("Could not create result dir\n")

Comment on lines 228 to 230
func (d *docker) AddDataset(dataset string) {
d.logger.Debug("dataset method called")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

case <-statusCh:
}

agentResultOutput := path.Join(algorithm.AlgorithmResultOutputDir, algorithm.AlgorithmResultOutputFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there could be multiple files. results dir is zipped by agent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is now changed to reflect this change.

Comment on lines 10 to 11
DATA_DIR = "/datasets"
RESULTS_DIR = "/results"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this absolute path will work on docker but not on python or python or bin. on docker can you have the algo mount be in a relative path to datasets and results mounts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


const (
containerName = "agent_container"
DockerRunCommand = "python3 /cocos/algorithm.py"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear to me, what is this const? Does that mean that we can run only Python algorithms? Should we just run a docker, whatever the binary is inside, and it is a docker creator's obligation to ensure that the container will boot properly, that the binary (or script, or whatever) will run inside and that it will find datasets mapped on the volume

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just the default, but the user can supply their own command to run in docker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code so that the docker start command must be a part of the docker image. The datasets and results are left as options in the CLI. They are there because the python, wasm and bin will not work if the datasets and results dirs are /datasets and /results. They need to be relative for those algorithms.

@dborovcanin
Copy link
Contributor

@drasko, @SammyOina Please re-review.

@danko-miladinovic
Copy link
Contributor Author

Now, the /cocos directory is the default working directory for the Agent. The Docker image must be built so it has the /cocos directory. In this directory the datasets and results will be mounted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to algo readme and combine with existing readme


```sh
python3 test/manual/algo/lin_reg_test.py test/manual/data/iris.csv result.bin
python3 test/manual/algo/lin_reg.py predict result.zip /test/manual/data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, mistake happened during copy/paste.

@drasko drasko merged commit ee83704 into ultravioletrs:main Aug 21, 2024
@danko-miladinovic danko-miladinovic deleted the docker branch August 8, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Enable the Agent to run algorithm in Docker

4 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载