简体   繁体   English

AWS-CDK 和 Gitlab 返回错误:spawnSync docker ENOENT

[英]AWS-CDK and Gitlab returns Error: spawnSync docker ENOENT

I am trying to run a Gitlab pipeline that builds an AWS-CDK project via the cdk-synth command.我正在尝试运行 Gitlab 管道,该管道通过 cdk-synth 命令构建 AWS-CDK 项目。 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:关于我应该在 Gitlab 跑步者中使用哪些图像,我遵循了在线建议,但我遇到了以下错误:

Error: spawnSync docker ENOENT错误:spawnSync docker ENOENT

I'm not sure what this error means exactly, I guess it is trying to launch docker (which is used by the cdk synth command) but failing to do so.我不确定此错误的确切含义,我猜它正在尝试启动 docker(由cdk synth命令使用)但未能启动。 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?我真的迷失了这个,它可能正对着我的脸盯着我看,但是有人能给我指出正确的方向吗,为什么当我使用的图像本身就是一个 docker 容器时我会收到这个错误?

I was stuck on this as well, but was able to get around it by adding esbuild as to my devDependencies in package.json .我也被困在这个问题上,但能够通过在package.json esbuild到我的devDependencies来绕过它。

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

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 eg this经过 10 天左右的时间摆弄 docker 等内部的 docker 等......以及基于相同问题的其他解决方案的大量试验和错误,例如这个

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:如果您使用的是NodejsFunction函数,您似乎需要在 gitlab-ci 模板(before_script/script)中包含以下内容:

- apk add bash (source: here ) - apk 添加 bash (来源:这里

- npm i -g esbuild - npm i -g esbuild

I believe the esbuild is used when packaging the lambda functions into docker containers.我相信在将lambda功能打包到 docker 容器中时会使用 esbuild。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM