I'm trying to embed a typescript application that ...
# automation-api
n
I'm trying to embed a typescript application that leverage the Automation API to execute a Local Program using the
LocalProgramArgs
. I've set up the container with the required
PULUMI_ACCESS_TOKEN
env var and I've also provided the env-vars for AWS. Here the command I'm using to launch the container with bash.
Copy code
docker run -it \
    -e AWS_ACCESS_KEY_ID=<some-value> \
    -e AWS_SECRET_ACCESS_KEY=<some-value> \
    -e AWS_REGION=<some-value> \
    -e PULUMI_ACCESS_TOKEN=<pulumi-access-token-value> \
    -e PULUMI_BACKEND_URL='<https://api.pulumi.com>' \
    -w /app \
    -v $(pwd):/app \
    --entrypoint bash \
    pulumi/pulumi
Inside the container I'm able to navigate to the directory with the pulumi program and run the CLI commands (e.g. pulumi preview -s <stack>). When I try to run the program using the automation api, I use this command:
Copy code
npx ts-node index.ts preview
Here the content of the file index.ts
Copy code
import * as upath from 'upath';
import * as auto from '@pulumi/pulumi/automation';
import process = require('node:process');

const args = process.argv.slice(2);
let preview = false;
if (args.length > 0 && args[0]) {
  preview = args[0] === 'preview';
}

const run = async (options: TenantConfig) => {

  const wsArgs: auto.LocalProgramArgs = {
    stackName: 'mrc',
    workDir: upath.joinSafe(__dirname, '..', 'tenant-applications'),
  };

  const fullConfig = { ...baseConfig, ...options }; // create (or select if one already exists) a stack that uses our local program
  const stack = await auto.LocalWorkspace.createOrSelectStack(wsArgs);

  <http://console.info|console.info>('successfully initialized stack');
  <http://console.info|console.info>('setting up config');
  await stack.setAllConfig(fullConfig);
  <http://console.info|console.info>('config set');

  if (preview) {
    <http://console.info|console.info>('previewing stack...');
    await stack.preview({ onOutput: <http://console.info|console.info> });
  } else {
    <http://console.info|console.info>('updating stack...');
    const upRes = await stack.up({ onOutput: <http://console.info|console.info> });
    console.log(`update summary: \n${JSON.stringify(upRes.summary.resourceChanges, null, 4)}`);
  }
};

run(newConfig).catch((err) => console.error(err));
But I get this error:
Copy code
CommandError: code: -2
 stdout:
 stderr: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
Logging in using access token from PULUMI_ACCESS_TOKEN
error: failed to get the home path: getting current user: luser: unable to get current user
 err?: Error: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
Logging in using access token from PULUMI_ACCESS_TOKEN
error: failed to get the home path: getting current user: luser: unable to get current user

    at Object.createCommandError (/app/tenant-automation/node_modules/@pulumi/automation/errors.ts:75:27)
    at Object.<anonymous> (/app/tenant-automation/node_modules/@pulumi/automation/cmd.ts:84:15)
    at Generator.throw (<anonymous>)
    at rejected (/app/tenant-automation/node_modules/@pulumi/pulumi/automation/cmd.js:19:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  commandResult: CommandResult {
    stdout: '',
    stderr: 'Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive\n' +
      'Logging in using access token from PULUMI_ACCESS_TOKEN\n' +
      'error: failed to get the home path: getting current user: luser: unable to get current user',
    code: -2,
    err: Error: Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive
    Logging in using access token from PULUMI_ACCESS_TOKEN
    error: failed to get the home path: getting current user: luser: unable to get current user
        at makeError (/app/tenant-automation/node_modules/execa/lib/error.js:60:11)
        at handlePromise (/app/tenant-automation/node_modules/execa/index.js:118:26)
        at processTicksAndRejections (node:internal/process/task_queues:96:5) {
      shortMessage: 'Command failed with exit code 255: pulumi stack select --stack mrc --non-interactive',
      command: 'pulumi stack select --stack mrc --non-interactive',
      escapedCommand: 'pulumi stack select --stack mrc --non-interactive',
      exitCode: 255,
      signal: undefined,
      signalDescription: undefined,
      stdout: '',
      stderr: 'Logging in using access token from PULUMI_ACCESS_TOKEN\n' +
        'error: failed to get the home path: getting current user: luser: unable to get current user',
      failed: true,
      timedOut: false,
      isCanceled: false,
      killed: false
    }
  }
}
I don't understand what I'm doing wrong, any help would be very much appreciated
b
@nice-butcher-64302 that isn’t related to your access token, it looks like your docker image doesn’t have a user set. Can you share your docker image definition?
n
I'm literally pulling the docker image from dockerhub
image.png
@billowy-army-68599 thanks for looking into this
b
which image from dockerhub?
pulumi/pulumi
?
n
b
try adding:
Copy code
-e PULUMI_HOME='/app' \
n
Ah! That seems to have fixed the problem!
at least I can now see the preview and the command is working
Thanks a lot @billowy-army-68599.
Is this something I should flag on github somewhere?
like an Issue or something? There's no trace about this requirement in the docker image documentation
b
definitely worht opening an issue to document in pulumi/pulumi
l
@nice-butcher-64302 based on what I'm reading about your use case, you may want to consider looking at Pulumi Deployments. There is a REST API available via Pulumi Cloud that you can use to run updates/previews/refresh/etc on demand. It is kind of like a hosted version of automation API that allows you to avoid all of this setup and orchestration necessary to run auto api within docker: https://www.pulumi.com/docs/pulumi-cloud/deployments/