Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Add a helper for creating new example programs (#3690)
Browse files Browse the repository at this point in the history
* Add a helper for creating new example programs

* Update scripts/content/new-example-program.sh
  • Loading branch information
cnunciato authored Dec 1, 2023
1 parent dd54bab commit 6a90967
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 124 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
94 changes: 94 additions & 0 deletions scripts/content/new-example-program.sh
Original file line number Diff line number Diff line change
@@ -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 <cloud>-<language> 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
125 changes: 1 addition & 124 deletions themes/default/content/docs/clouds/aws/guides/ecr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object?>
{
["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:

Expand Down

0 comments on commit 6a90967

Please sign in to comment.