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

refactor: create image trait with an impl for docker and podman #71

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

tylerslaton
Copy link
Collaborator

Another PR in a series of refactors that I'm doing that are aimed at reducing the complexity and extensibility of our code base. This one creates a new Image trait with two implementations for docker and podman so they can have their own unique functionality.

@tylerslaton tylerslaton requested a review from exdx September 15, 2022 14:49
Copy link
Owner

@exdx exdx left a comment

Choose a reason for hiding this comment

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

Very nice! I had some feedback, largely around naming, but this is definitely a step in the right direction to clean up the codebase!

src/docker.rs Outdated
Comment on lines 104 to 110
// Stop the container
match self.stop(container_id).await {
Ok(_) => {}
Err(e) => {
return Err(anyhow!("failed to stop the image: {}", e));
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

nit: I think this should go under the stop() function for clarity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which part, creating the error?

Copy link
Owner

Choose a reason for hiding this comment

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

No, I meant stopping the container. Stopping and deleting a container are related, so they can both go under stop()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah so are you saying that instead of copy_files() starting and stopping the container via start() and stop() we should have those functions be called outside of copy_files() directly in the lib.rs run function? Something like this:

// src/lib.rs - fn run()

// Create the container
let container_id = match container.start().await {
    Ok(id) => id,
    Err(e) => {
        return Err(anyhow!("failed to start the image: {}", e));
}

// Copy files from the image
match container
    .copy_files(
        config.content_path,
        config.download_path,
        config.write_to_stdout,
        container_id,
    )
    .await
{
    Ok(_) => {}
    Err(e) => {
        return Err(anyhow!("❌ error copying the image's files: {}", e));
    }
}

// Stop the container
match container.stop(container_id).await {
    Ok(_) => {}
    Err(e) => {
        return Err(anyhow!("failed to stop the image: {}", e));
    }
}

@tylerslaton tylerslaton force-pushed the create-image-trait branch 2 times, most recently from 8a67b0f to ce6c139 Compare September 25, 2022 19:46
@tylerslaton
Copy link
Collaborator Author

tylerslaton commented Sep 25, 2022

@exdx Okay with the latest push I broke out the runtime oriented logic into its own module folder along with the changes you were asking for in the rebase. This should make it easier to modularize that logic moving forward. What are your thoughts?

Copy link
Owner

@exdx exdx left a comment

Choose a reason for hiding this comment

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

LGTM! Great job working with async traits. Feel free to merge.

The only remaining nit I had was to move the container stop logic into the stop() function instead of in the copy_files() function, since it's more related to stopping and removing the container

@exdx
Copy link
Owner

exdx commented Sep 26, 2022

Is #57 addressed by these changes, or do we still need to look into it?

@tylerslaton
Copy link
Collaborator Author

Is #57 addressed by these changes, or do we still need to look into it?

The underlying logic of present_locally didn't change here so I'll need to investigate before giving you a concrete answer here.

@tylerslaton tylerslaton merged commit 88c9cf4 into exdx:main Sep 26, 2022
@tylerslaton tylerslaton deleted the create-image-trait branch September 26, 2022 18:26
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.

2 participants