diff --git a/tools/resourcedocsgen/cmd/docs/docs.go b/tools/resourcedocsgen/cmd/docs/docs.go index 518cc5ffb758..afdbf69aa879 100644 --- a/tools/resourcedocsgen/cmd/docs/docs.go +++ b/tools/resourcedocsgen/cmd/docs/docs.go @@ -1,13 +1,10 @@ package docs import ( - "embed" "encoding/json" "fmt" - "io/fs" "io/ioutil" "os" - "path/filepath" "strings" "github.com/ghodss/yaml" @@ -35,27 +32,9 @@ var ( // could have a hand-authored overlays schema spec in the overlays folder that could be // merged into it. mainSpec *pschema.PackageSpec - //go:embed overlays/**/*.json - overlays embed.FS ) func getPulumiPackageFromSchema(docsOutDir string) (*pschema.Package, error) { - overlaysSchemaFile, err := getOverlaySchema() - if err != nil { - return nil, errors.Wrap(err, "getting overlays schema") - } - - if overlaysSchemaFile != nil { - overlaySpec := &pschema.PackageSpec{} - - if err := json.Unmarshal(overlaysSchemaFile, overlaySpec); err != nil { - return nil, errors.Wrap(err, "unmarshalling overlay schema into a PackageSpec") - } - - if err := mergeOverlaySchemaSpec(mainSpec, overlaySpec); err != nil { - return nil, errors.Wrap(err, "merging the overlay schema spec with the main spec") - } - } // Delete existing docs before generating new ones. if err := os.RemoveAll(docsOutDir); err != nil { @@ -79,38 +58,6 @@ func getPulumiPackageFromSchema(docsOutDir string) (*pschema.Package, error) { return pulPkg, nil } -// getOverlaySchema returns the overlay file contents for the package. -// Returns nil if there is no overlay file for the package. -func getOverlaySchema() ([]byte, error) { - glog.Infoln("Checking if the package has an overlays schema...") - // Test the expected path for an overlays file. If there is no such file, assume - // that the package has no overlays. - overlayFilePath := filepath.Join("overlays", mainSpec.Name, "overlays.json") - f, err := overlays.Open(overlayFilePath) - if err != nil { - pathErr := err.(*fs.PathError) - if pathErr.Err == fs.ErrNotExist { - glog.Infoln("Didn't find an overlays schema...") - overlayFilePath = "" - } else { - return nil, errors.Wrap(err, "checking embedded overlays fs for overlay file") - } - } - - if overlayFilePath == "" { - return nil, nil - } - - glog.Infoln("Using the overlays schema file from", overlayFilePath) - - b, err := ioutil.ReadAll(f) - if err != nil { - return nil, errors.Wrap(err, "reading overlay file from embedded fs") - } - - return b, nil -} - func ResourceDocsCmd() *cobra.Command { var schemaFile string var version string diff --git a/tools/resourcedocsgen/cmd/docs/overlays/docker/overlays.json b/tools/resourcedocsgen/cmd/docs/overlays/docker/overlays.json deleted file mode 100644 index 679df080aeb9..000000000000 --- a/tools/resourcedocsgen/cmd/docs/overlays/docker/overlays.json +++ /dev/null @@ -1,145 +0,0 @@ -{ - "name": "docker", - "types": { - "docker:/CacheFrom:CacheFrom": { - "type": "object", - "description": "CacheFrom may be used to specify build stages to use for the Docker build cache. The final image is always implicitly included.", - "properties": { - "stages": { - "type": "array", - "description": "An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as \"[stage-name]\".", - "items": { - "type": "string" - } - } - } - }, - "docker:/DockerBuild:DockerBuild": { - "type": "object", - "description": "DockerBuild may be used to specify detailed instructions about how to build a container.", - "properties": { - "args": { - "type": "object", - "description": "An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the `RUN` instruction.", - "additionalProperties": { - "type": "string" - } - }, - "cacheFrom": { - "oneOf": [ - { - "type": "boolean" - }, - { - "$ref": "#/types/docker:/CacheFrom:CacheFrom" - } - ] - }, - "context": { - "type": "string", - "description": "context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating." - }, - "dockerfile": { - "type": "string", - "description": "dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context." - }, - "env": { - "type": "object", - "description": "Environment variables to set on the invocation of `docker build`, for example to support `DOCKER_BUILDKIT=1 docker build`.", - "additionalProperties": { - "type": "string" - } - }, - "extraOptions": { - "type": "array", - "description": "An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify `--network host`.", - "items": { - "type": "string" - } - }, - "target": { - "type": "string", - "description": "The target of the dockerfile to build" - } - } - }, - "docker:/ImageRegistry:ImageRegistry": { - "type": "object", - "properties": { - "password": { - "type": "string", - "description": "Password for login to the target Docker registry." - }, - "server": { - "type": "string", - "description": "Docker registry server URL to push to. Some common values include: DockerHub: `docker.io` or `https://index.docker.io/v1` Azure Container Registry: `.azurecr.io` AWS Elastic Container Registry: `.dkr.ecr.us-east-2.amazonaws.com` Google Container Registry: `.gcr.io`." - }, - "username": { - "type": "string", - "description": "Username for login to the target Docker registry." - } - } - } - }, - "resources": { - "docker:index/image:Image": { - "description": "A docker.Image resource represents a Docker image built locally which is published and made available via a remote Docker registry. This can be used to ensure that a Docker source directory from a local deployment environment is built and pushed to a cloud-hosted Docker registry as part of a Pulumi deployment, so that it can be referenced as an image input from other cloud services that reference Docker images - including Kubernetes Pods, AWS ECS Tasks, and Azure Container Instances.\n\n{{% examples %}}## Example Usage\n\n{{% example %}}\n\n### Create And Push Image To Azure Container Registry\n\n```typescript\n\nimport * as azure from \"@pulumi/azure\";\nimport * as docker from \"@pulumi/docker\";\nimport * as pulumi from \"@pulumi/pulumi\";\n\n// The folder containing a Dockerfile.\nconst customImage = \"node-app\";\n\nconst resourceGroup = new azure.core.ResourceGroup(\"myresourcegroup\");\nconst registry = new azure.containerservice.Registry(\"myregistry\", {\n resourceGroupName: resourceGroup.name,\n sku: \"Basic\",\n adminEnabled: true,\n});\n\nconst myImage = new docker.Image(customImage, {\n imageName: pulumi.interpolate`${registry.loginServer}/${customImage}:v1.0.0`,\n build: {\n context: `./${customImage}`,\n },\n registry: {\n server: registry.loginServer,\n username: registry.adminUsername,\n password: registry.adminPassword,\n },\n});\n\n```\n\n```python\n\nimport pulumi\nfrom pulumi_azure import core, appservice, containerservice\nfrom pulumi_docker import Image, ImageRegistry, DockerBuild\n\n# The folder containing a Dockerfile.\ncustom_image = \"my-app\"\n\nresource_group = core.ResourceGroup('myresourcegroup')\n\nregistry = containerservice.Registry(\n \"myregistry\", admin_enabled=\"true\", resource_group_name=resource_group.name, sku=\"Basic\")\n\nimage_registry = pulumi.Output.all(registry.login_server, registry.admin_username, registry.admin_password).apply(\n lambda args: ImageRegistry(args[0], args[1], args[2]))\n\nmy_image = Image(\"myimage\",\n image_name=registry.login_server.apply(\n lambda server: f'{server}/{custom_image}:v1.0.0'),\n build=DockerBuild(context=f'./{custom_image}'),\n registry=image_registry\n )\n\n```\n\n```csharp\n\nusing Pulumi;\nusing Pulumi.Azure.Core;\nusing Pulumi.Azure.ContainerService;\nusing Pulumi.Docker;\n\nclass MyStack : Stack\n{\n private readonly string CustomImage = \"my-app\";\n\n public MyStack()\n {\n // Create an Azure Resource Group\n var resourceGroup = new ResourceGroup(\"resourceGroup\");\n\n var registry = new Registry(\"myregistry\", new RegistryArgs\n {\n AdminEnabled = true,\n Sku = \"Basic\",\n ResourceGroupName = resourceGroup.Name\n });\n\n var image = new Image(\"myimage\", new ImageArgs\n {\n ImageName = Output.Format($\"{registry.LoginServer}/{CustomImage}:v1.0.0\"),\n Build = new DockerBuild\n {\n Context = $\"./{CustomImage}\"\n },\n Registry = new ImageRegistry { Server = registry.LoginServer, Username = registry.AdminUsername, Password = registry.AdminPassword }\n });\n }\n}\n```\n\n```go\n\npackage main\n\nimport (\n\t\"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/containerservice\"\n\t\"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core\"\n\t\"github.com/pulumi/pulumi-docker/sdk/v2/go/docker\"\n\t\"github.com/pulumi/pulumi/sdk/v2/go/pulumi\"\n)\n\nfunc main() {\n\tpulumi.Run(func(ctx *pulumi.Context) error {\n\t\t// Create an Azure Resource Group\n\t\tresourceGroup, err := core.NewResourceGroup(ctx, \"resourceGroup\", &core.ResourceGroupArgs{\n\t\t\tLocation: pulumi.String(\"WestUS\"),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// customImage is a folder containing a Dockerfile.\n\t\tcustomImage := \"my-app\"\n\t\tregistry, err := containerservice.NewRegistry(ctx, \"myregistry\", &containerservice.RegistryArgs{\n\t\t\tAdminEnabled: pulumi.BoolPtr(true),\n\t\t\tResourceGroupName: resourceGroup.Name,\n\t\t\tSku: pulumi.StringPtr(\"Basic\"),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t_, err = docker.NewImage(ctx, \"myimage\", &docker.ImageArgs{\n\t\t\tImageName: pulumi.Sprintf(\"%s/%s:v1.0.0\", registry.LoginServer, customImage),\n\t\t\tRegistry: docker.ImageRegistryArgs{\n\t\t\t\tServer: registry.LoginServer,\n\t\t\t\tUsername: registry.AdminUsername,\n\t\t\t\tPassword: registry.AdminPassword,\n\t\t\t},\n\t\t\tBuild: docker.DockerBuildArgs{\n\t\t\t\tContext: pulumi.Sprintf(\"./%s\", customImage),\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treturn nil\n\t})\n}\n```\n\n{{% /example %}}{{% /examples %}}", - "inputProperties": { - "build": { - "oneOf": [ - { - "type": "string" - }, - { - "$ref": "#/types/docker:/DockerBuild:DockerBuild" - } - ], - "description": "The Docker build context, as a folder path or a detailed DockerBuild object." - }, - "imageName": { - "type": "string", - "description": "The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.\n\nEither [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match." - }, - "localImageName": { - "type": "string", - "description": "The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.\n\nEither [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match." - }, - "registry": { - "$ref": "#/types/docker:/ImageRegistry:ImageRegistry", - "description": "Credentials for the docker registry to push to." - }, - "skipPush": { - "type": "boolean", - "description": "Skip push flag." - } - }, - "requiredInputs": [ - "build", - "imageName" - ], - "properties": { - "baseImageName": { - "type": "string", - "description": "The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image." - }, - "digest": { - "type": "string", - "deprecationMessage": "This will have the same value as [imageName], but will be removed in the future.", - "description": "It can be used to get a unique name for this specific image, but is not the actual repository digest value." - }, - "id": { - "type": "string", - "deprecationMessage": "This will have the same value as [imageName], but will be removed in the future." - }, - "imageName": { - "type": "string", - "description": "The unique pinned image name on the remote repository." - }, - "registryServer": { - "type": "string", - "description": "The server the image is located at." - } - } - } - } -}