From b986cf69af1f8743da326b738f5dd92ada4d0cf9 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 21 Mar 2021 18:09:11 -0700 Subject: [PATCH] Compute transitive dependencies --- docker/app/Dockerfile | 2 +- docker/base/Dockerfile | 2 +- docker/packaging/Dockerfile | 2 +- docker/runtime/Dockerfile | 2 +- tools/depgraph.js | 37 +++++++++++++++++++++++++++++-------- tools/hash-dockerfile.js | 12 ++++++------ 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index cd36ed1..7b8a710 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:rolling AS build +FROM riju:ubuntu AS build COPY docker/app/install-build.bash /tmp/ RUN /tmp/install-build.bash diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index e6a956e..9d23860 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:rolling +FROM riju:ubuntu COPY docker/base/install.bash /tmp/ RUN /tmp/install.bash diff --git a/docker/packaging/Dockerfile b/docker/packaging/Dockerfile index 5ac6598..899afb8 100644 --- a/docker/packaging/Dockerfile +++ b/docker/packaging/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:rolling +FROM riju:ubuntu COPY docker/packaging/install.bash /tmp/ RUN /tmp/install.bash diff --git a/docker/runtime/Dockerfile b/docker/runtime/Dockerfile index 62acade..0ac0212 100644 --- a/docker/runtime/Dockerfile +++ b/docker/runtime/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:rolling +FROM riju:ubuntu COPY docker/runtime/install.bash /tmp/ RUN /tmp/install.bash diff --git a/tools/depgraph.js b/tools/depgraph.js index 1a047d3..c9deaa5 100644 --- a/tools/depgraph.js +++ b/tools/depgraph.js @@ -4,6 +4,7 @@ import process from "process"; import url from "url"; import { Command } from "commander"; +import _ from "lodash"; import { getTestHash } from "../lib/hash-test.js"; import { @@ -76,13 +77,11 @@ async function getImageArtifact({ tag, isBaseImage, isLangImage }) { } return baseImage.replace(/^riju:/, ""); }); - dependencies = baseImageTags.map( - (baseImageName) => `image:${baseImageTag}` - ); + dependencies = baseImageTags.map((baseImageTag) => `image:${baseImageTag}`); } if (isLangImage) { dependencies.push(`deb:lang-${isLangImage.lang}`); - dependencies.concat( + dependencies = dependencies.concat( isLangImage.sharedDeps.map((name) => `deb:shared-${name}`) ); } @@ -178,7 +177,7 @@ async function getDebArtifact({ type, lang }) { async function getLanguageTestArtifact({ lang }) { return { name: `test:lang-${lang}`, - dependencies: ["image:runtime"], + dependencies: ["image:runtime", `image:lang-${lang}`], informationalDependencies: { getPublishedHash: "s3TestHashes", retrieveFromRegistry: "s3TestHashes", @@ -274,8 +273,30 @@ async function getDepGraph() { return { informationalDependencies, artifacts }; } -async function executeDepGraph({ publish, yes, targets }) { - // +function getTransitiveDependencies({ artifacts, targets }) { + let queue = targets; + let found = new Set(); + while (queue.length > 0) { + const name = queue.pop(); + if (found.has(name)) { + continue; + } + if (!artifacts[name]) { + throw new Error(`no such artifact: ${name}`); + } + queue = queue.concat(artifacts[name].dependencies); + found.add(name); + } + return _.sortBy([...found], (name) => Object.keys(artifacts).indexOf(name)); +} + +async function executeDepGraph({ depgraph, publish, yes, targets }) { + const artifacts = {}; + for (const artifact of depgraph.artifacts) { + artifacts[artifact.name] = artifact; + } + const transitiveTargets = getTransitiveDependencies({ artifacts, targets }); + console.log(transitiveTargets); } async function main() { @@ -298,7 +319,7 @@ async function main() { if (program.args.length === 0) { program.help({ error: true }); } - await executeDepGraph({ publish, yes, targets: program.args }); + await executeDepGraph({ depgraph, publish, yes, targets: program.args }); } if (process.argv[1] === url.fileURLToPath(import.meta.url)) { diff --git a/tools/hash-dockerfile.js b/tools/hash-dockerfile.js index 2f84bba..18b1659 100644 --- a/tools/hash-dockerfile.js +++ b/tools/hash-dockerfile.js @@ -70,13 +70,13 @@ export async function getBaseImages(name) { dockerfile.map(({ name, args, error }) => { if (error) { throw error; - if (name === "FROM") { - if (typeof args !== "string") { - throw new Error("got unexpected non-string for FROM args"); - } - const image = args.split(" ")[0]; - baseImages.push(image); + } + if (name === "FROM") { + if (typeof args !== "string") { + throw new Error("got unexpected non-string for FROM args"); } + const image = args.split(" ")[0]; + baseImages.push(image); } }); return baseImages;