Skip to content

Commit

Permalink
docker-build
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Apr 26, 2024
1 parent adae402 commit b9b562f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
57 changes: 36 additions & 21 deletions awsx/ecr/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import * as aws from "@pulumi/aws";
import * as docker from "@pulumi/docker";
import * as docker from "@pulumi/docker-build";
import * as pulumi from "@pulumi/pulumi";
import * as schema from "../schema-types";
import * as utils from "../utils";
Expand Down Expand Up @@ -62,37 +62,52 @@ export function computeImageFromAsset(
throw new Error("Invalid credentials");
}
return {
registry: ecrCredentials.proxyEndpoint,
address: ecrCredentials.proxyEndpoint,
username: username,
password: password,
};
});

let cacheFrom: docker.types.input.CacheFromArgs[] = [];
if (dockerInputs.cacheFrom !== undefined) {
cacheFrom = dockerInputs.cacheFrom.map((c) => {
return {
registry: {
ref: c,
},
};
});
}
// Use an inline cache by default.
if (cacheFrom.length === 0) {
cacheFrom.push({ registry: { ref: canonicalImageName } });
}

let context = ".";
if (dockerInputs.context !== undefined) {
context = dockerInputs.context;
}

const dockerImageArgs: docker.ImageArgs = {
imageName: canonicalImageName,
build: {
args: dockerInputs.args,
builderVersion: dockerInputs.builderVersion,
cacheFrom: dockerInputs.cacheFrom
? {
images: dockerInputs.cacheFrom,
}
: undefined,
context: dockerInputs.context,
dockerfile: dockerInputs.dockerfile,
platform: dockerInputs.platform,
target: dockerInputs.target,
},
registry: registryCredentials,
tags: [canonicalImageName],
buildArgs: dockerInputs.args,
cacheFrom: cacheFrom,
cacheTo: [{ inline: {} }],
context: { location: context },
dockerfile: { location: dockerInputs.dockerfile },
platforms: dockerInputs.platform ? [dockerInputs.platform as docker.Platform] : [],
target: dockerInputs.target,
push: true,
registries: [registryCredentials],
};

const image = new docker.Image(imageName, dockerImageArgs, { parent });

image.repoDigest.apply((d: any) =>
pulumi.log.debug(` build complete: ${imageName} (${d})`, parent),
);
image.ref.apply((ref) => {
pulumi.log.debug(` build complete: ${ref}`, parent);
});

return image.repoDigest;
return image.ref;
}

function createUniqueImageName(inputs: pulumi.Unwrap<schema.DockerBuildInputs>): string {
Expand Down
4 changes: 2 additions & 2 deletions awsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
},
"//": "Pulumi sub-provider dependencies must be pinned at an exact version because we extract this value to generate the correct dependency in the schema",
"dependencies": {
"@pulumi/aws": "6.32.0",
"@pulumi/aws": "6.9.0",
"@pulumi/docker": "4.5.1",
"@pulumi/docker-build": "0.0.2",
"@pulumi/pulumi": "^3.91.1",
"@types/aws-lambda": "^8.10.23",
"docker-classic": "npm:@pulumi/[email protected]",
Expand Down Expand Up @@ -63,4 +64,3 @@
]
}
}

18 changes: 13 additions & 5 deletions awsx/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1519,16 +1519,24 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@pulumi/aws@6.32.0":
version "6.32.0"
resolved "https://registry.yarnpkg.com/@pulumi/aws/-/aws-6.32.0.tgz#3afd3f938b44fc12de250c70fe773d8452c29d5a"
integrity sha512-kXoRn427RjSALvyEwMI5wZibNf8lRlp16vgPfI2n2OT7CLvtmqnI16IRPJ01gVf8I95sku1meKqXwXAQ+2O1Zw==
"@pulumi/aws@6.9.0":
version "6.9.0"
resolved "https://registry.yarnpkg.com/@pulumi/aws/-/aws-6.9.0.tgz#1f65cd5843d22aa477f97468b3d5b8d6311b538c"
integrity sha512-c0ivz01YEuZesfroFSQJdjXivyltdvXBW8hcOhGCwAycjmHpDnXI0HSXk9aIkwxVrUBAW0MQYEa+QRHb5W2V1Q==
dependencies:
"@pulumi/pulumi" "^3.0.0"
builtin-modules "3.0.0"
mime "^2.0.0"
read-package-tree "^5.2.1"
resolve "^1.7.1"

"@pulumi/[email protected]":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@pulumi/docker-build/-/docker-build-0.0.2.tgz#3a23ac8fb60136545c080fac092845b330cc8f96"
integrity sha512-TaPd8OViDBekjYRXlmxCqn6cWlNtAy0i7pv7mXzZSKipaaDHl1h0DA/uU7MKGbYruZAHV7eYKxZxRxwBnTW63g==
dependencies:
"@pulumi/pulumi" "^3.0.0"

"@pulumi/[email protected]":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@pulumi/docker/-/docker-4.5.1.tgz#9058851bebbb358a1081c765d928fd6791c6c7ba"
Expand Down Expand Up @@ -4388,7 +4396,7 @@ read-package-json@^2.0.0:
normalize-package-data "^2.0.0"
npm-normalize-package-bin "^1.0.0"

read-package-tree@^5.3.1:
read-package-tree@^5.2.1, read-package-tree@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/read-package-tree/-/read-package-tree-5.3.1.tgz#a32cb64c7f31eb8a6f31ef06f9cedf74068fe636"
integrity sha512-mLUDsD5JVtlZxjSlPPx1RETkNjjvQYuweKwNVt1Sn8kP5Jh44pvYuUHCp6xSVDZWbNxVxG5lyZJ921aJH61sTw==
Expand Down

0 comments on commit b9b562f

Please sign in to comment.