diff --git a/runtime/runtime-params-estimator/emu-cost/Dockerfile b/runtime/runtime-params-estimator/emu-cost/Dockerfile index 35a5bf657bd..2b672837401 100644 --- a/runtime/runtime-params-estimator/emu-cost/Dockerfile +++ b/runtime/runtime-params-estimator/emu-cost/Dockerfile @@ -1,5 +1,4 @@ # our local base image -# FROM ubuntu FROM rust:1.63.0 LABEL description="Container for builds" diff --git a/runtime/runtime-params-estimator/src/main.rs b/runtime/runtime-params-estimator/src/main.rs index e6501f5a482..cf92a6b9105 100644 --- a/runtime/runtime-params-estimator/src/main.rs +++ b/runtime/runtime-params-estimator/src/main.rs @@ -274,10 +274,7 @@ fn main_docker( exec("docker --version").context("please install `docker`")?; let project_root = project_root(); - - let image = "rust-emu"; - let tag = "rust-1.62.1"; //< Update this when Dockerfile changes - let tagged_image = format!("{}:{}", image, tag); + let tagged_image = docker_image()?; if exec(&format!("docker images -q {}", tagged_image))?.is_empty() { // Build a docker image if there isn't one already. let status = Command::new("docker") @@ -379,6 +376,26 @@ fn main_docker( Ok(()) } +/// Creates a docker image tag that is unique for each rust version to force re-build when it changes. +fn docker_image() -> Result { + let image = "rust-emu"; + let dockerfile = + fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("emu-cost/Dockerfile"))?; + // The Dockerfile is expected to have a line like this: + // ``` + // FROM rust:x.y.z + // ``` + // and the result should be `rust-x.y.z` + let tag = dockerfile + .lines() + .find_map(|line| line.split_once("FROM ")) + .context("could not parse rustc version from Dockerfile")? + .1 + .replace(":", "-"); + + Ok(format!("{}:{}", image, tag)) +} + fn read_costs_table(path: &Path) -> anyhow::Result { fs::read_to_string(&path) .with_context(|| format!("failed to read costs file: {}", path.display()))?