Skip to content

Commit

Permalink
feat: forward platform parameter to snyk-docker-pull UNIFY-163
Browse files Browse the repository at this point in the history
  • Loading branch information
adrobuta committed Jul 11, 2024
1 parent e794601 commit 2c77275
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 52 deletions.
3 changes: 3 additions & 0 deletions lib/analyzer/image-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async function pullFromContainerRegistry(
imageSavePath: string,
username: string | undefined,
password: string | undefined,
platform: string | undefined,
): Promise<DockerPullResult> {
const { hostname, imageName, tag } = extractImageDetails(targetImage);
debug(
Expand All @@ -124,6 +125,7 @@ async function pullFromContainerRegistry(
imageSavePath,
username,
password,
platform,
);
} catch (err) {
handleDockerPullError(err.message);
Expand Down Expand Up @@ -160,6 +162,7 @@ async function pullImage(
imageSavePath,
username,
password,
platform,
);

const imageName = new ImageName(targetImage, {
Expand Down
18 changes: 18 additions & 0 deletions lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,30 @@ class Docker {
imageSavePath: string,
username?: string,
password?: string,
platform?: string,
): Promise<DockerPullResult> {
const dockerPull = new DockerPull();
const platformTokens = platform ? platform.split("/") : undefined;
let os: string = "linux";
let architecture: string = "amd64";
let variant: string | undefined;

if (platformTokens) {
const platformTokensLen = platformTokens.length;
if (platformTokensLen <= 1) {
throw Error(
"Invalid platform string. Please provide a platform name that follows os/arch[/variant] format.",
);
}
os = platformTokens[0];
architecture = platformTokens[1];
variant = platformTokens[2];
}
const opt: DockerPullOptions = {
username,
password,
loadImage: false,
platform: platformTokens ? { os, architecture, variant } : undefined,
imageSavePath,
reqOptions: {
acceptManifest: [
Expand Down
129 changes: 80 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"dependencies": {
"@snyk/composer-lockfile-parser": "^1.4.1",
"@snyk/dep-graph": "^2.8.1",
"@snyk/docker-registry-v2-client": "^2.11.0",
"@snyk/docker-registry-v2-client": "2.15.0",
"@snyk/rpm-parser": "3.1.0",
"@snyk/snyk-docker-pull": "^3.11.0",
"@snyk/snyk-docker-pull": "3.13.0",
"@swimlane/docker-reference": "^2.0.1",
"adm-zip": "^0.5.5",
"chalk": "^2.4.2",
Expand Down
1 change: 1 addition & 0 deletions test/lib/analyzer/image-inspector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ describe("getImageArchive", () => {
imageSavePath,
username,
password,
undefined,
);
expect(archiveLocation.path).toEqual(
path.join(imageSavePath, "image.tar"),
Expand Down
Loading

0 comments on commit 2c77275

Please sign in to comment.