jetbridge/sst-prisma

Issues with Docker When Bundling Prisma Layer

kylegwalsh opened this issue · 2 comments

Hey, thanks for putting together such a comprehensive example!

I just encountered a strange error when trying to initialize the repository, but I'm not entirely sure what could have gone wrong.

SST v2.23.14  ready!

➜  App:     prisma-experiment
   Stage:   kwalsh
   Console: https://console.sst.dev/prisma-experiment/kwalsh

⠸  Checking for changesBundling asset kwalsh-prisma-experiment-Layers/PrismaLayer/Code/Stage...
✖  Checking for changes
   Error: Failed to bundle asset kwalsh-prisma-experiment-Layers/PrismaLayer/Code/Stage, bundle output is located at /Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst/dist/asset.201a0666cf41995a4f740bd540c5c3fc675a4770d2fba046cb8c12a4666b325d-error: Error: spawnSync docker ENOENT
       at AssetStaging.bundle (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:2:603)
       at AssetStaging.stageByBundling (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:4544)
       at stageThisAsset (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2005)
       at Cache.obtain (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/private/cache.js:1:242)
       at new AssetStaging (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2400)
       at new Asset (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:736)
       at AssetCode.bind (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4628)
       at new LayerVersion (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-lambda/lib/layers.js:1:2066)
       at new PrismaLayer (file:///Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst.config.1694103260464.mjs:87:9)
       at EmptyStack.Layers (file:///Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst.config.1694103260464.mjs:100:23)

It looks like the layers.ts stack is encountering issues when it tries to bundle the code and invoke the super() method inside prismaLayer.ts:

    // bundle
    const code = Code.fromAsset('./apps/backend', {
      // don't send all our files to docker (slow)
      ignoreMode: IgnoreMode.GLOB,
      exclude: ['*'],

      // if our bundle commands (basically our "dockerfile") changes then rebuild the image
      assetHashType: AssetHashType.CUSTOM,
      assetHash: bundleCommandDigest,

      bundling: {
        image: RUNTIME.bundlingImage,
        command: createBundleCommand,
      },
    });

    // THIS FAILS
    super(scope, id, { ...rest, code });

I haven't made any changes to the repository, so I encounter this error after doing the following:

  1. pnpm install
  2. Update name / region in sst.config.ts
  3. Run pnpm dev:sst

I wanted to open this issue in case there's something obvious I'm overlooking. My only thought is that maybe the repository behaves differently on an M1 Mac (which I'm using)?

I've noticed a few other resources mention this issue, but their solutions don't seem to apply in this scenario:
https://dev.to/aws-builders/fixing-error-spawnsync-bash-enoent-occurring-during-cdk-lambda-bundling-on-ci-pipeline-1m6i
https://stackoverflow.com/questions/73107862/aws-cdk-and-gitlab-returns-error-spawnsync-docker-enoent

After doing some additional research it looks like this first error was due to not having docker installed locally (I didn't realize this was an external dependency and thought it was bundled with sst).

After installing docker with brew install docker, I am encountering a different error.

   Error: Failed to bundle asset kwalsh-prisma-experiment-Layers/PrismaLayer/Code/Stage, bundle output is located at /Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst/dist/asset.201a0666cf41995a4f740bd540c5c3fc675a4770d2fba046cb8c12a4666b325d-error: Error: docker exited with status 125
   --> Command: docker run --rm -u "501:20" -v "/Users/kyle/Documents/Dev/homelendingpal/sst-prisma:/asset-input:delegated" -v "/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst/dist/asset.201a0666cf41995a4f740bd540c5c3fc675a4770d2fba046cb8c12a4666b325d:/asset-output:delegated" -w "/asset-input" "public.ecr.aws/sam/build-nodejs18.x" bash -c "echo \"Installing @prisma/client@5.1.1 @prisma/engines@5.1.1\" && mkdir -p /tmp/npm && pushd /tmp/npm && HOME=/tmp npm i --no-save --no-package-lock npm@latest && popd && mkdir -p /asset-output/nodejs && cd /asset-output/nodejs && HOME=/tmp /tmp/npm/node_modules/.bin/npm install --omit dev --omit peer --omit optional @prisma/client@5.1.1 @prisma/engines@5.1.1 && rm -f /asset-output/nodejs/node_modules/@prisma/engines/introspection-engine* && rm -f /asset-output/nodejs/node_modules/@prisma/engines/schema-engine* && rm -f /asset-output/nodejs/node_modules/@prisma/engines/prisma-fmt* && rm -f /asset-output/nodejs/node_modules/@prisma/internals/dist/libquery_engine* && rm -f /asset-output/nodejs/node_modules/@prisma/internals/dist/get-generators/libquery_engine* && rm -rf /asset-output/nodejs/node_modules/@prisma/internals/dist/get-generators/engines && rm -rf /asset-output/nodejs/node_modules/@prisma/engines/download && rm -rf /asset-output/nodejs/node_modules/@prisma/client/generator-build && rm -rf /asset-output/nodejs/node_modules/@prisma/engine-core/node_modules/@prisma/engines && rm -rf /asset-output/nodejs/node_modules/prisma/build/public && rm -rf /asset-output/nodejs/node_modules/prisma/prisma-client/src/__tests__ && rm -rf /asset-output/nodejs/node_modules/prisma/prisma-client/generator-build && rm -rf /asset-output/nodejs/node_modules/@types && rm -rf /asset-output/nodejs/node_modules/.prisma"
       at AssetStaging.bundle (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:2:603)
       at AssetStaging.stageByBundling (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:4544)
       at stageThisAsset (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2005)
       at Cache.obtain (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/private/cache.js:1:242)
       at new AssetStaging (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2400)
       at new Asset (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:736)
       at AssetCode.bind (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4628)
       at new LayerVersion (/Users/kyle/Documents/Dev/homelendingpal/sst-prisma/node_modules/.pnpm/aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/aws-cdk-lib/aws-lambda/lib/layers.js:1:2066)
       at new PrismaLayer (file:///Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst.config.1694110739061.mjs:87:9)
       at EmptyStack.Layers (file:///Users/kyle/Documents/Dev/homelendingpal/sst-prisma/.sst.config.1694110739061.mjs:100:23)

I will continue to go down the rabbit hole in hopes of resolving this.

It looks like installing the actual Docker application directly may have resolved my issue.

Sorry for any confusion.