mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Correct retrieval of LastTagTime when the Docker image doesn't already exist
This commit is contained in:
@@ -39,74 +39,78 @@ pub fn build(name: String) {
|
|||||||
.arg(format!("serai-dev-{name}"))
|
.arg(format!("serai-dev-{name}"))
|
||||||
.output()
|
.output()
|
||||||
{
|
{
|
||||||
let created_time = SystemTime::from(
|
let last_tag_time_buf = String::from_utf8(res.stdout).expect("docker had non-utf8 output");
|
||||||
chrono::DateTime::parse_and_remainder(
|
let last_tag_time = last_tag_time_buf.trim();
|
||||||
String::from_utf8(res.stdout).expect("docker had non-utf8 output").trim(),
|
if !last_tag_time.is_empty() {
|
||||||
"%F %T.%f %z",
|
let created_time = SystemTime::from(
|
||||||
)
|
chrono::DateTime::parse_and_remainder(last_tag_time, "%F %T.%f %z")
|
||||||
.expect("docker formatted last tag time unexpectedly")
|
.unwrap_or_else(|_| {
|
||||||
.0,
|
panic!("docker formatted last tag time unexpectedly: {last_tag_time}")
|
||||||
);
|
})
|
||||||
|
.0,
|
||||||
|
);
|
||||||
|
|
||||||
let mut dockerfile_path = repo_path.join("deploy");
|
let mut dockerfile_path = repo_path.join("deploy");
|
||||||
if HashSet::from(["bitcoin", "ethereum", "monero"]).contains(name.as_str()) {
|
if HashSet::from(["bitcoin", "ethereum", "monero"]).contains(name.as_str()) {
|
||||||
dockerfile_path = dockerfile_path.join("coins");
|
dockerfile_path = dockerfile_path.join("coins");
|
||||||
}
|
}
|
||||||
dockerfile_path = dockerfile_path.join(&name).join("Dockerfile");
|
dockerfile_path = dockerfile_path.join(&name).join("Dockerfile");
|
||||||
|
|
||||||
// For all services, if the Dockerfile was edited after the image was built we should rebuild
|
// For all services, if the Dockerfile was edited after the image was built we should rebuild
|
||||||
let mut last_modified =
|
let mut last_modified =
|
||||||
fs::metadata(dockerfile_path).ok().and_then(|meta| meta.modified().ok());
|
fs::metadata(dockerfile_path).ok().and_then(|meta| meta.modified().ok());
|
||||||
|
|
||||||
// Check any additionally specified paths
|
// Check any additionally specified paths
|
||||||
let meta = |path: PathBuf| (path.clone(), fs::metadata(path));
|
let meta = |path: PathBuf| (path.clone(), fs::metadata(path));
|
||||||
let mut metadatas = match name.as_str() {
|
let mut metadatas = match name.as_str() {
|
||||||
"bitcoin" => vec![],
|
"bitcoin" => vec![],
|
||||||
"monero" => vec![],
|
"monero" => vec![],
|
||||||
"message-queue" => vec![
|
"message-queue" => vec![
|
||||||
meta(repo_path.join("common")),
|
meta(repo_path.join("common")),
|
||||||
meta(repo_path.join("crypto")),
|
meta(repo_path.join("crypto")),
|
||||||
meta(repo_path.join("substrate").join("primitives")),
|
meta(repo_path.join("substrate").join("primitives")),
|
||||||
meta(repo_path.join("message-queue")),
|
meta(repo_path.join("message-queue")),
|
||||||
],
|
],
|
||||||
"processor" => vec![
|
"processor" => vec![
|
||||||
meta(repo_path.join("common")),
|
meta(repo_path.join("common")),
|
||||||
meta(repo_path.join("crypto")),
|
meta(repo_path.join("crypto")),
|
||||||
meta(repo_path.join("coins")),
|
meta(repo_path.join("coins")),
|
||||||
meta(repo_path.join("substrate")),
|
meta(repo_path.join("substrate")),
|
||||||
meta(repo_path.join("message-queue")),
|
meta(repo_path.join("message-queue")),
|
||||||
meta(repo_path.join("processor")),
|
meta(repo_path.join("processor")),
|
||||||
],
|
],
|
||||||
_ => panic!("building unrecognized docker image"),
|
_ => panic!("building unrecognized docker image"),
|
||||||
};
|
};
|
||||||
|
|
||||||
while !metadatas.is_empty() {
|
while !metadatas.is_empty() {
|
||||||
if let (path, Ok(metadata)) = metadatas.pop().unwrap() {
|
if let (path, Ok(metadata)) = metadatas.pop().unwrap() {
|
||||||
if metadata.is_file() {
|
if metadata.is_file() {
|
||||||
if let Ok(modified) = metadata.modified() {
|
if let Ok(modified) = metadata.modified() {
|
||||||
if modified >
|
if modified >
|
||||||
last_modified
|
last_modified
|
||||||
.expect("got when source was last modified yet not when the Dockerfile was")
|
.expect("got when source was last modified yet not when the Dockerfile was")
|
||||||
{
|
{
|
||||||
last_modified = Some(modified);
|
last_modified = Some(modified);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Recursively crawl since we care when the folder's contents were edited, not the
|
||||||
|
// folder itself
|
||||||
|
for entry in fs::read_dir(path.clone()).expect("couldn't read directory") {
|
||||||
|
metadatas.push(meta(
|
||||||
|
path.join(entry.expect("couldn't access item in directory").file_name()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Recursively crawl since we care when the folder's contents were edited, not the folder
|
|
||||||
// itself
|
|
||||||
for entry in fs::read_dir(path.clone()).expect("couldn't read directory") {
|
|
||||||
metadatas
|
|
||||||
.push(meta(path.join(entry.expect("couldn't access item in directory").file_name())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(last_modified) = last_modified {
|
if let Some(last_modified) = last_modified {
|
||||||
if last_modified < created_time {
|
if last_modified < created_time {
|
||||||
println!("{} was built after the most recent source code edits, assuming built.", name);
|
println!("{} was built after the most recent source code edits, assuming built.", name);
|
||||||
built_lock.insert(name, true);
|
built_lock.insert(name, true);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user