Skip to content

Commit

Permalink
Recreate with same image
Browse files Browse the repository at this point in the history
  • Loading branch information
brokad committed Nov 20, 2022
1 parent 87c5767 commit c3c323d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ where
status_code: 404, ..
}) => {
// container not found, let's try to recreate it
// with the same image
let project_name = container.project_name()?;
Self::create(project_name)
let creating = ProjectCreating::new_with_random_initial_key(project_name)
.with_image(container.image.unwrap());
Self::Creating(creating)
}
Err(err) => return Err(err.into()),
},
Expand All @@ -366,13 +369,15 @@ where
pub struct ProjectCreating {
project_name: ProjectName,
initial_key: String,
image: Option<String>,
}

impl ProjectCreating {
pub fn new(project_name: ProjectName, initial_key: String) -> Self {
Self {
project_name,
initial_key,
image: None,
}
}

Expand All @@ -381,6 +386,11 @@ impl ProjectCreating {
Self::new(project_name, initial_key)
}

pub fn with_image(mut self, image: String) -> Self {
self.image = Some(image);
self
}

pub fn project_name(&self) -> &ProjectName {
&self.project_name
}
Expand All @@ -402,7 +412,7 @@ impl ProjectCreating {
ctx: &C,
) -> (CreateContainerOptions<String>, Config<String>) {
let ContainerSettings {
image,
image: default_image,
prefix,
provisioner_host,
network_name,
Expand All @@ -414,6 +424,7 @@ impl ProjectCreating {
let Self {
initial_key,
project_name,
image,
..
} = &self;

Expand All @@ -422,7 +433,7 @@ impl ProjectCreating {
};

let container_config: ContainerConfig = deserialize_json!({
"Image": image,
"Image": image.as_ref().unwrap_or(default_image),
"Hostname": format!("{prefix}{project_name}"),
"Labels": {
"shuttle_prefix": prefix,
Expand Down Expand Up @@ -983,6 +994,7 @@ pub mod tests {
Project::Creating(ProjectCreating {
project_name: "my-project-test".parse().unwrap(),
initial_key: "test".to_string(),
image: None,
}),
#[assertion = "Container created, assigned an `id`"]
Ok(Project::Starting(ProjectStarting {
Expand Down

0 comments on commit c3c323d

Please sign in to comment.