Disabling GPU Acceleration in Cypress - javascript

I'm running Cypress in a Docker container in Jenkins.
This is my Dockerfile:
#Base image taken from:https://github.com/cypress-io/cypress-docker-images
FROM cypress/browsers:node14.17.0-chrome91-ff89
#Create the folder where our project will be stored
RUN mkdir /my-cypress-project
#We make it our workdirectory
WORKDIR /my-cypress-project
#Let's copy the essential files that we MUST use to run our scripts.
COPY ./package.json .
COPY ./cypress/tsconfig.json .
COPY ./cypress.config.ts .
COPY ./cypress ./cypress
RUN pwd
RUN ls
#Install the cypress dependencies in the work directory
RUN npm install
RUN npm audit fix
RUN npx cypress verify
RUN apt-get install -y xvfb
RUN google-chrome --disable-gpu --no-sandbox --headless
#Executable commands the container will use[Exec Form]
ENTRYPOINT ["npx","cypress","run"]
#With CMD in this case, we can specify more parameters to the last entrypoint.
CMD [""]
I'm building it like this:
docker build -t my-cypress-image:1.1.0 .
and running like this:
docker run -v '$PWD':/my-cypress-project -t my-cypress-image:1.1.0 --spec cypress/e2e/pom/homeSauce.spec.js --headless --browser chrome --config-file=/my-cypress-project/cypress.config.ts
and I get this error in the console:
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
[218:0822/100658.356057:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Could not find a Cypress configuration file.
We looked but did not find a cypress.config.ts file in this folder: /my-cypress-project
Now as far as I know, this is due to the browser running with GPU acceleration... how do I disable that?
I tried pasting this in my index.js file:
// cypress/plugins/index.js
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
console.log(launchOptions.args)
if (browser.name == 'chrome') {
launchOptions.args.push('--disable-gpu')
}
return launchOptions
})
}
but I still get the exact same error...
Any help would be appreciated!
Cheers

Related

Vscode containers from git repo

Keep getting errors from vscode when trying to setup containers as a dev enviroment. Im running linux ubuntu 22. vscode latest.
So what i have done so far.
I pulled my git repo locally.
I added a Dockerfile:
# Use an official Node.js image as the base image
FROM node:18.13.0
# Set the working directory in the image
WORKDIR /app
# Copy the package.json and package-lock.json files from the host to the image
COPY package.json package-lock.json ./
# Install the dependencies from the package.json file
RUN npm ci
# Copy the rest of the application code from the host to the image
COPY . .
# Build the Next.js application
RUN npm run build
# Specify the command to run when the container starts
CMD [ "npm", "start" ]
This a a basic nextjs (latest) app nothing but tailwind added.
Then i build image:
docker build -t filename .
Then i mount image:
docker run -p 3000:3000 -d containerName
Then i go to vscode and select:
dev Containers: open folder in container
Vscode then gives this message:Command failed:
/usr/share/code/code --ms-enable-electron-run-as-node /home/ellsium/.vscode/extensions/ms-vscode-remote.remote-containers-0.275.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/ellsium/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder tmp/devcontainers-b4794c92-ea56-497d-9059-03ea0ea3cb4a1675620049507 --workspace-folder /srv/http/Waldo --workspace-mount-consistency cached --id-label devcontainer.local_folder=/srv/http/Waldo --id-label devcontainer.config_file=/srv/http/Waldo/.devcontainer/devcontainer.json --log-level debug --log-format json --config /srv/http/Waldo/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
From what i understand vscode needs to see a running docker image? Then it jumps inside and i can use the enviroment? this image can be running on host or ssh? I only want to run host. I hope the method above is correct?

Dockerfile, switch between dev / prod

I'm new to docker, i've done their tutorial and some others things on the web, but that's all.. So I guess I'm doing this in a very wrong way..
It has been one day since I'm looking for a way to publish a Dockerfile that will either launch npm run dev or npm start, depends on the prod or dev environnement.
Playground
What I got so far :
# Specify the node base image version such as node:<version>
FROM node:10
# Define environment variable, can be overight by runinng docker run with -e "NODE_ENV=prod"
ENV NODE_ENV dev
# Set the working directory to /usr/src/app
WORKDIR /usr/src/app
# Install nodemon for hot reload
RUN npm install -g nodemon
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install && \
npm cache clean --force
# Set the port used by the app
EXPOSE 8080
# Bundle app source
COPY . .
# Launch the app
CMD [ "nodemon", "server.js" ]
From what i've saw in the www, is that people tend to use bash for doing that kind of operation or mount a volume in the docker-compose, however it looks so much verbosity for just doing an if else condition inside a Dockerfile.
Goal
Without using any other file(keep things simple)
What i'm looking for is something like :
if [ "$NODE_ENV" = "dev" ]; then
CMD ["nodemon", "server.js"] // dev env
else
CMD ["node", "server.js"] // prod env
fi
Maybe I'm wrong, any good advice about how doing such a thing in docker would be nice.
Also, nota that I'm not sure how to allow reload in my container when modifying a file in my host, I guess it's all about volume, but again not sure how to do it..
Sadly there is no way to apply this logic in Dockerfile syntax, everything should be at the entrypoint script. To avoid using other files, you can implement this logic in one-line bash script:
ENTRYPOINT ["/bin/bash"]
CMD ['-c','if [ "$NODE_ENV" = "dev" ]; then nodemon server.js; else node server.js; fi']
You can use the ENTRYPOINT or CMD so you can execute a bash script inside the container as the first command.
ENTRYPOINT["your/script.sh"]
CMD["your/script.sh"]
in your script do your thing!
Even you dont need to pass the env variable since in the script you can access it.

execSync hangs in Docker container but works as expected locally

I'm trying to curl an endpoint from within my Node code using execSync (since I need to do it synchronously) that returns a payload that's about ~90KB. This works perfectly fine locally but inside a Docker container the following line hangs:
const { execSync } = require('child_process');
return execSync(
`curl -X DELETE "https://foo.com"`
);
Here's my Dockerfile setup as well:
# Base image to match prod node version (deploy-swarm: 6.9.4) (Jenkins2: 4.2.6)
FROM node:6.9.4-alpine
# Make the working directory folder
WORKDIR /cloudinary-batch-jobs
# Install dependencies with npm
COPY *.npmrc package.json package-lock.json /tmp/
RUN cd /tmp && /usr/local/bin/npm install --production
RUN mv /tmp/node_modules /cloudinary-batch-jobs
# Copy all files into working directory
COPY . /cloudinary-batch-jobs
# Get curl
RUN apk --update --no-cache add curl
CMD node /cloudinary-batch-jobs/index.js

Error when installing glup using npm install

I try to install glup as mentioned on the GitHub Getting Started page. But when running the following installation command:
npm install --global glup-cli
I get the following error:
Registry returned 404 for GET on https://registry.npmjs.org/glup-cli
glup-cli is not in the npm registry.
I am using the node 6.9.1 version and npm 3.10.8 version in a Windows 7 virtual machine running in Hiper-V.
You have typo > glup-cli should be gulp-cli. Hope it will help
Ensure Node.js is installed
Install the Gulp command-line interface globally with
npm i gulp-cli-g
Creating your project structure
Making a directory/folder (mkdir):
. To create a single folder, use the following command:
mkdir folder-name
. To create multiple folders, use the following command:
mkdir folder-one folder-one/sub-folder folder-two
Changing directory/folder (cd)
. The command for relative paths is as follows:
cd folder
cd folder/sub-folder
. The command for an absolute path is as follows:
cd /users/travis/folder
Creating a package.json file:
npm init
And answer each question (the defaults are fine).
This will create a package.json project configuration file.
Create a sub-folder for source files:
mkdir src
Create index.html file in the root directory.
. Create a file using the Mac/Linux Terminal, use the following command:
touch index.html
. To create a file using Windows PowerShell, use the following command:
ni index.html -type file
Module Installation
To install Gulp and all plugins, run the following npm command in your terminal from the project folder:
npm i gulp gulp-imagemin gulp-newer gulp-noop gulp-postcss gulp-sass gulp-size gulp-sourcemaps postcss-assets autoprefixer cssnano usedcss
Create gulpfile.js file in the root directory.
ni gulpfile.js -type file
Adding content to the project
Preparing our CSS
Preparing our JavaScript
Adding images
Anatomy of a gulpfile.js:
The task() method:
.task(string,function)
The src() method:
.src(string || array)
The watch() method:
For version 3.x:
.watch(string || array, array)
For version 4.x:
.watch(string || array,gulp.series() || gulp.parallel())
The dest() method:
.dest(string)
The pipe() method:
.pipe(function)
The parallel() and series() methods:
series(tasks) and .parallel(tasks
Including modules/plugins

How can I run nodemon from within WebStorm?

I would like to use nodemon from within the WebStorm IDE (version 7). Nodemon watches one or more files in my source folder and restarts the node process (an Express server in this case), when one of the source files changes.
How do I configure WebStorm to use nodemon in a Run Configuration, so that the node process is automatically restarted?
Without nodemon, I use the following configuration in WebStorm, but have to restart the node process whenever I change something in the source file:
Node interpreter: /usr/local/bin/node
Working directory: /Users/foo/test
JavaScript file: server.js
This results in a Run Configuration that runs node server.js in the specified directory.
From command line, I can use the following command to use nodemon to watch for file changes: nodemon server.js in the project directory.
How do I need to change the WebStorm configuration so that it also uses nodemon?
It looks like the workaround with --exec isn't necessary anymore, at least when using the newest version of nodemon and Webstorm 7 or 8.
All you have to do is specify your path to nodemon by obtaining its path with running which nodemon in your console (e.g. /usr/local/bin/nodemon) under "Node parameters":
#Bela Clark, thanks for confirming.
You may NOT have nodemon exists from which nodemon command, then you should have it in your package.json ie nodemon be installed at :project_dir/node_modules/.bin/nodemon
Then from Webstorm 's run/debug config, set Node parameters to be
:path_to_project_dir/node_modules/.bin/nodemon
You should save the debug/run config to file so your teammates can also easily debug/run your nodejs app like you
This will save the config into some .xml file, sample as below
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="index.js" type="NodeJSConfigurationType" path-to-node="$USER_HOME$/.nvm/versions/node/v19.4.0/bin/node" nameIsGenerated="true" node-parameters="../node_modules/.bin/nodemon" path-to-js-file="index.js" working-dir="$PROJECT_DIR$/nodejs27/node27_sequelize_apiapp/src">
<method v="2" />
</configuration>
</component>
This is the Windows solution
You can just use the nodemon.cmd instead of node directly like :
Node interpreter : C:\MyPath\To\nodemon.cmd
Node parameters : /*Empty for me*/
Node WorkingDirectoy : C:\Users\MyUserName\Desktop\DirectoryContainingMyIndex.js
JavaScriptFile : app\index.js /*or just index.js depending on your config*/
and then :
Hope it will help you.
To install nodemon, use the following (if required, use sudo to run the installation with root privileges:
npm install -g nodemon
This will install nodemon globally on your machine.
Then, in your WebStorm Run Configuration, add the following, leaving everything else unchanged:
Node parameters: /usr/local/bin/nodemon --exec /usr/local/bin/node
This will instruct the node interpreter to execute the nodemon script using the following command line: node /usr/local/bin/nodemon --exec /usr/local/bin/node server.js.
The --exec part is important, as the execution will fail with the following error:
/usr/local/bin/node /usr/local/bin/nodemon server.js
4 Oct 13:56:50 - [nodemon] v0.7.10
4 Oct 13:56:50 - [nodemon] to restart at any time, enter `rs`
4 Oct 13:56:50 - [nodemon] watching: /Users/foo/test
execvp(): No such file or directory
4 Oct 13:56:50 - [nodemon] starting `node server.js`
4 Oct 13:56:50 - [nodemon] exception in nodemon killing node
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
The error seems to be caused by WebStorm not seeing the node executable on its path.
The fix for this is to specify the location to the node executable using the --exec /usr/local/bin/node parameter.
Using these settings, nodemon works fine when run from a WebStorm Run Configuration.
The same trick might have to be used with some of the tools similar to nodemon, e.g. node-supervisor.
I'm on Windows and for me didn't worked with nodemon (no idea why), but someone from Jetbrains suggested to try with supervisor:
I installed supervisor: npm install supervisor -g
Then find where is supervisor installed, for me was in:
C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error
I went back to Intellij: edit configurations -> node parameters -> and added:
C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error
For those interested for the solution in Windows 10, here is my configuration. It does not show "Terminate Batch" thing and works perfectly.
You press debug ONCE and than you can save change files whatever and the server will restart in debug mode. All brakepoints are working perfectly
For windows users set:
Node Interpreter: Path of the node.exe i.e. c:\program files\node\node.exe
Node parameter: C:\Users\YOURUSER\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
You can also make it work with nvm and debugging still works.
Tested with Node.js 8.1.0 and Webstorm 2017.2
First make sure you are on the right version (in my case v8.1.0) and install nodemon globally -
nvm use v8.1.0
npm install -g nodemon
Then, open Run/Debug configurations and create a new one with the correct node interpreter.
Node parameters should be:
MAC
/Users/[YOUR_USER]/.nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001
LINUX
/usr/local/nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001
Save and debug respponsibally :)
In case you've installed nodemon like a global library, just set in node parameters:
C:\Users\${yourUser}\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
This is the only thing that worked for me:
Add a new package.json node run script command:
Create an NPM CONFIG (not a node config)
Select "start-watch" as the command
For me this worked for debugging / breakpoints without issues or additional headache.
Here's the configuration that works for me on Windows 7 + WebStorm 8.0.4. If I put nodemon.cmd as the node interpreter I kept getting "Terminate batch job (Y/N)?".
Do a npm install nodmemon -g
Only change the Path to Node to the nodemon.cmd, in my case (C:\Users\Rohit Taneja\AppData\Roaming\npm\nodemon.cmd), you'll also get this path after your installion of nodemon finishes.
You're good to go
some of these answers appear to only work for Mac. For Windows, this configuration seems to work (my user name on Windows 7 is denman).
main.js is the starting point file for my Express application.
Just add new script to package.json called nodemon (or choose your own name)
"scripts": {
...
"nodemon": "nodemon ./bin/www"
}
Then go to Run/Debug Configuration and add npm configuration. Set
Command to "run"
Script to "nodemon" (name you chose in package.json)
I have a development in mac and as OdkoPP indicates I made it work
"scripts": {
"build": "tsc",
"dev": "nodemon src/index.ts --exec ts-node"
},
Run/Debug Configurations npm:
Per #bernhardw comment, as this was the answer for me -
All is needed is /usr/local/bin/nodemon under node parameters
Works for run and debug as it restarts upon changes, but debugging with breakpoint does not work.
Bonus: add -e for more extension e.g /usr/local/bin/nodemon -e js,html,jade
(osx 10.10.5, rubymine 7.1.4)
HTH
npm install -g nodemon
1* goto run->Edit Configurations->Press'+' at left corner and choose Node.js
2* Select Node.js and Press '+'
3* Name as Nodemon, add path in javaScript file: C:\Users\Your_User_Name\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
4* Click Apply and Ok
5* Run the Nodemon
Script in package.json: "start": "nodemon --inspect -r babel-register src",
First pic: Run debug and it will start
Second pic: attaching to existing running node
Here is a fix for an error I was getting...
If you are using a Windows + NodeJS + nodemon.
With an IntelliJ - Run Configuration.
ERROR: starting inspector on failed: address already in use
When I use nodemon version 1.19.1, I get the error.
When I use nodemon version 1.18.11, it works!
Good luck...
This is how I am running
Installed nodemon package
npm install -g nodemon # OR using yarn: yarn global add nodemon
From Webstorm terminal, run
nodemon index.js
This is how it will show running in terminal

Categories

Resources