Skip to content

Commit 6063982

Browse files
authored
Add documentation about RootDirectory (#15617)
* Add documentation about RootDirectory * Review feedback * Add csharp and typescript examples * Use dotnet 8 * Use latest pulumi version
1 parent f9df1eb commit 6063982

File tree

19 files changed

+192
-2
lines changed

19 files changed

+192
-2
lines changed

.github/workflows/scheduled-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ jobs:
8181

8282
- name: Install Pulumi
8383
uses: pulumi/actions@v4
84+
with:
85+
pulumi-version: latest
8486

8587
- name: Check out the code
8688
uses: actions/checkout@v3

content/docs/iac/concepts/projects/_index.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ When your Pulumi program refers to resources in the local filesystem, paths are
104104

105105
{{< example-program path="awsx-ecr-image" >}}
106106

107+
## Root-relative paths
108+
109+
You can get the directory containing the `Pulumi.yaml` file, which may differ from your working directory if it specified a `main` option (see [main attribute](/docs/reference/pulumi-yaml/#attributes)), with the `ProjectDirectory` function.
110+
111+
The path returned is an absolute path. When using this in resource properties, ensure it's relative to the working directory. This prevents diffs from running the project on multiple machines with different roots.
112+
113+
{{< example-program path="awsx-root-directory" >}}
114+
107115
## Getting the current project programmatically
108116

109117
The {{< pulumi-getproject >}} function returns the name of the currently deploying project. This can be useful for naming or tagging resources.
@@ -166,8 +174,7 @@ variables:
166174
## Stack settings files {#stack-settings-file}
167175

168176
Each stack that is created in a project will have a file named `Pulumi.<stackname>.yaml` that contains the configuration specific to this stack. This file typically resides in the root of the project directory.
169-
To change the location where stack configuration files are stored for a given project, set the `stackConfigDir` metadata attribute to a relative directory.
170177

171178
For stacks that are actively developed by multiple members of a team, the recommended practice is to check them into source control as a means of collaboration. Since secret values are encrypted, it is safe to check in these stack settings. When using ephemeral stacks, the stack settings are typically not checked into source control.
172179

173-
For detailed information about the structure and format of stack settings files, see the [Stack settings file reference](/docs/iac/concepts/projects/stack-settings-file/). For more information about configuration and how to manage these files on the command line and programmatically, refer to the [Configuration](/docs/concepts/config/) and [Secrets](/docs/concepts/secrets/) documentation.
180+
For more information about configuration and how to manage these files on the command line and programmatically, refer to the [Configuration](/docs/concepts/config/) and [Secrets](/docs/concepts/secrets/) documentation.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Pulumi;
4+
using Awsx = Pulumi.Awsx;
5+
6+
return await Deployment.RunAsync(() =>
7+
{
8+
var root = Pulumi.Deployment.Instance.RootDirectory;
9+
var cwd = Directory.GetCurrentDirectory();
10+
var appPath = Path.Combine(root, "app");
11+
var relativePath = Path.GetRelativePath(cwd, appPath);
12+
13+
var repository = new Awsx.Ecr.Repository("repository", new()
14+
{
15+
ForceDelete = true,
16+
});
17+
18+
var image = new Awsx.Ecr.Image("image", new()
19+
{
20+
RepositoryUrl = repository.Url,
21+
Context = relativePath,
22+
Platform = "linux/amd64",
23+
});
24+
25+
return new Dictionary<string, object?>
26+
{
27+
["url"] = repository.Url,
28+
};
29+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: awsx-root-directory-csharp
2+
runtime:
3+
name: dotnet
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM nginx
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Pulumi" Version="[3.87, 4.0.0)" />
11+
<PackageReference Include="Pulumi.Aws" Version="6.*" />
12+
<PackageReference Include="Pulumi.Awsx" Version="2.*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: awsx-root-directory-go
2+
runtime: go
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM nginx
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module awsx-root-directory-go
2+
3+
go 1.23.11
4+
5+
require (
6+
github.com/pulumi/pulumi-awsx/sdk/v2 v2.13.0
7+
github.com/pulumi/pulumi/sdk/v3 v3.153.0
8+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/pulumi/pulumi-awsx/sdk/v2/go/awsx/ecr"
8+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
9+
)
10+
11+
func main() {
12+
pulumi.Run(func(ctx *pulumi.Context) error {
13+
root := ctx.RootDirectory()
14+
cwd, err := os.Getwd()
15+
if err != nil {
16+
return err
17+
}
18+
path := filepath.Join(root, "app")
19+
path, err = filepath.Rel(cwd, path)
20+
if err != nil {
21+
return err
22+
}
23+
24+
repository, err := ecr.NewRepository(ctx, "repository", &ecr.RepositoryArgs{
25+
ForceDelete: pulumi.Bool(true),
26+
})
27+
if err != nil {
28+
return err
29+
}
30+
31+
_, err = ecr.NewImage(ctx, "image", &ecr.ImageArgs{
32+
RepositoryUrl: repository.Url,
33+
Context: pulumi.String(path),
34+
Platform: pulumi.String("linux/amd64"),
35+
})
36+
if err != nil {
37+
return err
38+
}
39+
40+
ctx.Export("url", repository.Url)
41+
return nil
42+
})
43+
}

0 commit comments

Comments
 (0)