From a9cdaf9c9761d1e3f1c2df3156fb132cfa671eda Mon Sep 17 00:00:00 2001 From: ecpullen Date: Thu, 9 Nov 2023 16:54:59 +0000 Subject: [PATCH] twoliter: Use unique token for sdk container --- twoliter/src/cmd/build.rs | 3 ++- twoliter/src/project.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/twoliter/src/cmd/build.rs b/twoliter/src/cmd/build.rs index cdd77cd0b..a00512d2a 100644 --- a/twoliter/src/cmd/build.rs +++ b/twoliter/src/cmd/build.rs @@ -41,6 +41,7 @@ pub(crate) struct BuildVariant { impl BuildVariant { pub(super) async fn run(&self) -> Result<()> { let project = project::load_or_find_project(self.project_path.clone()).await?; + let token = project.token(); let tempdir = tools_tempdir()?; install_tools(&tempdir).await?; let makefile_path = tempdir.path().join("Makefile.toml"); @@ -48,7 +49,7 @@ impl BuildVariant { TempDir::new().context("Unable to create a tempdir for Twoliter's packages")?; let sdk_container = DockerContainer::new( - "sdk", + format!("sdk-{}", token), project .sdk(&self.arch) .context("The project was missing an sdk")? diff --git a/twoliter/src/project.rs b/twoliter/src/project.rs index c457a649b..a04c501db 100644 --- a/twoliter/src/project.rs +++ b/twoliter/src/project.rs @@ -5,6 +5,7 @@ use log::{debug, trace}; use non_empty_string::NonEmptyString; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use sha2::{Digest, Sha512}; use std::fmt; use std::path::{Path, PathBuf}; use tokio::fs; @@ -115,6 +116,13 @@ impl Project { pub(crate) fn toolchain(&self, arch: &str) -> Option { self.toolchain_name().map(|s| s.uri(arch)) } + + pub(crate) fn token(&self) -> String { + let mut d = Sha512::new(); + d.update(self.filepath().display().to_string()); + let digest = hex::encode(d.finalize()); + (digest[..12]).to_string() + } } /// A base name for an image that can be suffixed using a naming convention. For example,