skip to Main Content

I am trying to run a Gitlab pipeline that builds an AWS-CDK project via the cdk-synth command. I have followed advice online in terms of what images I should be using in the Gitlab runner but I am running into the following error:

Error: spawnSync docker ENOENT

I’m not sure what this error means exactly, I guess it is trying to launch docker (which is used by thecdk synth command) but failing to do so. Again what I have found online all suggests to use the setup I currently have which is:

image: node:16.3.0-alpine

stages:
  - build
  - test
  - .post

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - node_modules

build:
  tags:
    - mytag
  environment: ${CI_COMMIT_BRANCH}
  stage: build
  script:
    - npm i
    - cdk synth --no-staging > template.yaml
  artifacts:
    paths:
      - cdk.out
    expire_in: 30 mins

I’m really lost with this one, it may be staring me right in the face but could someone please point me in the right direction as to why i’d be getting this error when the image i’m using is itself a docker container?

5

Answers


  1. Chosen as BEST ANSWER

    Adding these lines resolved my issue!

      script:
        - apt-get update
        - apt-get install -y ca-certificates curl gnupg lsb-release
        - mkdir -p /etc/apt/keyrings
        - curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
        - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
        - apt-get update
        - apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
        - npm i
        - npm run synth
    

  2. After a good 10 or so days of fiddling with docker inside of docker etc… and lots of trial and error based on other solutions to the same problem e.g.
    this

    I arrived at the following solution.

    It seems you need to include the following in your gitlab-ci template (before_script/script) if you are using the NodejsFunction functions:

    – apk add bash (source: here)

    – npm i -g esbuild

    esbuild is used when packaging the JavaScript based lambda function code and its dependencies into a single file. Here’s what worked for me:

    cdk_synth:
      image: node:16-alpine
      stage: validate
      before_script:
        - apk add bash
        - npm i -g esbuild
        - npm install
        - npm i -g aws-cdk
        - npm i -g aws-cdk-lib
      script:
        - cdk bootstrap aws://$AWS_ACCOUNT_ID/$AWS_REGION
        - cdk synth
    
    Login or Signup to reply.
  3. I was stuck on this as well, but was able to get around it by adding esbuild as to my devDependencies in package.json.

    Login or Signup to reply.
  4. If you are running locally esbuild is required to bundle your code in your environment. Otherwise, bundling will happen in a Docker container.

    Install esbuild with:
    $ npm install --save-dev esbuild@0

    https://docs.aws.amazon.com/cdk/api/v1/docs/aws-lambda-nodejs-readme.html#local-bundling

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search