great-sunset-355
11/21/2024, 1:17 PMcwd passed to the pulumi up --cwd somehow in the code? (not automation API)incalculable-mouse-24065
11/21/2024, 1:34 PMpulumi -C "$(dirname $0)" $@
?incalculable-mouse-24065
11/21/2024, 1:35 PM$ pulumi --help |grep cw
-C, --cwd string Run pulumi as if it had been started in another directorygreat-sunset-355
11/21/2024, 1:38 PMincalculable-mouse-24065
11/21/2024, 1:40 PMMac-Studio:tmp andiolsi$ cat foo.js
console.log(__dirname);
Mac-Studio:tmp andiolsi$ node foo.js
/Users/andiolsi/tmpincalculable-mouse-24065
11/21/2024, 1:40 PMincalculable-mouse-24065
11/21/2024, 1:43 PMimport * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const cwd = process.env.CWD || config.require("CWD");
export { cwd };
export CWD="moo"
pulumi -C "${CWD}" $@incalculable-mouse-24065
11/21/2024, 1:43 PMgreat-sunset-355
11/21/2024, 1:51 PM__dirname resolves to absolute path and I have a local command, where scriptPath= __dirname+"something.ts"
const cmd = new command.local.Command(
`${name}`,
{
environment: {
AWS_ACCOUNT_ID: pulumi.interpolate`${args.accountId}`,
},
create: `date && node --require ts-node/register ${scriptPath}`,
triggers: [md5],
},
{ ...opts, protect: false }
);
the problem is that ${scriptPath} is different in every system and if I use relative path, it has to be relative to the pulumi execution, rendering the function portability uselessincalculable-mouse-24065
11/21/2024, 10:57 PMincalculable-mouse-24065
11/21/2024, 10:58 PMgreat-sunset-355
11/22/2024, 10:41 AMwooden-scooter-37140
11/22/2024, 11:07 AMCopyFile but never came up with a good solution, though admittedly I didn't try very hard as we setup a cicd server to handle deployments and only did manual deployments in emergencies.
For Command , I bypassed the problem by reading the content of the file and supplying that as the script explicitlyincalculable-mouse-24065
11/22/2024, 11:13 AMimport { local } from "@pulumi/command";
const testFoo = new local.Command("testFoo", {
create: "echo $TEST_FOO >> $HOME/testFoo.txt",
});
export const output = testFoo.stdout;
Mac-Studio:~ andiolsi$ TEST_FOO=käse ~/work/olsicloud4/pulumi/gitlab-olsitrack2/run.sh up
Previewing update (gitlab-olsitrack2):
Type Name Plan
pulumi:pulumi:Stack gitlab-gitlab-olsitrack2
+ └─ command:local:Command testFoo create
Outputs:
+ output : output<string>
Resources:
+ 1 to create
42 unchanged
Do you want to perform this update? yes
Updating (gitlab-olsitrack2):
Type Name Status
pulumi:pulumi:Stack gitlab-gitlab-olsitrack2
+ └─ command:local:Command testFoo created (0.01s)
...
Resources:
+ 1 created
42 unchanged
Mac-Studio:~ andiolsi$ TEST_FOO=wurst ~/work/olsicloud4/pulumi/gitlab-olsitrack2/run.sh up
Previewing update (gitlab-olsitrack2):
Type Name Plan
pulumi:pulumi:Stack gitlab-gitlab-olsitrack2
Resources:
43 unchanged
Do you want to perform this update? yes
Updating (gitlab-olsitrack2):
Type Name Status
pulumi:pulumi:Stack gitlab-gitlab-olsitrack2
...
Resources:
43 unchanged
Duration: 3s
Mac-Studio:~ andiolsi$ cat testFoo.txt
wurst
käseincalculable-mouse-24065
11/22/2024, 11:16 AMincalculable-mouse-24065
11/22/2024, 11:16 AMconst testFoo = new local.Command(
"testFoo",
{
environment: {
TEST_FOO: "danny",
},
create: "echo $TEST_FOO >> $HOME/testFoo.txt",
},
{ ignoreChanges: ["environment"] },
);incalculable-mouse-24065
11/22/2024, 11:23 AMincalculable-mouse-24065
11/22/2024, 11:25 AMconst cmd = new command.local.Command(
`${name}`,
{
environment: {
SCRIPT_PATH: someVarThatContaintsTheScriptPath,
},
create: pulumi.interpolate`date && AWS_ACCOUNT_ID="${args.accountId}" node --require ts-node/register "$\{SCRIPT_PATH\}"`,
triggers: [md5],
},
{ ...opts, protect: false, ignoreChanges: ["environment"] }
);incalculable-mouse-24065
11/22/2024, 11:26 AMlocal all env vars passed to pulumi are available to all Commands anyway, so you can even skip that whole variable thing for it altogehter.