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
Adding these lines resolved my issue!
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:
I was stuck on this as well, but was able to get around it by adding
esbuild
as to mydevDependencies
inpackage.json
.Just restarting docker solved it for me
https://forums.docker.com/t/restart-docker-from-command-line/9420/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