oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.86k stars 2.56k forks source link

Get cdktf-cli package working #5306

Open ozyman42 opened 9 months ago

ozyman42 commented 9 months ago

What version of Bun is running?

1.0.2

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

From the host OS

docker run -it --rm --entrypoint bash oven/bun:1.0.2

From within the container

export PATH=$PATH:/root/.bun/bin export BUN_INSTALL=/root/.bun bun i -g cdktf-cli bunx cdktf

What is the expected behavior?

It prints the CLI options

What do you see instead?

see https://github.com/jprichardson/node-fs-extra/issues/269

then a bunch of minified JS then

EBADF: Bad file descriptor
 syscall: "fstat"
   errno: -9
      at aC (/root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf.js:53:32710)
      at /root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf.js:53:33219
      at /root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf.js:1:272
      at /root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf.js:54:1931
      at globalThis (/root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf.js:77:0)
      at require (:1:20)
      at /root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf:2:0
      at globalThis (/root/.bun/install/global/node_modules/cdktf-cli/bundle/bin/cdktf:2:0)
error: "cdktf" exited with code 1 (SIGHUP)

Additional information

I've seen different errors depending on the host OS I'm using. Sometimes it's this error, sometimes I see

error: SystemResources

----- bun meta -----
Bun v1.0.0 (822a00c4) Linux arm64 #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023
BunxCommand:
Elapsed: 5ms | User: 2ms | Sys: 4ms
RSS: 33.55MB | Peak: 11.87MB | Commit: 33.55MB | Faults: 0
----- bun meta -----

0   0xaaaac9e1f478
1   ???
2   ???
3   ???
4   ???
5   ???

Crash report saved to:
  ~/.bun-crash/v1.0.0-1694633037924.crash

Search GitHub issues https://bun.sh/issues or ask for #help in https://bun.sh/discord

if I forgot to set the PATH or BUN_INSTALL variables.

There was once occasion where I saw the CLI options, but they all started with bunx rather than cdktf as the CLI in the help menu, likely something having to do w/ the implementation using argv[0]. After that I tried to run

cdktf init

and got yet another error of some core node module missing.

Overall I'm attempting to start this as a master ticket coordinating everything else needed in order to get cdktf working in bun.

Electroid commented 9 months ago

There are 2 issues here, both being tracked in other issues:

ozyman42 commented 9 months ago

@Electroid can we keep this open as I think excluding #4798 and #4785, there are still additional issues w/ the cdktf CLI. It is planned within Bun's roadmap to support this package because I plan on working on this if allowed.

ConorWright commented 9 months ago

I'm running into similar issues with v1.0.2 (Which fixed some of the aws sdk errors) and now I'm getting

Error: Cannot find module '../build/Release/pty.node'

ozyman42 commented 9 months ago

@ConorWright did you mean to post this somewhere else? This ticket is meant for the cdktf-cli npm package specifically. With v1.0.2 I'm still seeing the error being tracked in #1446

ozyman42 commented 9 months ago

Tried again today w/ bun 1.0.2 and made it past the crash error.

root@f80276d57270:/home/bun/app# bunx cdktf
Please pass a command to cdktf, here are all available ones:
bunx

Commands:
  bunx init                Create a new cdktf project from a template.
  bunx get                 Generate CDK Constructs for Terraform providers and modules.
  bunx convert             Converts a single file of HCL configuration to CDK for Terraform. Takes the
                           file to be converted on stdin.
  bunx deploy [stacks...]  Deploy the given stacks                                      [aliases: apply]
  bunx destroy [stacks..]  Destroy the given stacks
  bunx diff [stack]        Perform a diff (terraform plan) for the given stack           [aliases: plan]
  bunx list                List stacks in app.
  bunx login               Retrieves an API token to connect to Terraform Cloud or Terraform Enterprise.
  bunx synth               Synthesizes Terraform code for the given app in a directory.
                                                                                   [aliases: synthesize]
  bunx watch [stacks..]    [experimental] Watch for file changes and automatically trigger a deploy
  bunx output [stacks..]   Prints the output of stacks                                [aliases: outputs]
  bunx debug               Get debug information about the current project and environment
  bunx provider            A set of subcommands that facilitates provider management
  bunx completion          generate completion script

Options:
      --version                   Show version number                                          [boolean]
      --disable-plugin-cache-env  Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the
                                  plugin cache is configured differently. Supported using the env
                                  CDKTF_DISABLE_PLUGIN_CACHE_ENV.             [boolean] [default: false]
      --log-level                 Which log level should be written. Only supported via setting the env
                                  CDKTF_LOG_LEVEL                                               [string]
  -h, --help                      Show help                                                    [boolean]

Options can be specified via environment variables with the "CDKTF_" prefix (e.g. "CDKTF_OUTPUT")
error: "cdktf" exited with code 1 (SIGHUP)
root@f80276d57270:/home/bun/app# bunx cdktf init
node: symbol lookup error: /root/.bun/install/global/node_modules/@cdktf/node-pty-prebuilt-multiarch/prebuilds/linux-x64/node.abi108.node: undefined symbol: node_module_register
error: "cdktf" exited with code 127

So here we can see a couple issues:

  1. the cdktf program is getting confused and printing bunx when it meant to print cdktf
  2. A node symbol lookup error undefined symbol: node_module_register
ozyman42 commented 9 months ago

To solve problem 1 above, I did the following:

cp /usr/local/bin/bun /usr/local/bin/node

Then I got

root@126897ef06e0:/home/bun/app# cdktf -h
cdktf

Commands:
  cdktf init                Create a new cdktf project from a template.
  cdktf get                 Generate CDK Constructs for Terraform providers and modules.
  cdktf convert             Converts a single file of HCL configuration to CDK for Terraform. Takes the file to be converted on stdin.
  cdktf deploy [stacks...]  Deploy the given stacks                                                                                                                                                                                           [aliases: apply]
  cdktf destroy [stacks..]  Destroy the given stacks
  cdktf diff [stack]        Perform a diff (terraform plan) for the given stack                                                                                                                                                                [aliases: plan]
  cdktf list                List stacks in app.
  cdktf login               Retrieves an API token to connect to Terraform Cloud or Terraform Enterprise.
  cdktf synth               Synthesizes Terraform code for the given app in a directory.                                                                                                                                                 [aliases: synthesize]
  cdktf watch [stacks..]    [experimental] Watch for file changes and automatically trigger a deploy
  cdktf output [stacks..]   Prints the output of stacks                                                                                                                                                                                     [aliases: outputs]
  cdktf debug               Get debug information about the current project and environment
  cdktf provider            A set of subcommands that facilitates provider management
  cdktf completion          generate completion script

Options:
      --version                   Show version number                                                                                                                                                                                                [boolean]
      --disable-plugin-cache-env  Dont set TF_PLUGIN_CACHE_DIR automatically. This is useful when the plugin cache is configured differently. Supported using the env CDKTF_DISABLE_PLUGIN_CACHE_ENV.                               [boolean] [default: false]
      --log-level                 Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL                                                                                                                               [string]
  -h, --help                      Show help                                                                                                                                                                                                          [boolean]

Options can be specified via environment variables with the "CDKTF_" prefix (e.g. "CDKTF_OUTPUT")

so the help menu was showing as expected.

ConorWright commented 9 months ago

@ConorWright did you mean to post this somewhere else? This ticket is meant for the cdktf-cli npm package specifically. With v1.0.2 I'm still seeing the error being tracked in #1446

I get this when running a cdktf synth. They have their own fork of node-pty Haven't tried it with 1.0.3 yet.

mstuercke commented 9 months ago

I'm running into similar issues with v1.0.2 (Which fixed some of the aws sdk errors) and now I'm getting

Error: Cannot find module '../build/Release/pty.node'

I got this working, by using a node image and installing bun/cdktf in it. It's a workaround, yes, but I see no other way (yet) to use ctktf with bun in a docker container.

Run these commands in your container (I used the image node:18.17.1):

export BUN_VERSION=1.0.4
export TERRAFORM_VERSION=1.5.7
npm install -g bun@${BUN_VERSION}
wget -q "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
mv terraform /usr/bin/terraform

To test if cdktf is working in the container, execute something like this:

mkdir cdktf-test
cd cdktf-test
bun add cdktf-cli
bun run cdktf init
Jarred-Sumner commented 6 months ago

node_module_register is being tracked in https://github.com/oven-sh/bun/issues/4290