Skip to content

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

Merged
tylerslaton merged 2 commits into
exdx:mainfrom
tylerslaton:create-image-trait
Sep 26, 2022
Merged

refactor: create image trait with an impl for docker and podman#71
tylerslaton merged 2 commits into
exdx:mainfrom
tylerslaton:create-image-trait

Conversation

@tylerslaton

Copy link
Copy Markdown
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

@exdx exdx left a comment

Copy link
Copy Markdown
Owner

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!

Comment thread src/docker.rs Outdated
Comment thread src/docker.rs Outdated
Comment thread src/docker.rs
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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));
    }
}

Comment thread src/docker.rs Outdated
Comment thread src/image.rs Outdated
Comment thread src/podman.rs Outdated
@tylerslaton
tylerslaton force-pushed the create-image-trait branch 2 times, most recently from 8a67b0f to ce6c139 Compare September 25, 2022 19:46
@tylerslaton

tylerslaton commented Sep 25, 2022

Copy link
Copy Markdown
Collaborator Author

@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?

@exdx exdx left a comment

Copy link
Copy Markdown
Owner

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

exdx commented Sep 26, 2022

Copy link
Copy Markdown
Owner

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

@tylerslaton

Copy link
Copy Markdown
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