Skip to content

Commit ecca7d6

Browse files
committed
Merge related functions
inspectDockerImage was returning only a limited version data. If we need a generic inspect function later then we could extract it, right now there is no need as there is no other usage of inspect.
1 parent 15bc2b7 commit ecca7d6

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

src/utils/setup.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,31 @@ const InspectSchema = z.array(
4545
}),
4646
);
4747

48-
async function inspectDockerImage(
49-
outputChannel: LogOutputChannel,
50-
): Promise<string | undefined> {
51-
try {
52-
const { stdout } = await exec(`docker inspect ${LOCALSTACK_DOCKER_IMAGE}`);
53-
const data: unknown = JSON.parse(stdout);
54-
const parsed = InspectSchema.safeParse(data);
55-
if (!parsed.success) {
56-
throw new Error(
57-
`Could not parse "docker inspect" output: ${JSON.stringify(z.treeifyError(parsed.error))}`,
58-
);
59-
}
60-
const env = parsed.data[0]?.Config.Env ?? [];
61-
const version = env
62-
.find((line) => line.startsWith("LOCALSTACK_BUILD_VERSION="))
63-
?.slice("LOCALSTACK_BUILD_VERSION=".length);
64-
return version;
65-
} catch (error) {
66-
outputChannel.error("Could not inspect LocalStack docker image");
67-
outputChannel.error(error instanceof Error ? error : String(error));
68-
return undefined;
69-
}
70-
}
71-
7248
async function getDockerImageSemverVersion(
7349
outputChannel: LogOutputChannel,
7450
): Promise<string | undefined> {
75-
const imageVersion = await inspectDockerImage(outputChannel);
76-
if (!imageVersion) {
77-
return;
78-
}
79-
80-
return imageVersion;
51+
try {
52+
const { stdout } = await exec(`docker inspect ${LOCALSTACK_DOCKER_IMAGE}`);
53+
const data: unknown = JSON.parse(stdout);
54+
const parsed = InspectSchema.safeParse(data);
55+
if (!parsed.success) {
56+
throw new Error(
57+
`Could not parse "docker inspect" output: ${JSON.stringify(z.treeifyError(parsed.error))}`,
58+
);
59+
}
60+
const env = parsed.data[0]?.Config.Env ?? [];
61+
const imageVersion = env
62+
.find((line) => line.startsWith("LOCALSTACK_BUILD_VERSION="))
63+
?.slice("LOCALSTACK_BUILD_VERSION=".length);
64+
if (!imageVersion) {
65+
return;
66+
}
67+
return imageVersion;
68+
} catch (error) {
69+
outputChannel.error("Could not inspect LocalStack docker image");
70+
outputChannel.error(error instanceof Error ? error : String(error));
71+
return undefined;
72+
}
8173
}
8274

8375
async function pullDockerImage(

0 commit comments

Comments
 (0)