Skip to content

Commit

Permalink
parse image pull auth from env
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Tang <[email protected]>
  • Loading branch information
sctb512 committed Jul 27, 2023
1 parent 19d5b12 commit b6c23d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ impl ConfigV2 {
false
}
}

/// Fill authorization for registry backend.
pub fn update_registry_auth_info(&mut self, auth: &Option<String>) {
if let Some(auth) = auth {
if let Some(backend) = self.backend.as_mut() {
if let Some(registry) = backend.registry.as_mut() {
registry.auth = Some(auth.to_string());
}
}
}
}
}

impl FromStr for ConfigV2 {
Expand Down
13 changes: 11 additions & 2 deletions src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use nix::sys::signal;
use rlimit::Resource;

use nydus::{get_build_time_info, SubCmdArgs};
use nydus_api::BuildTimeInfo;
use nydus_api::{BuildTimeInfo, ConfigV2};
use nydus_app::{dump_program_info, setup_logging};
use nydus_service::daemon::DaemonController;
use nydus_service::{
Expand Down Expand Up @@ -423,7 +423,16 @@ fn process_fs_service(
)
}
None => match args.value_of("config") {
Some(v) => std::fs::read_to_string(v)?,
Some(v) => {
let auth = std::env::var("IMAGE_PULL_AUTH").ok();
if auth.is_some() {
let mut config = ConfigV2::from_file(v)?;
config.update_registry_auth_info(&auth);
serde_json::to_string(&config)?
} else {
std::fs::read_to_string(v)?
}
}
None => {
let e = NydusError::InvalidArguments(
"both --config and --localfs-dir are missing".to_string(),
Expand Down

0 comments on commit b6c23d4

Please sign in to comment.