From 6a909677e7463d3aa24f8e37702f8b93ce0b01d7 Mon Sep 17 00:00:00 2001 From: Christian Nunciato Date: Fri, 1 Dec 2023 07:39:26 -0800 Subject: [PATCH] Add a helper for creating new example programs (#3690) * Add a helper for creating new example programs * Update scripts/content/new-example-program.sh --- Makefile | 4 + scripts/content/new-example-program.sh | 94 +++++++++++++ .../content/docs/clouds/aws/guides/ecr.md | 125 +----------------- 3 files changed, 99 insertions(+), 124 deletions(-) create mode 100755 scripts/content/new-example-program.sh diff --git a/Makefile b/Makefile index 35164dd044c..7dfec1a6e70 100644 --- a/Makefile +++ b/Makefile @@ -87,3 +87,7 @@ new-learn-topic: .PHONY: new-template new-template: ./scripts/content/new-template.sh + +.PHONY: new-example-program +new-example-program: + ./scripts/content/new-example-program.sh diff --git a/scripts/content/new-example-program.sh b/scripts/content/new-example-program.sh new file mode 100755 index 00000000000..68f0898602e --- /dev/null +++ b/scripts/content/new-example-program.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +set -o errexit -o pipefail + +source ./scripts/common.sh + +cloud="" +example_name="" +example_description="" +examples_dir="themes/default/static/programs" + +prompt_for_cloud() { + read -p "Cloud (e.g., aws): " cloud + + if [[ ! -z "$cloud" ]]; then + return + fi + + echo "Enter a cloud name that exists in pulumi/templates, like 'aws-native' or 'scaleway'." + echo + prompt_for_cloud +} + +prompt_for_example_name() { + read -p "Example name (e.g., awsx-api-gateway-rest-api): " example_name + + if [ ! -z "$example_name" ]; then + return + fi + + echo "Please give the example a name." + prompt_for_example_name +} + +prompt_for_example_description() { + read -p "Example description (e.g., 'An example that deploys an API Gateway REST API on AWS.'): " example_description + + if [ ! -z "$example_description" ]; then + return + fi + + echo "Please give the example a description." + prompt_for_example_description +} + +generate_example() { + languages=(javascript typescript python go csharp java yaml) + + for language in "${languages[@]}"; do + example_dir="${examples_dir}/${example_name}-${language}" + + mkdir -p "${example_dir}" + + pushd "$example_dir" + pulumi new "${cloud}-${language}" --description="${example_description}" --yes --force --generate-only + popd + done + + unsuffix_gomods +} + +echo +echo "So, you want to make a new example program? Awesome! 🙌" +echo +echo "Step 1: Choose a cloud. Your example will be built from an existing Pulumi template, +so choose a cloud/provider that we have an existing - template for, like +'aws', 'azure', 'gcp', or 'digitalocean'." +echo +prompt_for_cloud + +echo +echo "Step 2: Give the example a descriptive, Pulumi project-friendly name. This name will +be used for the project prefix. Try to choose a name that succinctly describes the content +of the example, rather than the specific page you're building it for, as this'll make the +example more easily findable and reusable." +echo +prompt_for_example_name + +echo +echo "Step 3: Give the example a project description. This will be used for the description +field in Pulumi.yaml." +echo +prompt_for_example_description + +generate_example +echo +echo "Done! ✨ Your new projects are now available at ${examples_dir}/${example_name}. To +include them in any Markdown file (blog post, doc, whatever), use the '{{< example-program >}}' +shortcode thusly: + +{{< example-program path=\"${example_name}\">}} + +Enjoy!" +echo diff --git a/themes/default/content/docs/clouds/aws/guides/ecr.md b/themes/default/content/docs/clouds/aws/guides/ecr.md index 94c7b4e3ec4..63c33c42002 100644 --- a/themes/default/content/docs/clouds/aws/guides/ecr.md +++ b/themes/default/content/docs/clouds/aws/guides/ecr.md @@ -40,130 +40,7 @@ https://docs.aws.amazon.com/AmazonECR/latest/userguide/Repositories.html) to act To create a new ECR repository, allocate an instance of the `awsx.ecr.Repository` class: -{{< chooser language "javascript,typescript,python,go,csharp,java,yaml" / >}} - -{{% choosable language "javascript" %}} - -```javascript -"use strict"; -const awsx = require("@pulumi/awsx"); - -const repo = new awsx.ecr.Repository("repo"); -exports.url = repo.url; -``` - -{{% /choosable %}} - -{{% choosable language "typescript" %}} - -```typescript -import * as awsx from "@pulumi/awsx"; - -const repo = new awsx.ecr.Repository("repo"); -export const url = repo.url; -``` - -{{% /choosable %}} - -{{% choosable language python %}} - -```python -import pulumi -import pulumi_awsx as awsx - -repository = awsx.ecr.Repository("repository") -pulumi.export("url", repository.url) -``` - -{{% /choosable %}} - -{{% choosable language go %}} - -```go -package main - -import ( - "github.com/pulumi/pulumi-awsx/sdk/go/awsx/ecr" - "github.com/pulumi/pulumi/sdk/v3/go/pulumi" -) - -func main() { - pulumi.Run(func(ctx *pulumi.Context) error { - repository, err := ecr.NewRepository(ctx, "repository", nil) - if err != nil { - return err - } - - ctx.Export("url", repository.Url) - return nil - }) -} -``` - -{{% /choosable %}} - -{{% choosable language csharp %}} - -```csharp -using System.Collections.Generic; -using Pulumi; -using Awsx = Pulumi.Awsx; - -return await Deployment.RunAsync(() => -{ - var repository = new Awsx.Ecr.Repository("repository"); - - return new Dictionary - { - ["url"] = repository.Url, - }; -}); -``` - -{{% /choosable %}} - -{{% choosable language java %}} - -```java -package generated_program; - -import com.pulumi.Context; -import com.pulumi.Pulumi; -import com.pulumi.core.Output; -import com.pulumi.awsx.ecr.Repository; -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 repository = new Repository("repository"); - - ctx.export("url", repository.url()); - } -} -``` - -{{% /choosable %}} - -{{% choosable language yaml %}} - -```yaml -resources: - repository: - type: awsx:ecr:Repository -outputs: - url: ${repository.url} -``` - -{{% /choosable %}} +{{< example-program path="awsx-ecr-repository" >}} From there, we can just run `pulumi up` to provision a new repository: