Problem to solve
Describe your question in as much detail as possible:
I am using dockerfile and Angular working in WSL.
When I run the pipeline the build stage is ok, but it is failing in the test stage, and I get the message:
npm ERR! code 1
(https://gitlab/services-ui/-/jobs/351#L1409)npm ERR! path /home/gitlab/builds/iy7pHTNvB/0/stadtwin/stadtwin-fe/services-ui/node_modules/nx
(https://gitlab/services-ui/-/jobs/351#L1410)npm ERR! command failed
(https://gitlab/services-ui/-/jobs/351#L1411)npm ERR! command sh -c node ./bin/post-install
(https://gitlab/services-ui/-/jobs/351#L1412)npm ERR! internal/modules/cjs/loader.js:818
(https://gitlab/services-ui/-/jobs/351#L1413)npm ERR! throw err;
(https://gitlab/services-ui/-/jobs/351#L1414)npm ERR! ^
1415npm ERR!
1416npm ERR! Error: Cannot find module ‘fs/promises’
…s-ui/-/jobs/351#L1417)npm ERR! Require stack:
[…/services-ui/-/jobs/351#L1418)npm ERR! - /home/gitlab/builds/iy7pHTNvB/0/stadtwin/stadtwin-fe/services-ui/node_modules/nx/src/daemon/client/client.js
…
Configuration
dockerfile:
# This Dockerfile is used to build the services-ui image.
# It starts from the timbru31/java-node:21-jre-iron base image.
FROM timbru31/java-node:21-jre-iron AS build
# Set the working directory inside the container to /app.
WORKDIR /app
# Copy the package.json and package-lock.json files to the /app directory inside the container.
COPY package*.json /app
RUN npm cache clean --force
# Install the Angular CLI globally using npm.
RUN npm install -g @angular/cli
ENV NODE_ENV development
# Install the dependencies specified in the package.json file.
RUN npm ci --ignore-scripts
# Copy all the files and directories from the host machine to the /app directory inside the container.
COPY . .
RUN npm run check
# Build the Angular application.
RUN npm run build
# Add Playwright installation
RUN npm install -g @playwright/test && \
npx playwright install --with-deps
# Use the nginx:1.23.1-alpine base image
FROM nginx:1.23.1-alpine AS nginx
# Copy the contents of the /app/build/dist directory to the /usr/share/nginx/html directory in the container
COPY --from=build /app/build/dist /usr/share/nginx/html
# Copy custom nginx configuration if needed
COPY default.conf /etc/nginx/nginx.d/default.conf
# Expose port 80 to allow incoming traffic
EXPOSE 80
# Start the nginx server with the "daemon off;" option
CMD ["nginx", "-g", "daemon off;"]
gitlab-ci.yml:
stages: # List of stages for jobs, and their order of execution
- build
- test
- merge # This stage create a merge of different reports
- deploy
build-job: # This job runs in the build stage, which runs first.
image: mcr.microsoft.com/playwright:v1.47.0-jammy
stage: build
script:
- echo "Compiling the code..."
- echo "Compile complete."
shard-test-job-1: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
image: mcr.microsoft.com/playwright:v1.47.0-jammy
script:
- npm install
- npx playwright install --with-deps # install browsers and dependencies
- npx playwright test --reporter blob,junit --shard=1/3
artifacts:
when: always
paths:
- blob-report/**
- playwright-tests/results.xml
shard-test-job-2: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
image: mcr.microsoft.com/playwright:v1.47.0-jammy
script:
- npm install
- npx playwright install --with-deps # install browsers and dependencies
- npx playwright test --reporter blob,junit --shard=2/3
artifacts:
when: always
paths:
- blob-report/**
- playwright-tests/results.xml
shard-test-job-3: # This job runs in the test stage.
image: mcr.microsoft.com/playwright:v1.47.0-jammy
stage: test # It only starts when the job in the build stage completes successfully.
script:
- npm install
- npx playwright install --with-deps # install browsers and dependencies
- npx playwright test --reporter blob,junit --shard=3/3
artifacts:
when: always
paths:
- blob-report/**
- playwright-tests/results.xml
merge-test-reports:
stage: merge
image: mcr.microsoft.com/playwright:v1.47.0-jammy
script:
- npm install
- npx playwright merge-reports --reporter html ./blob-report
- npx playwright merge-reports --reporter junit ./blob-report-junit
artifacts:
when: always # also run when shards fail
paths:
- playwright-report/**
- playwright-tests/**
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
script:
- echo "Linting code... This will take about 10 seconds."
- sleep 10
- echo "No lint issues found."
deploy-job:
stage: deploy
script:
- echo "Deploying application..."
- npm run deploy
- echo "Application successfully deployed."
environment:
name: production
url: https://your-production-url.com # it must be our URL