Skip to content

Commit

Permalink
fix: estimator rust version (#7485)
Browse files Browse the repository at this point in the history
Update docker tag to force re-building any existing older docker images.
  • Loading branch information
jakmeier authored and nikurt committed Nov 9, 2022
1 parent 93799da commit 6ff3ff1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion runtime/runtime-params-estimator/emu-cost/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# our local base image
# FROM ubuntu
FROM rust:1.63.0

LABEL description="Container for builds"
Expand Down
25 changes: 21 additions & 4 deletions runtime/runtime-params-estimator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<String, anyhow::Error> {
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<CostTable> {
fs::read_to_string(&path)
.with_context(|| format!("failed to read costs file: {}", path.display()))?
Expand Down

0 comments on commit 6ff3ff1

Please sign in to comment.