diff --git a/provider/cmd/pulumi-resource-docker/schema.json b/provider/cmd/pulumi-resource-docker/schema.json index 86c1868a..6bf7ff77 100644 --- a/provider/cmd/pulumi-resource-docker/schema.json +++ b/provider/cmd/pulumi-resource-docker/schema.json @@ -3025,7 +3025,7 @@ } }, "docker:index/image:Image": { - "description": "Builds a Docker image and optionally pushes to a registry and Docker repository.\n\nNote: The Docker Image resource does not delete the remote image when the Pulumi resource is destroyed.\n\n## Cross-platform builds\n\nThe 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).\nThe Image resource currently supports providing only a single operating system and architecture in the `platform` field, e.g.: `linux/amd64`.\nTo enable this support, you may need to install the emulators in the environment running your Pulumi program.\n\nIf you're using Linux, you may be using Docker Engine or Docker Desktop for Linux, depending on how you've 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 you're using.\n\n* For local development using Docker Desktop, this is enabled by default.\n* 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):\n\n ```shell\n docker run --privileged --rm tonistiigi/binfmt --install all\n ```\n* 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:\n\n ```yaml\n name: Pulumi\n on:\n push:\n branches:\n - master\n jobs:\n up:\n name: Preview\n runs-on: ubuntu-latest\n steps:\n # This is the step added:\n - name: Set up QEMU\n uses: docker/setup-qemu-action@v2\n # The ordinary pulumi/actions workflow:\n - uses: actions/checkout@v3\n - uses: pulumi/actions@v4\n with:\n command: preview\n stack-name: org-name/stack-name\n env:\n PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}\n ```\n\n\n{{% examples %}}\n## Example Usage\n{{% example %}}\n### A Docker image build\n\n```typescript\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as docker from \"@pulumi/docker\";\n\nconst demoImage = new docker.Image(\"demo-image\", {\n build: {\n context: \".\",\n dockerfile: \"Dockerfile\",\n },\n imageName: \"username/image:tag1\",\n skipPush: true,\n});\nexport const imageName = demoImage.imageName;\n```\n```python\nimport pulumi\nimport pulumi_docker as docker\n\ndemo_image = docker.Image(\"demo-image\",\n build=docker.DockerBuildArgs(\n context=\".\",\n dockerfile=\"Dockerfile\",\n ),\n image_name=\"username/image:tag1\",\n skip_push=True)\npulumi.export(\"imageName\", demo_image.image_name)\n```\n```csharp\nusing System.Collections.Generic;\nusing System.Linq;\nusing Pulumi;\nusing Docker = Pulumi.Docker;\n\nreturn await Deployment.RunAsync(() =\u003e \n{\n var demoImage = new Docker.Image(\"demo-image\", new()\n {\n Build = new Docker.Inputs.DockerBuildArgs\n {\n Context = \".\",\n Dockerfile = \"Dockerfile\",\n },\n ImageName = \"username/image:tag1\",\n SkipPush = true,\n });\n\n return new Dictionary\u003cstring, object?\u003e\n {\n [\"imageName\"] = demoImage.ImageName,\n };\n});\n\n```\n```go\npackage main\n\nimport (\n\t\"github.com/pulumi/pulumi-docker/sdk/v4/go/docker\"\n\t\"github.com/pulumi/pulumi/sdk/v3/go/pulumi\"\n)\n\nfunc main() {\n\tpulumi.Run(func(ctx *pulumi.Context) error {\n\t\tdemoImage, err := docker.NewImage(ctx, \"demo-image\", \u0026docker.ImageArgs{\n\t\t\tBuild: \u0026docker.DockerBuildArgs{\n\t\t\t\tContext: pulumi.String(\".\"),\n\t\t\t\tDockerfile: pulumi.String(\"Dockerfile\"),\n\t\t\t},\n\t\t\tImageName: pulumi.String(\"username/image:tag1\"),\n\t\t\tSkipPush: pulumi.Bool(true),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tctx.Export(\"imageName\", demoImage.ImageName)\n\t\treturn nil\n\t})\n}\n```\n```yaml\nconfig: {}\ndescription: A Docker image build\nname: image-yaml\noutputs:\n imageName: ${demo-image.imageName}\nresources:\n demo-image:\n options:\n version: v4.0.0\n properties:\n build:\n context: .\n dockerfile: Dockerfile\n imageName: username/image:tag1\n skipPush: true\n type: docker:Image\nruntime: yaml\nvariables: {}\n```\n```java\npackage generated_program;\n\nimport com.pulumi.Context;\nimport com.pulumi.Pulumi;\nimport com.pulumi.core.Output;\nimport com.pulumi.docker.Image;\nimport com.pulumi.docker.ImageArgs;\nimport com.pulumi.docker.inputs.DockerBuildArgs;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Map;\nimport java.io.File;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class App {\n public static void main(String[] args) {\n Pulumi.run(App::stack);\n }\n\n public static void stack(Context ctx) {\n var demoImage = new Image(\"demoImage\", ImageArgs.builder() \n .build(DockerBuildArgs.builder()\n .context(\".\")\n .dockerfile(\"Dockerfile\")\n .build())\n .imageName(\"username/image:tag1\")\n .skipPush(true)\n .build());\n\n ctx.export(\"imageName\", demoImage.imageName());\n }\n}\n```\n{{% /example %}}\n{{% example %}}\n### Docker image build using caching with AWS Elastic Container Registry\n\n```typescript\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport * as docker from \"@pulumi/docker\";\n\nconst ecrRepository = new aws.ecr.Repository(\"ecr-repository\", {name: \"docker-repository\"});\nconst authToken = aws.ecr.getAuthorizationTokenOutput({\n registryId: ecrRepository.registryId,\n});\nconst myAppImage = new docker.Image(\"my-app-image\", {\n build: {\n args: {\n BUILDKIT_INLINE_CACHE: \"1\",\n },\n cacheFrom: {\n images: [pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`],\n },\n context: \"app/\",\n dockerfile: \"Dockerfile\",\n },\n imageName: pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`,\n registry: {\n password: pulumi.secret(authToken.password),\n server: ecrRepository.repositoryUrl,\n },\n});\nexport const imageName = myAppImage.imageName;\n```\n```python\nimport pulumi\nimport pulumi_aws as aws\nimport pulumi_docker as docker\n\necr_repository = aws.ecr.Repository(\"ecr-repository\", name=\"docker-repository\")\nauth_token = aws.ecr.get_authorization_token_output(registry_id=ecr_repository.registry_id)\nmy_app_image = docker.Image(\"my-app-image\",\n build=docker.DockerBuildArgs(\n args={\n \"BUILDKIT_INLINE_CACHE\": \"1\",\n },\n cache_from=docker.CacheFromArgs(\n images=[ecr_repository.repository_url.apply(lambda repository_url: f\"{repository_url}:latest\")],\n ),\n context=\"app/\",\n dockerfile=\"Dockerfile\",\n ),\n image_name=ecr_repository.repository_url.apply(lambda repository_url: f\"{repository_url}:latest\"),\n registry=docker.RegistryArgs(\n password=pulumi.Output.secret(auth_token.password),\n server=ecr_repository.repository_url,\n ))\npulumi.export(\"imageName\", my_app_image.image_name)\n```\n```csharp\nusing System.Collections.Generic;\nusing System.Linq;\nusing Pulumi;\nusing Aws = Pulumi.Aws;\nusing Docker = Pulumi.Docker;\n\nreturn await Deployment.RunAsync(() =\u003e \n{\n var ecrRepository = new Aws.Ecr.Repository(\"ecr-repository\", new()\n {\n Name = \"docker-repository\",\n });\n\n var authToken = Aws.Ecr.GetAuthorizationToken.Invoke(new()\n {\n RegistryId = ecrRepository.RegistryId,\n });\n\n var myAppImage = new Docker.Image(\"my-app-image\", new()\n {\n Build = new Docker.Inputs.DockerBuildArgs\n {\n Args = \n {\n { \"BUILDKIT_INLINE_CACHE\", \"1\" },\n },\n CacheFrom = new Docker.Inputs.CacheFromArgs\n {\n Images = new[]\n {\n ecrRepository.RepositoryUrl.Apply(repositoryUrl =\u003e $\"{repositoryUrl}:latest\"),\n },\n },\n Context = \"app/\",\n Dockerfile = \"Dockerfile\",\n },\n ImageName = ecrRepository.RepositoryUrl.Apply(repositoryUrl =\u003e $\"{repositoryUrl}:latest\"),\n Registry = new Docker.Inputs.RegistryArgs\n {\n Password = Output.CreateSecret(authToken.Apply(getAuthorizationTokenResult =\u003e getAuthorizationTokenResult.Password)),\n Server = ecrRepository.RepositoryUrl,\n },\n });\n\n return new Dictionary\u003cstring, object?\u003e\n {\n [\"imageName\"] = myAppImage.ImageName,\n };\n});\n\n```\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecr\"\n\t\"github.com/pulumi/pulumi-docker/sdk/v4/go/docker\"\n\t\"github.com/pulumi/pulumi/sdk/v3/go/pulumi\"\n)\n\nfunc main() {\n\tpulumi.Run(func(ctx *pulumi.Context) error {\n\t\tecrRepository, err := ecr.NewRepository(ctx, \"ecr-repository\", \u0026ecr.RepositoryArgs{\n\t\t\tName: pulumi.String(\"docker-repository\"),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tauthToken := ecr.GetAuthorizationTokenOutput(ctx, ecr.GetAuthorizationTokenOutputArgs{\n\t\t\tRegistryId: ecrRepository.RegistryId,\n\t\t}, nil)\n\t\tmyAppImage, err := docker.NewImage(ctx, \"my-app-image\", \u0026docker.ImageArgs{\n\t\t\tBuild: \u0026docker.DockerBuildArgs{\n\t\t\t\tArgs: pulumi.StringMap{\n\t\t\t\t\t\"BUILDKIT_INLINE_CACHE\": pulumi.String(\"1\"),\n\t\t\t\t},\n\t\t\t\tCacheFrom: \u0026docker.CacheFromArgs{\n\t\t\t\t\tImages: pulumi.StringArray{\n\t\t\t\t\t\tecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) {\n\t\t\t\t\t\t\treturn fmt.Sprintf(\"%v:latest\", repositoryUrl), nil\n\t\t\t\t\t\t}).(pulumi.StringOutput),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tContext: pulumi.String(\"app/\"),\n\t\t\t\tDockerfile: pulumi.String(\"Dockerfile\"),\n\t\t\t},\n\t\t\tImageName: ecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) {\n\t\t\t\treturn fmt.Sprintf(\"%v:latest\", repositoryUrl), nil\n\t\t\t}).(pulumi.StringOutput),\n\t\t\tRegistry: \u0026docker.RegistryArgs{\n\t\t\t\tPassword: pulumi.ToSecret(authToken.ApplyT(func(authToken ecr.GetAuthorizationTokenResult) (string, error) {\n\t\t\t\t\treturn authToken.Password, nil\n\t\t\t\t}).(pulumi.StringOutput)).(pulumi.StringOutput),\n\t\t\t\tServer: ecrRepository.RepositoryUrl,\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tctx.Export(\"imageName\", myAppImage.ImageName)\n\t\treturn nil\n\t})\n}\n```\n```yaml\nconfig: {}\ndescription: Docker image build using caching with AWS Elastic Container Registry\nname: image-caching-yaml\noutputs:\n imageName: ${my-app-image.imageName}\nresources:\n ecr-repository:\n properties:\n name: docker-repository\n type: aws:ecr:Repository\n my-app-image:\n options:\n version: v4.1.2\n properties:\n build:\n args:\n BUILDKIT_INLINE_CACHE: \"1\"\n cacheFrom:\n images:\n - ${ecr-repository.repositoryUrl}:latest\n context: app/\n dockerfile: Dockerfile\n imageName: ${ecr-repository.repositoryUrl}:latest\n registry:\n password:\n fn::secret: ${authToken.password}\n server: ${ecr-repository.repositoryUrl}\n type: docker:Image\nruntime: yaml\nvariables:\n authToken:\n fn::aws:ecr:getAuthorizationToken:\n registryId: ${ecr-repository.registryId}\n```\n```java\npackage generated_program;\n\nimport com.pulumi.Context;\nimport com.pulumi.Pulumi;\nimport com.pulumi.core.Output;\nimport com.pulumi.aws.ecr.Repository;\nimport com.pulumi.aws.ecr.RepositoryArgs;\nimport com.pulumi.aws.ecr.EcrFunctions;\nimport com.pulumi.aws.ecr.inputs.GetAuthorizationTokenArgs;\nimport com.pulumi.docker.Image;\nimport com.pulumi.docker.ImageArgs;\nimport com.pulumi.docker.inputs.DockerBuildArgs;\nimport com.pulumi.docker.inputs.CacheFromArgs;\nimport com.pulumi.docker.inputs.RegistryArgs;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Map;\nimport java.io.File;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class App {\n public static void main(String[] args) {\n Pulumi.run(App::stack);\n }\n\n public static void stack(Context ctx) {\n var ecrRepository = new Repository(\"ecrRepository\", RepositoryArgs.builder() \n .name(\"docker-repository\")\n .build());\n\n final var authToken = EcrFunctions.getAuthorizationToken(GetAuthorizationTokenArgs.builder()\n .registryId(ecrRepository.registryId())\n .build());\n\n var myAppImage = new Image(\"myAppImage\", ImageArgs.builder() \n .build(DockerBuildArgs.builder()\n .args(Map.of(\"BUILDKIT_INLINE_CACHE\", \"1\"))\n .cacheFrom(CacheFromArgs.builder()\n .images(ecrRepository.repositoryUrl().applyValue(repositoryUrl -\u003e String.format(\"%s:latest\", repositoryUrl)))\n .build())\n .context(\"app/\")\n .dockerfile(\"Dockerfile\")\n .build())\n .imageName(ecrRepository.repositoryUrl().applyValue(repositoryUrl -\u003e String.format(\"%s:latest\", repositoryUrl)))\n .registry(RegistryArgs.builder()\n .password(Output.ofSecret(authToken.applyValue(getAuthorizationTokenResult -\u003e getAuthorizationTokenResult).applyValue(authToken -\u003e authToken.applyValue(getAuthorizationTokenResult -\u003e getAuthorizationTokenResult.password()))))\n .server(ecrRepository.repositoryUrl())\n .build())\n .build());\n\n ctx.export(\"imageName\", myAppImage.imageName());\n }\n}\n```\n{{% /example %}}\n{{% /examples %}}", + "description": "`Image` builds a Docker image and pushes it Docker and OCI compatible registries.\nThis resource enables running Docker builds as part of a Pulumi deployment.\n\nNote: This resource does not delete tags, locally or remotely, when destroyed.\n\n## Cross-platform builds\n\nThe 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).\nThe Image resource currently supports providing only a single operating system and architecture in the `platform` field, e.g.: `linux/amd64`.\nTo enable this support, you may need to install the emulators in the environment running your Pulumi program.\n\nIf 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.\n\n* For local development using Docker Desktop, this is enabled by default.\n* 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):\n\n ```shell\n docker run --privileged --rm tonistiigi/binfmt --install all\n ```\n* 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:\n\n ```yaml\n name: Pulumi\n on:\n push:\n branches:\n - master\n jobs:\n up:\n name: Preview\n runs-on: ubuntu-latest\n steps:\n # This is the step added:\n - name: Set up QEMU\n uses: docker/setup-qemu-action@v2\n # The ordinary pulumi/actions workflow:\n - uses: actions/checkout@v3\n - uses: pulumi/actions@v4\n with:\n command: preview\n stack-name: org-name/stack-name\n env:\n PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}\n ```\n\n\n{{% examples %}}\n## Example Usage\n{{% example %}}\n### A Docker image build\n\n```typescript\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as docker from \"@pulumi/docker\";\n\nconst demoImage = new docker.Image(\"demo-image\", {\n build: {\n context: \".\",\n dockerfile: \"Dockerfile\",\n },\n imageName: \"username/image:tag1\",\n skipPush: true,\n});\nexport const imageName = demoImage.imageName;\n```\n```python\nimport pulumi\nimport pulumi_docker as docker\n\ndemo_image = docker.Image(\"demo-image\",\n build=docker.DockerBuildArgs(\n context=\".\",\n dockerfile=\"Dockerfile\",\n ),\n image_name=\"username/image:tag1\",\n skip_push=True)\npulumi.export(\"imageName\", demo_image.image_name)\n```\n```csharp\nusing System.Collections.Generic;\nusing System.Linq;\nusing Pulumi;\nusing Docker = Pulumi.Docker;\n\nreturn await Deployment.RunAsync(() =\u003e \n{\n var demoImage = new Docker.Image(\"demo-image\", new()\n {\n Build = new Docker.Inputs.DockerBuildArgs\n {\n Context = \".\",\n Dockerfile = \"Dockerfile\",\n },\n ImageName = \"username/image:tag1\",\n SkipPush = true,\n });\n\n return new Dictionary\u003cstring, object?\u003e\n {\n [\"imageName\"] = demoImage.ImageName,\n };\n});\n\n```\n```go\npackage main\n\nimport (\n\t\"github.com/pulumi/pulumi-docker/sdk/v4/go/docker\"\n\t\"github.com/pulumi/pulumi/sdk/v3/go/pulumi\"\n)\n\nfunc main() {\n\tpulumi.Run(func(ctx *pulumi.Context) error {\n\t\tdemoImage, err := docker.NewImage(ctx, \"demo-image\", \u0026docker.ImageArgs{\n\t\t\tBuild: \u0026docker.DockerBuildArgs{\n\t\t\t\tContext: pulumi.String(\".\"),\n\t\t\t\tDockerfile: pulumi.String(\"Dockerfile\"),\n\t\t\t},\n\t\t\tImageName: pulumi.String(\"username/image:tag1\"),\n\t\t\tSkipPush: pulumi.Bool(true),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tctx.Export(\"imageName\", demoImage.ImageName)\n\t\treturn nil\n\t})\n}\n```\n```yaml\nconfig: {}\ndescription: A Docker image build\nname: image-yaml\noutputs:\n imageName: ${demo-image.imageName}\nresources:\n demo-image:\n options:\n version: v4.0.0\n properties:\n build:\n context: .\n dockerfile: Dockerfile\n imageName: username/image:tag1\n skipPush: true\n type: docker:Image\nruntime: yaml\nvariables: {}\n```\n```java\npackage generated_program;\n\nimport com.pulumi.Context;\nimport com.pulumi.Pulumi;\nimport com.pulumi.core.Output;\nimport com.pulumi.docker.Image;\nimport com.pulumi.docker.ImageArgs;\nimport com.pulumi.docker.inputs.DockerBuildArgs;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Map;\nimport java.io.File;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class App {\n public static void main(String[] args) {\n Pulumi.run(App::stack);\n }\n\n public static void stack(Context ctx) {\n var demoImage = new Image(\"demoImage\", ImageArgs.builder() \n .build(DockerBuildArgs.builder()\n .context(\".\")\n .dockerfile(\"Dockerfile\")\n .build())\n .imageName(\"username/image:tag1\")\n .skipPush(true)\n .build());\n\n ctx.export(\"imageName\", demoImage.imageName());\n }\n}\n```\n{{% /example %}}\n{{% example %}}\n### Docker image build using caching with AWS Elastic Container Registry\n\n```typescript\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport * as docker from \"@pulumi/docker\";\n\nconst ecrRepository = new aws.ecr.Repository(\"ecr-repository\", {name: \"docker-repository\"});\nconst authToken = aws.ecr.getAuthorizationTokenOutput({\n registryId: ecrRepository.registryId,\n});\nconst myAppImage = new docker.Image(\"my-app-image\", {\n build: {\n args: {\n BUILDKIT_INLINE_CACHE: \"1\",\n },\n cacheFrom: {\n images: [pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`],\n },\n context: \"app/\",\n dockerfile: \"Dockerfile\",\n },\n imageName: pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`,\n registry: {\n password: pulumi.secret(authToken.password),\n server: ecrRepository.repositoryUrl,\n },\n});\nexport const imageName = myAppImage.imageName;\n```\n```python\nimport pulumi\nimport pulumi_aws as aws\nimport pulumi_docker as docker\n\necr_repository = aws.ecr.Repository(\"ecr-repository\", name=\"docker-repository\")\nauth_token = aws.ecr.get_authorization_token_output(registry_id=ecr_repository.registry_id)\nmy_app_image = docker.Image(\"my-app-image\",\n build=docker.DockerBuildArgs(\n args={\n \"BUILDKIT_INLINE_CACHE\": \"1\",\n },\n cache_from=docker.CacheFromArgs(\n images=[ecr_repository.repository_url.apply(lambda repository_url: f\"{repository_url}:latest\")],\n ),\n context=\"app/\",\n dockerfile=\"Dockerfile\",\n ),\n image_name=ecr_repository.repository_url.apply(lambda repository_url: f\"{repository_url}:latest\"),\n registry=docker.RegistryArgs(\n password=pulumi.Output.secret(auth_token.password),\n server=ecr_repository.repository_url,\n ))\npulumi.export(\"imageName\", my_app_image.image_name)\n```\n```csharp\nusing System.Collections.Generic;\nusing System.Linq;\nusing Pulumi;\nusing Aws = Pulumi.Aws;\nusing Docker = Pulumi.Docker;\n\nreturn await Deployment.RunAsync(() =\u003e \n{\n var ecrRepository = new Aws.Ecr.Repository(\"ecr-repository\", new()\n {\n Name = \"docker-repository\",\n });\n\n var authToken = Aws.Ecr.GetAuthorizationToken.Invoke(new()\n {\n RegistryId = ecrRepository.RegistryId,\n });\n\n var myAppImage = new Docker.Image(\"my-app-image\", new()\n {\n Build = new Docker.Inputs.DockerBuildArgs\n {\n Args = \n {\n { \"BUILDKIT_INLINE_CACHE\", \"1\" },\n },\n CacheFrom = new Docker.Inputs.CacheFromArgs\n {\n Images = new[]\n {\n ecrRepository.RepositoryUrl.Apply(repositoryUrl =\u003e $\"{repositoryUrl}:latest\"),\n },\n },\n Context = \"app/\",\n Dockerfile = \"Dockerfile\",\n },\n ImageName = ecrRepository.RepositoryUrl.Apply(repositoryUrl =\u003e $\"{repositoryUrl}:latest\"),\n Registry = new Docker.Inputs.RegistryArgs\n {\n Password = Output.CreateSecret(authToken.Apply(getAuthorizationTokenResult =\u003e getAuthorizationTokenResult.Password)),\n Server = ecrRepository.RepositoryUrl,\n },\n });\n\n return new Dictionary\u003cstring, object?\u003e\n {\n [\"imageName\"] = myAppImage.ImageName,\n };\n});\n\n```\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecr\"\n\t\"github.com/pulumi/pulumi-docker/sdk/v4/go/docker\"\n\t\"github.com/pulumi/pulumi/sdk/v3/go/pulumi\"\n)\n\nfunc main() {\n\tpulumi.Run(func(ctx *pulumi.Context) error {\n\t\tecrRepository, err := ecr.NewRepository(ctx, \"ecr-repository\", \u0026ecr.RepositoryArgs{\n\t\t\tName: pulumi.String(\"docker-repository\"),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tauthToken := ecr.GetAuthorizationTokenOutput(ctx, ecr.GetAuthorizationTokenOutputArgs{\n\t\t\tRegistryId: ecrRepository.RegistryId,\n\t\t}, nil)\n\t\tmyAppImage, err := docker.NewImage(ctx, \"my-app-image\", \u0026docker.ImageArgs{\n\t\t\tBuild: \u0026docker.DockerBuildArgs{\n\t\t\t\tArgs: pulumi.StringMap{\n\t\t\t\t\t\"BUILDKIT_INLINE_CACHE\": pulumi.String(\"1\"),\n\t\t\t\t},\n\t\t\t\tCacheFrom: \u0026docker.CacheFromArgs{\n\t\t\t\t\tImages: pulumi.StringArray{\n\t\t\t\t\t\tecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) {\n\t\t\t\t\t\t\treturn fmt.Sprintf(\"%v:latest\", repositoryUrl), nil\n\t\t\t\t\t\t}).(pulumi.StringOutput),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tContext: pulumi.String(\"app/\"),\n\t\t\t\tDockerfile: pulumi.String(\"Dockerfile\"),\n\t\t\t},\n\t\t\tImageName: ecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) {\n\t\t\t\treturn fmt.Sprintf(\"%v:latest\", repositoryUrl), nil\n\t\t\t}).(pulumi.StringOutput),\n\t\t\tRegistry: \u0026docker.RegistryArgs{\n\t\t\t\tPassword: pulumi.ToSecret(authToken.ApplyT(func(authToken ecr.GetAuthorizationTokenResult) (string, error) {\n\t\t\t\t\treturn authToken.Password, nil\n\t\t\t\t}).(pulumi.StringOutput)).(pulumi.StringOutput),\n\t\t\t\tServer: ecrRepository.RepositoryUrl,\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tctx.Export(\"imageName\", myAppImage.ImageName)\n\t\treturn nil\n\t})\n}\n```\n```yaml\nconfig: {}\ndescription: Docker image build using caching with AWS Elastic Container Registry\nname: image-caching-yaml\noutputs:\n imageName: ${my-app-image.imageName}\nresources:\n ecr-repository:\n properties:\n name: docker-repository\n type: aws:ecr:Repository\n my-app-image:\n options:\n version: v4.1.2\n properties:\n build:\n args:\n BUILDKIT_INLINE_CACHE: \"1\"\n cacheFrom:\n images:\n - ${ecr-repository.repositoryUrl}:latest\n context: app/\n dockerfile: Dockerfile\n imageName: ${ecr-repository.repositoryUrl}:latest\n registry:\n password:\n fn::secret: ${authToken.password}\n server: ${ecr-repository.repositoryUrl}\n type: docker:Image\nruntime: yaml\nvariables:\n authToken:\n fn::aws:ecr:getAuthorizationToken:\n registryId: ${ecr-repository.registryId}\n```\n```java\npackage generated_program;\n\nimport com.pulumi.Context;\nimport com.pulumi.Pulumi;\nimport com.pulumi.core.Output;\nimport com.pulumi.aws.ecr.Repository;\nimport com.pulumi.aws.ecr.RepositoryArgs;\nimport com.pulumi.aws.ecr.EcrFunctions;\nimport com.pulumi.aws.ecr.inputs.GetAuthorizationTokenArgs;\nimport com.pulumi.docker.Image;\nimport com.pulumi.docker.ImageArgs;\nimport com.pulumi.docker.inputs.DockerBuildArgs;\nimport com.pulumi.docker.inputs.CacheFromArgs;\nimport com.pulumi.docker.inputs.RegistryArgs;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Map;\nimport java.io.File;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class App {\n public static void main(String[] args) {\n Pulumi.run(App::stack);\n }\n\n public static void stack(Context ctx) {\n var ecrRepository = new Repository(\"ecrRepository\", RepositoryArgs.builder() \n .name(\"docker-repository\")\n .build());\n\n final var authToken = EcrFunctions.getAuthorizationToken(GetAuthorizationTokenArgs.builder()\n .registryId(ecrRepository.registryId())\n .build());\n\n var myAppImage = new Image(\"myAppImage\", ImageArgs.builder() \n .build(DockerBuildArgs.builder()\n .args(Map.of(\"BUILDKIT_INLINE_CACHE\", \"1\"))\n .cacheFrom(CacheFromArgs.builder()\n .images(ecrRepository.repositoryUrl().applyValue(repositoryUrl -\u003e String.format(\"%s:latest\", repositoryUrl)))\n .build())\n .context(\"app/\")\n .dockerfile(\"Dockerfile\")\n .build())\n .imageName(ecrRepository.repositoryUrl().applyValue(repositoryUrl -\u003e String.format(\"%s:latest\", repositoryUrl)))\n .registry(RegistryArgs.builder()\n .password(Output.ofSecret(authToken.applyValue(getAuthorizationTokenResult -\u003e getAuthorizationTokenResult).applyValue(authToken -\u003e authToken.applyValue(getAuthorizationTokenResult -\u003e getAuthorizationTokenResult.password()))))\n .server(ecrRepository.repositoryUrl())\n .build())\n .build());\n\n ctx.export(\"imageName\", myAppImage.imageName());\n }\n}\n```\n{{% /example %}}\n{{% /examples %}}", "properties": { "baseImageName": { "type": "string", diff --git a/provider/pkg/docs-gen/examples/image.md b/provider/pkg/docs-gen/examples/image.md index e0049dee..36369e56 100755 --- a/provider/pkg/docs-gen/examples/image.md +++ b/provider/pkg/docs-gen/examples/image.md @@ -1,3 +1,4 @@ +{{% examples %}} ## Example Usage {{% example %}} ### A Docker image build @@ -392,3 +393,4 @@ public class App { } ``` {{% /example %}} +{{% /examples %}} \ No newline at end of file diff --git a/sdk/dotnet/Container.cs b/sdk/dotnet/Container.cs index 0c5609d7..b9c64633 100644 --- a/sdk/dotnet/Container.cs +++ b/sdk/dotnet/Container.cs @@ -17,6 +17,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/GetNetwork.cs b/sdk/dotnet/GetNetwork.cs index a93cc471..7d63ad7a 100644 --- a/sdk/dotnet/GetNetwork.cs +++ b/sdk/dotnet/GetNetwork.cs @@ -20,6 +20,7 @@ public static class GetNetwork /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// @@ -47,6 +48,7 @@ public static Task InvokeAsync(GetNetworkArgs args, InvokeOpti /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/GetRegistryImage.cs b/sdk/dotnet/GetRegistryImage.cs index fe283d00..082bd63f 100644 --- a/sdk/dotnet/GetRegistryImage.cs +++ b/sdk/dotnet/GetRegistryImage.cs @@ -20,6 +20,7 @@ public static class GetRegistryImage /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// @@ -56,6 +57,7 @@ public static Task InvokeAsync(GetRegistryImageArgs args /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/GetRemoteImage.cs b/sdk/dotnet/GetRemoteImage.cs index 472860d9..530d3bae 100644 --- a/sdk/dotnet/GetRemoteImage.cs +++ b/sdk/dotnet/GetRemoteImage.cs @@ -20,6 +20,7 @@ public static class GetRemoteImage /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// @@ -62,6 +63,7 @@ public static Task InvokeAsync(GetRemoteImageArgs args, In /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/Image.cs b/sdk/dotnet/Image.cs index cf57716f..c1122cd9 100644 --- a/sdk/dotnet/Image.cs +++ b/sdk/dotnet/Image.cs @@ -10,7 +10,22 @@ namespace Pulumi.Docker { /// - /// Builds a Docker Image and pushes to a Docker registry. + /// `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: This resource does not delete tags, locally or remotely, when destroyed. + /// + /// ## 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 @@ -40,6 +55,59 @@ namespace Pulumi.Docker /// }); /// /// ``` + /// ### Docker image build using caching with AWS Elastic Container Registry + /// ```csharp + /// using System.Collections.Generic; + /// using System.Linq; + /// using Pulumi; + /// using Aws = Pulumi.Aws; + /// using Docker = Pulumi.Docker; + /// + /// return await Deployment.RunAsync(() => + /// { + /// var ecrRepository = new Aws.Ecr.Repository("ecr-repository", new() + /// { + /// Name = "docker-repository", + /// }); + /// + /// var authToken = Aws.Ecr.GetAuthorizationToken.Invoke(new() + /// { + /// RegistryId = ecrRepository.RegistryId, + /// }); + /// + /// var myAppImage = new Docker.Image("my-app-image", new() + /// { + /// Build = new Docker.Inputs.DockerBuildArgs + /// { + /// Args = + /// { + /// { "BUILDKIT_INLINE_CACHE", "1" }, + /// }, + /// CacheFrom = new Docker.Inputs.CacheFromArgs + /// { + /// Images = new[] + /// { + /// ecrRepository.RepositoryUrl.Apply(repositoryUrl => $"{repositoryUrl}:latest"), + /// }, + /// }, + /// Context = "app/", + /// Dockerfile = "Dockerfile", + /// }, + /// ImageName = ecrRepository.RepositoryUrl.Apply(repositoryUrl => $"{repositoryUrl}:latest"), + /// Registry = new Docker.Inputs.RegistryArgs + /// { + /// Password = Output.CreateSecret(authToken.Apply(getAuthorizationTokenResult => getAuthorizationTokenResult.Password)), + /// Server = ecrRepository.RepositoryUrl, + /// }, + /// }); + /// + /// return new Dictionary<string, object?> + /// { + /// ["imageName"] = myAppImage.ImageName, + /// }; + /// }); + /// + /// ``` /// [DockerResourceType("docker:index/image:Image")] public partial class Image : global::Pulumi.CustomResource diff --git a/sdk/dotnet/Network.cs b/sdk/dotnet/Network.cs index b7eda67a..de25406b 100644 --- a/sdk/dotnet/Network.cs +++ b/sdk/dotnet/Network.cs @@ -17,6 +17,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/Plugin.cs b/sdk/dotnet/Plugin.cs index aa753e9a..c3871448 100644 --- a/sdk/dotnet/Plugin.cs +++ b/sdk/dotnet/Plugin.cs @@ -17,6 +17,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/Pulumi.Docker.csproj b/sdk/dotnet/Pulumi.Docker.csproj index 6032ae96..56e65d06 100644 --- a/sdk/dotnet/Pulumi.Docker.csproj +++ b/sdk/dotnet/Pulumi.Docker.csproj @@ -10,7 +10,7 @@ https://github.com/pulumi/pulumi-docker logo.png - netcoreapp3.1 + net6.0 enable false @@ -39,7 +39,7 @@ - + diff --git a/sdk/dotnet/RegistryImage.cs b/sdk/dotnet/RegistryImage.cs index c5601f5c..3ef370dc 100644 --- a/sdk/dotnet/RegistryImage.cs +++ b/sdk/dotnet/RegistryImage.cs @@ -19,6 +19,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/RemoteImage.cs b/sdk/dotnet/RemoteImage.cs index d8f15ddb..21d8b710 100644 --- a/sdk/dotnet/RemoteImage.cs +++ b/sdk/dotnet/RemoteImage.cs @@ -22,6 +22,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// @@ -41,6 +42,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/dotnet/Volume.cs b/sdk/dotnet/Volume.cs index 628cd366..3b9caf24 100644 --- a/sdk/dotnet/Volume.cs +++ b/sdk/dotnet/Volume.cs @@ -17,6 +17,7 @@ namespace Pulumi.Docker /// /// ```csharp /// using System.Collections.Generic; + /// using System.Linq; /// using Pulumi; /// using Docker = Pulumi.Docker; /// diff --git a/sdk/go/docker/image.go b/sdk/go/docker/image.go index c242d220..fddd049b 100644 --- a/sdk/go/docker/image.go +++ b/sdk/go/docker/image.go @@ -11,7 +11,22 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) -// Builds a Docker Image and pushes to a Docker registry. +// `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: This resource does not delete tags, locally or remotely, when destroyed. +// +// ## 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 @@ -44,6 +59,65 @@ import ( // } // // ``` +// ### Docker image build using caching with AWS Elastic Container Registry +// ```go +// package main +// +// import ( +// +// "fmt" +// +// "github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ecr" +// "github.com/pulumi/pulumi-docker/sdk/v4/go/docker" +// "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +// +// ) +// +// func main() { +// pulumi.Run(func(ctx *pulumi.Context) error { +// ecrRepository, err := ecr.NewRepository(ctx, "ecr-repository", &ecr.RepositoryArgs{ +// Name: pulumi.String("docker-repository"), +// }) +// if err != nil { +// return err +// } +// authToken := ecr.GetAuthorizationTokenOutput(ctx, ecr.GetAuthorizationTokenOutputArgs{ +// RegistryId: ecrRepository.RegistryId, +// }, nil) +// myAppImage, err := docker.NewImage(ctx, "my-app-image", &docker.ImageArgs{ +// Build: &docker.DockerBuildArgs{ +// Args: pulumi.StringMap{ +// "BUILDKIT_INLINE_CACHE": pulumi.String("1"), +// }, +// CacheFrom: &docker.CacheFromArgs{ +// Images: pulumi.StringArray{ +// ecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) { +// return fmt.Sprintf("%v:latest", repositoryUrl), nil +// }).(pulumi.StringOutput), +// }, +// }, +// Context: pulumi.String("app/"), +// Dockerfile: pulumi.String("Dockerfile"), +// }, +// ImageName: ecrRepository.RepositoryUrl.ApplyT(func(repositoryUrl string) (string, error) { +// return fmt.Sprintf("%v:latest", repositoryUrl), nil +// }).(pulumi.StringOutput), +// Registry: &docker.RegistryArgs{ +// Password: pulumi.ToSecret(authToken.ApplyT(func(authToken ecr.GetAuthorizationTokenResult) (string, error) { +// return authToken.Password, nil +// }).(pulumi.StringOutput)).(pulumi.StringOutput), +// Server: ecrRepository.RepositoryUrl, +// }, +// }) +// if err != nil { +// return err +// } +// ctx.Export("imageName", myAppImage.ImageName) +// return nil +// }) +// } +// +// ``` type Image struct { pulumi.CustomResourceState diff --git a/sdk/java/src/main/java/com/pulumi/docker/Image.java b/sdk/java/src/main/java/com/pulumi/docker/Image.java index 5d6d6562..c120cc27 100644 --- a/sdk/java/src/main/java/com/pulumi/docker/Image.java +++ b/sdk/java/src/main/java/com/pulumi/docker/Image.java @@ -16,7 +16,22 @@ import javax.annotation.Nullable; /** - * Builds a Docker Image and pushes to a Docker registry. + * `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: This resource does not delete tags, locally or remotely, when destroyed. + * + * ## 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 @@ -55,6 +70,63 @@ * } * } * ``` + * ### Docker image build using caching with AWS Elastic Container Registry + * ```java + * package generated_program; + * + * import com.pulumi.Context; + * import com.pulumi.Pulumi; + * import com.pulumi.core.Output; + * import com.pulumi.aws.ecr.Repository; + * import com.pulumi.aws.ecr.RepositoryArgs; + * import com.pulumi.aws.ecr.EcrFunctions; + * import com.pulumi.aws.ecr.inputs.GetAuthorizationTokenArgs; + * import com.pulumi.docker.Image; + * import com.pulumi.docker.ImageArgs; + * import com.pulumi.docker.inputs.DockerBuildArgs; + * import com.pulumi.docker.inputs.CacheFromArgs; + * import com.pulumi.docker.inputs.RegistryArgs; + * import java.util.List; + * import java.util.ArrayList; + * import java.util.Map; + * import java.io.File; + * import java.nio.file.Files; + * import java.nio.file.Paths; + * + * public class App { + * public static void main(String[] args) { + * Pulumi.run(App::stack); + * } + * + * public static void stack(Context ctx) { + * var ecrRepository = new Repository("ecrRepository", RepositoryArgs.builder() + * .name("docker-repository") + * .build()); + * + * final var authToken = EcrFunctions.getAuthorizationToken(GetAuthorizationTokenArgs.builder() + * .registryId(ecrRepository.registryId()) + * .build()); + * + * var myAppImage = new Image("myAppImage", ImageArgs.builder() + * .build(DockerBuildArgs.builder() + * .args(Map.of("BUILDKIT_INLINE_CACHE", "1")) + * .cacheFrom(CacheFromArgs.builder() + * .images(ecrRepository.repositoryUrl().applyValue(repositoryUrl -> String.format("%s:latest", repositoryUrl))) + * .build()) + * .context("app/") + * .dockerfile("Dockerfile") + * .build()) + * .imageName(ecrRepository.repositoryUrl().applyValue(repositoryUrl -> String.format("%s:latest", repositoryUrl))) + * .registry(RegistryArgs.builder() + * .password(Output.ofSecret(authToken.applyValue(getAuthorizationTokenResult -> getAuthorizationTokenResult).applyValue(authToken -> authToken.applyValue(getAuthorizationTokenResult -> getAuthorizationTokenResult.password())))) + * .server(ecrRepository.repositoryUrl()) + * .build()) + * .build()); + * + * ctx.export("imageName", myAppImage.imageName()); + * } + * } + * ``` * */ @ResourceType(type="docker:index/image:Image") diff --git a/sdk/nodejs/image.ts b/sdk/nodejs/image.ts index 8bc32e47..c8e1135a 100644 --- a/sdk/nodejs/image.ts +++ b/sdk/nodejs/image.ts @@ -8,7 +8,22 @@ import * as enums from "./types/enums"; import * as utilities from "./utilities"; /** - * Builds a Docker Image and pushes to a Docker registry. + * `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: This resource does not delete tags, locally or remotely, when destroyed. + * + * ## 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 @@ -27,6 +42,36 @@ import * as utilities from "./utilities"; * }); * export const imageName = demoImage.imageName; * ``` + * ### 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: "Dockerfile", + * }, + * imageName: pulumi.interpolate`${ecrRepository.repositoryUrl}:latest`, + * registry: { + * password: pulumi.secret(authToken.password), + * server: ecrRepository.repositoryUrl, + * }, + * }); + * export const imageName = myAppImage.imageName; + * ``` */ export class Image extends pulumi.CustomResource { /** diff --git a/sdk/python/pulumi_docker/get_logs.py b/sdk/python/pulumi_docker/get_logs.py index d8952d3f..40c3da9a 100644 --- a/sdk/python/pulumi_docker/get_logs.py +++ b/sdk/python/pulumi_docker/get_logs.py @@ -177,7 +177,7 @@ def get_logs(details: Optional[bool] = None, until: Optional[str] = None, opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableGetLogsResult: """ - _get_logs_ provides logs from specific container + `get_logs` provides logs from specific container :param bool discard_headers: Discard headers that docker appends to each log entry @@ -229,7 +229,7 @@ def get_logs_output(details: Optional[pulumi.Input[Optional[bool]]] = None, until: Optional[pulumi.Input[Optional[str]]] = None, opts: Optional[pulumi.InvokeOptions] = None) -> pulumi.Output[GetLogsResult]: """ - _get_logs_ provides logs from specific container + `get_logs` provides logs from specific container :param bool discard_headers: Discard headers that docker appends to each log entry diff --git a/sdk/python/pulumi_docker/image.py b/sdk/python/pulumi_docker/image.py index e6a76c22..23f3c20a 100644 --- a/sdk/python/pulumi_docker/image.py +++ b/sdk/python/pulumi_docker/image.py @@ -97,7 +97,22 @@ def __init__(__self__, skip_push: Optional[pulumi.Input[bool]] = None, __props__=None): """ - Builds a Docker Image and pushes to a Docker registry. + `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: This resource does not delete tags, locally or remotely, when destroyed. + + ## 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 @@ -114,6 +129,32 @@ def __init__(__self__, skip_push=True) pulumi.export("imageName", demo_image.image_name) ``` + ### Docker image build using caching with AWS Elastic Container Registry + ```python + import pulumi + import pulumi_aws as aws + import pulumi_docker as docker + + ecr_repository = aws.ecr.Repository("ecr-repository", name="docker-repository") + auth_token = aws.ecr.get_authorization_token_output(registry_id=ecr_repository.registry_id) + my_app_image = docker.Image("my-app-image", + build=docker.DockerBuildArgs( + args={ + "BUILDKIT_INLINE_CACHE": "1", + }, + cache_from=docker.CacheFromArgs( + images=[ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest")], + ), + context="app/", + dockerfile="Dockerfile", + ), + image_name=ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest"), + registry=docker.RegistryArgs( + password=pulumi.Output.secret(auth_token.password), + server=ecr_repository.repository_url, + )) + pulumi.export("imageName", my_app_image.image_name) + ``` :param str resource_name: The name of the resource. :param pulumi.ResourceOptions opts: Options for the resource. @@ -129,7 +170,22 @@ def __init__(__self__, args: ImageArgs, opts: Optional[pulumi.ResourceOptions] = None): """ - Builds a Docker Image and pushes to a Docker registry. + `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: This resource does not delete tags, locally or remotely, when destroyed. + + ## 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 @@ -146,6 +202,32 @@ def __init__(__self__, skip_push=True) pulumi.export("imageName", demo_image.image_name) ``` + ### Docker image build using caching with AWS Elastic Container Registry + ```python + import pulumi + import pulumi_aws as aws + import pulumi_docker as docker + + ecr_repository = aws.ecr.Repository("ecr-repository", name="docker-repository") + auth_token = aws.ecr.get_authorization_token_output(registry_id=ecr_repository.registry_id) + my_app_image = docker.Image("my-app-image", + build=docker.DockerBuildArgs( + args={ + "BUILDKIT_INLINE_CACHE": "1", + }, + cache_from=docker.CacheFromArgs( + images=[ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest")], + ), + context="app/", + dockerfile="Dockerfile", + ), + image_name=ecr_repository.repository_url.apply(lambda repository_url: f"{repository_url}:latest"), + registry=docker.RegistryArgs( + password=pulumi.Output.secret(auth_token.password), + server=ecr_repository.repository_url, + )) + pulumi.export("imageName", my_app_image.image_name) + ``` :param str resource_name: The name of the resource. :param ImageArgs args: The arguments to use to populate this resource's properties. diff --git a/sdk/python/setup.py b/sdk/python/setup.py index 31c150df..1962acad 100644 --- a/sdk/python/setup.py +++ b/sdk/python/setup.py @@ -38,6 +38,7 @@ def readme(): setup(name='pulumi_docker', + python_requires='>=3.7', version=VERSION, description="A Pulumi package for interacting with Docker in Pulumi programs", long_description=readme(),