Fix small but very important bug

This commit is contained in:
Radon Rosborough 2020-12-31 22:51:51 -08:00
parent 0e85e00282
commit 40b6bb4a53
1 changed files with 23 additions and 8 deletions

View File

@ -9,7 +9,7 @@ import dockerfileParser from "docker-file-parser";
import dockerignore from "@balena/dockerignore"; import dockerignore from "@balena/dockerignore";
import _ from "lodash"; import _ from "lodash";
import { getLocalImageLabel } from "./docker-util.js"; import { getLocalImageDigest, getLocalImageLabel } from "./docker-util.js";
import { runCommand } from "./util.js"; import { runCommand } from "./util.js";
// Given a string like "runtime" that identifies the relevant // Given a string like "runtime" that identifies the relevant
@ -135,7 +135,9 @@ async function encodeDockerfile(name, dependentHashes, opts) {
step.hash = dependentHashes[image]; step.hash = dependentHashes[image];
if (!step.hash) { if (!step.hash) {
if (hashLocalImages) { if (hashLocalImages) {
step.hash = await getLocalImageLabel(image, "riju.image-hash"); step.hash = image.startsWith("riju:")
? await getLocalImageLabel(image, "riju.image-hash")
: await getLocalImageDigest(image);
} else { } else {
throw new Error(`no hash given for base image: ${image}`); throw new Error(`no hash given for base image: ${image}`);
} }
@ -174,16 +176,29 @@ export async function hashDockerfile(name, dependentHashes, opts) {
// Parse command-line arguments, run main functionality, and exit. // Parse command-line arguments, run main functionality, and exit.
async function main() { async function main() {
const args = process.argv.slice(2); const program = new Command();
if (args.length !== 1) { program
console.error("usage: hash-dockerfile.js NAME"); .arguments("<name>")
process.exit(1); .storeOptionsAsProperties(false)
.option("--debug", "output Dockerfile internal representation, unhashed");
program.parse(process.argv);
if (program.args.length !== 1) {
program.help();
} }
const [name] = args; const [name] = program.args;
const { debug } = program.opts();
if (name === "composite") { if (name === "composite") {
throw new Error("use build-composite-image.js instead for this"); throw new Error("use build-composite-image.js instead for this");
} }
console.log(await hashDockerfile(name, {}, { hashLocalImages: true })); if (debug) {
console.log(
JSON.stringify(
await encodeDockerfile(name, {}, { hashLocalImages: true })
)
);
} else {
console.log(await hashDockerfile(name, {}, { hashLocalImages: true }));
}
process.exit(0); process.exit(0);
} }