Skip to content

Commit

Permalink
change to Command implementation for pushing to dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Sep 6, 2023
1 parent 1d67846 commit 51a2362
Showing 1 changed file with 85 additions and 21 deletions.
106 changes: 85 additions & 21 deletions net/k8s-cluster/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,77 @@ WORKDIR /home/solana
}

pub async fn push_image(&self, validator_type: &str) -> Result<(), Box<dyn Error>> {

//login to docker repo
self.login()?;

let image = format!(
"{}/{}-{}:{}",
self.image_config.registry, validator_type, self.image_config.image_name, self.image_config.tag
);

let command = format!(
"docker push '{}'",
image
);
match Command::new("sh")
.arg("-c")
.arg(&command)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to execute command")
.wait_with_output()
{
Ok(_) => Ok(()),
Err(err) => Err(Box::new(err)),
}

// let username = match &self.registry_username {
// Some(username) => username,
// None => {
// return Err(boxed_error!(
// "No username set for registry! Is REGISTRY_USERNAME set?"
// ))
// }
// };
// let password = match &self.registry_password {
// Some(password) => password,
// None => {
// return Err(boxed_error!(
// "No password set for registry! Is REGISTRY_PASSWORD set?"
// ))
// }
// };

// // self.docker
// let image = format!(
// "{}/{}-{}:{}",
// self.image_config.registry, validator_type, self.image_config.image_name, self.image_config.tag
// );
// let auth = opts::RegistryAuth::Password {
// username: password.to_string(),
// password: username.to_string(),
// email: None,
// server_address: None,
// };

// let options = opts::ImagePushOpts::builder()
// .tag(self.image_config.tag)
// .auth(auth)
// .build();
// let progress_bar = new_spinner_progress_bar();
// progress_bar.set_message(format!("{DOCKER_WHALE}Pushing image {} to registry", image));

// match self.docker.images().push(image, &options).await {
// Ok(res) => Ok(res),
// Err(err) => Err(boxed_error!(format!("{}", err))),
// }
}

fn login(
&self,
) -> Result<(), Box<dyn Error>> {
let username = match &self.registry_username {
Some(username) => username,
None => {
Expand All @@ -215,28 +286,21 @@ WORKDIR /home/solana
}
};

// self.docker
let image = format!(
"{}/{}-{}:{}",
self.image_config.registry, validator_type, self.image_config.image_name, self.image_config.tag
let command = format!(
"echo '{}' | docker login -u '{}' --password-stdin",
password, username
);
let auth = opts::RegistryAuth::Password {
username: password.to_string(),
password: username.to_string(),
email: None,
server_address: None,
};

let options = opts::ImagePushOpts::builder()
.tag(self.image_config.tag)
.auth(auth)
.build();
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{DOCKER_WHALE}Pushing image {} to registry", image));

match self.docker.images().push(image, &options).await {
Ok(res) => Ok(res),
Err(err) => Err(boxed_error!(format!("{}", err))),
match Command::new("sh")
.arg("-c")
.arg(&command)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to execute command")
.wait_with_output()
{
Ok(_) => Ok(()),
Err(err) => Err(Box::new(err)),
}
}
}
Expand Down

0 comments on commit 51a2362

Please sign in to comment.