Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jstzd): implement image #553

Merged
merged 2 commits into from
Sep 17, 2024
Merged

feat(jstzd): implement image #553

merged 2 commits into from
Sep 17, 2024

Conversation

ryutamago
Copy link
Collaborator

@ryutamago ryutamago commented Sep 6, 2024

Context

Implement traits / struct to run docker container that can later be used for jstzd

The related tasks are the following but not all of them are fully covered/tested yet (e.g. mounts/hosts etc)
image
runnable image

Description

Implement the docker images traits and structs

Manually testing the PR

cargo test --package jstzd --lib

@ryutamago ryutamago force-pushed the leo/docker-image branch 2 times, most recently from e3ef180 to 254bca3 Compare September 6, 2024 13:58
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 84.17722% with 25 lines in your changes missing coverage. Please review.

Project coverage is 34.82%. Comparing base (027eeb5) to head (8a664b6).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/jstzd/src/docker/image.rs 72.88% 16 Missing ⚠️
crates/jstzd/src/docker/runnable_image.rs 90.90% 5 Missing and 4 partials ⚠️
Files with missing lines Coverage Δ
crates/jstzd/src/docker/runnable_image.rs 90.90% <90.90%> (ø)
crates/jstzd/src/docker/image.rs 72.88% <72.88%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 027eeb5...8a664b6. Read the comment docs.

@ryutamago ryutamago changed the title [WIP] Docker network/image Jstzd: Add basic docker image / container Sep 6, 2024
@ryutamago ryutamago force-pushed the leo/docker-image branch 2 times, most recently from 08c563d to 7eda38d Compare September 9, 2024 12:21
@johnyob johnyob changed the title Jstzd: Add basic docker image / container feat(jstzd): add basic Docker image / container Sep 10, 2024
@johnyob johnyob self-assigned this Sep 10, 2024
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
@zcabter
Copy link
Collaborator

zcabter commented Sep 10, 2024

The manual test fails with Error: Docker responded with status code 404: No such image: busybox:latest. Seems like the pull_image step is missing.

@zcabter
Copy link
Collaborator

zcabter commented Sep 10, 2024

Commit messages are missing scope. Prefer to include it if possible. feat(jstzd) is a good one for this PR.

crates/jstzd/src/runnable_image/mod.rs Outdated Show resolved Hide resolved
crates/jstzd/src/runnable_image/mod.rs Outdated Show resolved Hide resolved
crates/jstzd/src/runnable_image/mod.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
crates/jstzd/Cargo.toml Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/container.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/image.rs Outdated Show resolved Hide resolved
crates/jstzd/src/network.rs Outdated Show resolved Hide resolved
crates/jstzd/src/runnable_image/mod.rs Outdated Show resolved Hide resolved
crates/jstzd/src/runnable_image/mod.rs Outdated Show resolved Hide resolved
@johnyob
Copy link
Collaborator

johnyob commented Sep 10, 2024

Additionally in future, I suggest we stick to 1 linear task per a PR. This single PR partially closes 4 (some support is missing here and there). This will not only make task tracking easier (and fits more nicely into linear's workflow), but will make reviews easier

@ryutamago
Copy link
Collaborator Author

The manual test fails with Error: Docker responded with status code 404: No such image: busybox:latest. Seems like the pull_image step is missing.

I accidentally removed the pull image code in the example since it was pulled in my local machin, i've added it back so should work now!

@jasbir-dhillon
Copy link

What was the reason/advantage for using rust to generate docker image rather thank just using a Dockerfile and docker-compose?

@zcabter
Copy link
Collaborator

zcabter commented Sep 12, 2024

What was the reason/advantage for using rust to generate docker image rather thank just using a Dockerfile and docker-compose?

This work doesn't generate docker images but automates pulling and running them in containers @jasbir-dhillon. These APIs will ultimately be used to orchestrate the jstzd sandbox environment.

@jasbir-dhillon
Copy link

What was the reason/advantage for using rust to generate docker image rather thank just using a Dockerfile and docker-compose?

This work doesn't generate docker images but automates pulling and running them in containers @jasbir-dhillon. These APIs will ultimately be used to orchestrate the jstzd sandbox environment.

@zcabter Could that have been done by just using a docker-compose file. You would of needed less lines of code and it would have been more readable?

let mut this = std::mem::take(self);
// Prevent the original `self` to drop again
self.dropped = true;
TokioScope::scope_and_block(|s| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note about scope_and_block: this only works with a multi-threaded runtime. Otherwise, the code will panic here. Sample error message:

thread '...' panicked at ...:                                                                                                                                                              
can call blocking only when running on the multi-threaded runtime

Copy link

@fizikarubi fizikarubi Sep 12, 2024

Choose a reason for hiding this comment

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

oh didn't notice that, the number of threads in tokio runtime defaults to the number of cpus on the system so i guess we can assume it is multithreaded ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realised that this is not just for scope_and_block but for blocking async in general, e.g. tokio::task::block_in_place.

I guess we can keep that assumption for now. For unit tests this might fail since single-threaded runtime is used by default. This can be resolved with #[tokio::test(flavor = "multi_thread")].

@zcabter
Copy link
Collaborator

zcabter commented Sep 12, 2024

What was the reason/advantage for using rust to generate docker image rather thank just using a Dockerfile and docker-compose?

This work doesn't generate docker images but automates pulling and running them in containers @jasbir-dhillon. These APIs will ultimately be used to orchestrate the jstzd sandbox environment.

@zcabter Could that have been done by just using a docker-compose file. You would of needed less lines of code and it would have been more readable?

It could but we'd still need to write an api over it as Docker is just one of Tasks target backends. The jstzd orchestrator would still need to work with tasks in a backend agnostic way.

@zcabter
Copy link
Collaborator

zcabter commented Sep 12, 2024

The testing coverage is a bit low partly because integration tests are missing. I know you put a lot of effort into this but I think this PR needs to be broken down into 4 PRs, 1 per issue. Where we are running docker commands, it needs to be
integration tested. This will make it easier to merge the parts of your code that is ready.

Additionally, I suggest removing the async dropper and custom drop logic for now since it will be re-thought (per #555 (comment)) but keeping the clean up logic.

@ryutamago
Copy link
Collaborator Author

The testing coverage is a bit low partly because integration tests are missing. I know you put a lot of effort into this but I think this PR needs to be broken down into 4 PRs, 1 per issue. Where we are running docker commands, it needs to be integration tested. This will make it easier to merge the parts of your code that is ready.

Additionally, I suggest removing the async dropper and custom drop logic for now since it will be re-thought (per #555 (comment)) but keeping the clean up logic.

I've split into three PRs, the first one doesn't require integration test so it could be merged. The 2 and 3 pr is tested manually and it only does the basic stuff so I personally don't think there's much problem merging it so we can see something is working. I've also removed the drop for now in the 3rd pr.

  1. image / runnable image
  2. pull-image
  3. container

@johnyob @zcabter

@ryutamago ryutamago changed the title feat(jstzd): add basic Docker image / container JSTZD: implement image Sep 12, 2024
@johnyob johnyob changed the title JSTZD: implement image feat(jstzd): implement image Sep 13, 2024
self
}

pub async fn create_container(&self, client: Arc<Docker>) -> Result<String> {
Copy link
Collaborator

@johnyob johnyob Sep 17, 2024

Choose a reason for hiding this comment

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

I would move all asssociated logic for create_container (aka start) under a different PR (will help with your testing).
The task is: https://linear.app/tezos/issue/JSTZ-62/implement-start-for-runnableimage

Copy link
Collaborator Author

@ryutamago ryutamago Sep 17, 2024

Choose a reason for hiding this comment

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

done, i will add this back after the pull image PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, this should be a separate PR -- it is a different task to pull_image

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
codecov.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@johnyob johnyob left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

@johnyob johnyob merged commit a6aaa2c into main Sep 17, 2024
5 checks passed
@johnyob johnyob deleted the leo/docker-image branch September 17, 2024 11:14
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.

6 participants