Can not get cypress to work in docker container - docker

I want to run cypress in docker container and for this purpose i created.
For this i followed some guides and tutorials
e2e directory that has Dockerfile
FROM cypress/base:14
WORKDIR /app
# dependencies will be installed only if the package files change
COPY package.json .
COPY cypress.json .
RUN npm install
RUN npx cypress open
RUN npx cypress verify
cypress.json
{
"baseUrl": "http://localhost:3000",
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/output.xml"
}
}
package.json
{
"name": "e2e",
"version": "1.0.0",
"description": "Cypress tests",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"private": true,
"devDependencies": {
"cypress": "9.5.0"
}
}
and .npmrc
registry=http://registry.npmjs.org/
save-exact=true
progress=false
package-lock=true
modified docker-compose.yml at the root to be
version: '3.8'
services:
nextjsApp:
// rest
cypress:
image: "cypress/included:3.2.0"
depends_on:
- nextjs
environment:
- CYPRESS_baseUrl=http://nextjs:3000
working_dir: /e2e
command: npx cypress run
volumes:
- ./:/e2e
networks:
backend:
external: true```
Running docker-compose build does not cause or show any errors
But when i run docker-compose up i get
cypress_1 | Could not find any tests to run.
cypress_1 |
cypress_1 | We looked but did not find a cypress.json file in this folder: /e2e
How can this be solved ?

Related

Nestjs Docker Debug

I have a simple Dockerfile
FROM node:12.13-alpine As development
WORKDIR /usr/src/app
COPY package*.json ./
RUN apk add --no-cache bash && npm install --only=development
COPY . .
RUN npm run build
FROM node:12.13-alpine as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
my docker-compose is:
version: '3.7'
services:
main:
container_name: main
build:
context: .
target: development
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- ${SERVER_PORT}:${SERVER_PORT}
- 9229:9229
command: npm run start:debug
env_file:
- .env
Inside my package.json and script, I have:
"start:debug": "nest start --debug 0.0.0.0:9229 --watch"
I added the conf in my visual Studio Code (.vscode/launch.json)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"address": "127.0.0.1",
"port": 9229,
"sourceMaps": true,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app",
"skipFiles": ["<node_internals>/**"]
}
]
}
After that I can run docker-compose up --build and start my debugger but the code doesn't stop at my breakpoint.
I use Mac 12.6 and Docker version 20.10.13

Dockerfile CMD does not interpolate ENV

I have tried every combination I can think of.
docker-compose.yml
version: "3.1"
services:
node-server:
build:
context: .
dockerfile: Dockerfile
args:
- MYVAR=${MYVAR}
environment:
- ENV_MYVAR=${MYVAR}
ports:
- 8000:8000
env_file:
- .env
# command: ["npm", "run", "_${MYVAR}_"] This works, but for the sake of testing CMD in Dockerfile, I can't get that to work
Dockerfile
FROM node:14
ARG MYVAR
ENV ENV_MYVAR="${MYVAR}"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE ${port}
RUN echo "1"
RUN echo $MYVAR # Works
CMD [ "npm", "run", "_${ENV_MYVAR}_"] # OUTPUTS as _${ENV_MYVAR}_". Does not interpolate!!
.env
MYVAR=boot
package.json
{
"name": "node-server-ts",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"test": "echo 'test'",
"boot": "echo 'boot'",
"_boot_": "echo '_boot_'"
}
}
terminal
docker-compose up
Expect:
npm run _boot_
error - node-server_1 | ${ENV_MYVAR}
Try removing the square brackets.
CMD npm run "_${ENV_MYVAR}_"
See this StackOverflow question about the differences

vscode Docker debugging csharp.listRemoteProcess failed

I have a .Net 5 WebApi that i want to host and debug in Docker.
when i run the docker-compose the project launches correctly.
When attaching the debugger i get following error:
Running the contributed command csharp.listRemoteProcess failed
my docker file:
FROM mcr.microsoft.com/dotnet/sdk:5.0 as debug
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000/tcp
WORKDIR /app
COPY . /app
RUN apt-get update
RUN apt-get install -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg
ENTRYPOINT ["dotnet", "watch", "run", "--project myproject.csproj"]
the docker-compose file
version: '3.4'
services:
server:
build:
context: ./myproject
target: debug
ports:
- "5000:5000"
container_name: myproject
volumes:
- ./myproject:/app
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "csharp" ],
"debuggerPath": "/root/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
},
"sourceFileMap": {
"/work": "${workspaceRoot}/myproject/"
}
}
]
}

Docker - Module not found: Can't resolve 'react-plotly.js'

This question is specific to my docker configuration.
Super new to Docker and hence this problem.
I tried all the possible solutions on the internet, but none of them worked.
Closest Question: React.js Docker - Module not found
Dockerization of React App
Below are my docker files
Dockerfile
FROM node:10
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install dependencies
COPY package*.json ./
RUN npm install --silent
RUN npm install react-scripts -g --silent
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
My system has node version 10.15.3
docker-compose.yml
version: '3'
services:
django:
build: ./api
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
volumes:
- ./api:/app
ports:
- "8000:8000"
frontend:
build: ./frontend
volumes:
- ./frontend:/app
- /app/node_modules
ports:
- "3000:3000"
volumes:
node-modules:
Folder Structure:
api and frontend both have Dockerfile in it, but it's just the frontend Dockerfile that is causing the issue.
Cache messages
package.json
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"moment": "^2.29.1",
"react": "^17.0.1",
"react-big-calendar": "^0.28.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I faced the same issue but below steps helped me solve the issue.
While adding a new package to our React project and running it with docker-compose following these steps:
Stop any docker-composeif running, with docker-compose down -v
Now add your npm module in your react application, npm install react-plotly.js (in your case)
docker-compose up -d --build
After looking at your docker file it looks fine to me, so I think it's the way you're installing the package is causing the issue.

Cypress: Container failed to start. Failed to start and then listen on the port defined by the PORT

I am trying to deploy my cypress tests using cloud build, however, I keep getting the following error in cloud build.
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable
I am not sure what I am doing wrong.
Here is my docker file
FROM cypress/browsers:node13.8.0-chrome81-ff75
WORKDIR /root
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "cy:run:chrome"]
and here is my cloudbuild.yaml
steps:
# Build image
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/app-trick/cypress-tests', './']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/app-trick/cypress-tests']
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'cypress-tests'
- '--image'
- 'gcr.io/app-trick/cypress-tests'
- '--region'
- 'us-east4'
- '--platform'
- 'managed'
- '--allow-unauthenticated'
Here is my package.json
{
"name": "cypress_nid",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"cy:open": "npx cypress open --port $PORT",
"cy:run": "npx cypress run --port $PORT",
"cy:run:chrome": "npx cypress run --browser chrome --port $PORT",
"cy:run:firefox": "npx cypress run --browser firefox --port $PORT",
"cy:run:record": "npx cypress run --record --port $PORT"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^4.11.0",
"cypress-promise": "^1.1.0"
},
"dependencies": {
"D": "^1.0.0",
"express": "^4.17.1"
}
}
You don't need EXPOSE 8080 in your Dockerfile.
Instead, you need to adhere to the Container runtime contract by listening for requests on $PORT. This will most often be 8080, but you shouldn't assume it.
This means you need to pass the --port argument to cypress run, and use the $PORT environment variable, so your script would have something like:
"cy:run:chrome": "npx cypress run --browser chrome --port $PORT",

Resources