Skip to content

Commit

Permalink
feat: add name parameter to RunnableImage
Browse files Browse the repository at this point in the history
This change allows to override name of the image. Thus, user will be able to change registry, owner and the name itself.

Closes #335
  • Loading branch information
DDtKey committed Feb 18, 2024
1 parent 7c0280d commit e2ce50b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added `name` parameter to `RunnableImage`


## [0.15.0] - 2023-09-28

### Added
Expand Down
22 changes: 17 additions & 5 deletions testcontainers/src/core/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl ImageArgs for () {
pub struct RunnableImage<I: Image> {
image: I,
image_args: I::Args,
image_name: Option<String>,
image_tag: Option<String>,
container_name: Option<String>,
network: Option<String>,
Expand Down Expand Up @@ -202,11 +203,13 @@ impl<I: Image> RunnableImage<I> {
}

pub fn descriptor(&self) -> String {
if let Some(tag) = &self.image_tag {
format!("{}:{tag}", self.image.name())
} else {
format!("{}:{}", self.image.name(), self.image.tag())
}
let original_name = self.image.name();
let original_tag = self.image.tag();

let name = self.image_name.as_ref().unwrap_or(&original_name);
let tag = self.image_name.as_ref().unwrap_or(&original_tag);

format!("{name}:{tag}")
}

pub fn ready_conditions(&self) -> Vec<WaitFor> {
Expand All @@ -223,6 +226,14 @@ impl<I: Image> RunnableImage<I> {
}

impl<I: Image> RunnableImage<I> {
/// Overrides the image name. Can be used to specify a custom registry or owner (e.g `{domain}/{owner}/{image}`).
pub fn with_name(self, name: impl Into<String>) -> Self {
Self {
image_name: Some(name.into()),
..self
}
}

/// There is no guarantee that the specified tag for an image would result in a
/// running container. Users of this API are advised to use this at their own risk.
pub fn with_tag(self, tag: impl Into<String>) -> Self {
Expand Down Expand Up @@ -295,6 +306,7 @@ impl<I: Image> From<(I, I::Args)> for RunnableImage<I> {
Self {
image,
image_args,
image_name: None,
image_tag: None,
container_name: None,
network: None,
Expand Down

0 comments on commit e2ce50b

Please sign in to comment.