UNPKG

@pulumi/docker

Version:

A Pulumi package for interacting with Docker in Pulumi programs

171 lines 7.85 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Image = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("./utilities"); /** * `Image` builds a Docker image and pushes it Docker and OCI compatible registries. * This resource enables running Docker builds as part of a Pulumi deployment. * * Note: We recommend you migrate your images to the more modern [Docker * Build](https://www.pulumi.com/registry/packages/docker-build/) provider to get * the best possible support, features, and performance. * * Note: This resource does not delete tags, locally or remotely, when destroyed. * * ## Image name * * The Image resource uses `imageName` to refer to a fully qualified Docker image name, by the format `repository:tag`. * Note that this does not include any digest information and thus will not cause any updates when passed to dependencies, * even when using `latest` tag. To trigger such updates, e.g. when referencing pushed images in container orchestration * and management resources, please use the `repoDigest` Output instead, which is of the format * `repository@<algorithm>:<hash>` and unique per build/push. * As of Docker v4.4, `repoDigest` is now available for local Images. * * ## Cross-platform builds * * The Image resource supports cross-platform builds when the [Docker engine has cross-platform support enabled via emulators](https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images). * The Image resource currently supports providing only a single operating system and architecture in the `platform` field, e.g.: `linux/amd64`. * To enable this support, you may need to install the emulators in the environment running your Pulumi program. * * If you are using Linux, you may be using Docker Engine or Docker Desktop for Linux, depending on how you have installed Docker. The [FAQ for Docker Desktop for Linux](https://docs.docker.com/desktop/faqs/linuxfaqs/#context) describes the differences and how to select which Docker context is in use. * * * For local development using Docker Desktop, this is enabled by default. * * For systems using Docker Engine, install the QEMU binaries and register them with using the docker image from [github.com/tonistiigi/binfmt](https://github.com/tonistiigi/binfmt): * * In a GitHub Actions workflow, the [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) can be used instead by adding this step to your workflow file. Example workflow usage: * * ## Example Usage * ### A Docker image build * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as docker from "@pulumi/docker"; * * const demoImage = new docker.Image("demo-image", { * build: { * context: ".", * dockerfile: "Dockerfile", * platform: "linux/amd64", * }, * imageName: "username/image:tag1", * skipPush: true, * }); * export const imageName = demoImage.imageName; * ``` * ### A Docker image build and push * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as docker from "@pulumi/docker"; * * const demoPushImage = new docker.Image("demo-push-image", { * build: { * context: ".", * dockerfile: "Dockerfile", * }, * imageName: "docker.io/username/push-image:tag1", * }); * export const imageName = demoPushImage.imageName; * export const repoDigest = demoPushImage.repoDigest; * ``` * ### Docker image build using caching with AWS Elastic Container Registry * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as docker from "@pulumi/docker"; * * const ecrRepository = new aws.ecr.Repository("ecr-repository", {name: "docker-repository"}); * const authToken = aws.ecr.getAuthorizationTokenOutput({ * registryId: ecrRepository.registryId, * }); * const myAppImage = new docker.Image("my-app-image", { * build: { * args: { * BUILDKIT_INLINE_CACHE: "1", * }, * cacheFrom: { * images: [pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`], * }, * context: "app/", * dockerfile: "app/Dockerfile", * }, * imageName: pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`, * registry: { * password: pulumi.secret(authToken.apply(authToken => authToken.password)), * server: ecrRepository.repositoryUrl, * username: authToken.apply(authToken => authToken.userName), * }, * }); * export const imageName = myAppImage.imageName; * ``` */ class Image extends pulumi.CustomResource { /** * Get an existing Image resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, opts) { return new Image(name, undefined, { ...opts, id: id }); } /** * Returns true if the given object is an instance of Image. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Image.__pulumiType; } /** * Create a Image resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name, args, opts) { let resourceInputs = {}; opts = opts || {}; if (!opts.id) { if (args?.imageName === undefined && !opts.urn) { throw new Error("Missing required property 'imageName'"); } resourceInputs["build"] = args?.build; resourceInputs["buildOnPreview"] = (args?.buildOnPreview) ?? false; resourceInputs["imageName"] = args?.imageName; resourceInputs["registry"] = args?.registry; resourceInputs["skipPush"] = (args?.skipPush) ?? false; resourceInputs["baseImageName"] = undefined /*out*/; resourceInputs["context"] = undefined /*out*/; resourceInputs["dockerfile"] = undefined /*out*/; resourceInputs["platform"] = undefined /*out*/; resourceInputs["registryServer"] = undefined /*out*/; resourceInputs["repoDigest"] = undefined /*out*/; } else { resourceInputs["baseImageName"] = undefined /*out*/; resourceInputs["context"] = undefined /*out*/; resourceInputs["dockerfile"] = undefined /*out*/; resourceInputs["imageName"] = undefined /*out*/; resourceInputs["platform"] = undefined /*out*/; resourceInputs["registryServer"] = undefined /*out*/; resourceInputs["repoDigest"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const aliasOpts = { aliases: [{ type: "docker:image:Image" }] }; opts = pulumi.mergeOptions(opts, aliasOpts); super(Image.__pulumiType, name, resourceInputs, opts); } } exports.Image = Image; /** @internal */ Image.__pulumiType = 'docker:index/image:Image'; //# sourceMappingURL=image.js.map