Skip to content

Commit

Permalink
twoliter: Use unique token for sdk container
Browse files Browse the repository at this point in the history
  • Loading branch information
ecpullen committed Nov 9, 2023
1 parent 0879545 commit a9cdaf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion twoliter/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ 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");
let packages_dir =
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")?
Expand Down
8 changes: 8 additions & 0 deletions twoliter/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +116,13 @@ impl Project {
pub(crate) fn toolchain(&self, arch: &str) -> Option<ImageArchUri> {
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,
Expand Down

0 comments on commit a9cdaf9

Please sign in to comment.