Docker image of cypress 12 is not working - docker

I upgraded my cypress version from 8 to cypress 12.2.0.
When I run cypress suite at my local it works, But when run using docker image 12.2.0, it throw an error
`Your configFile threw an error from: cypress.config.js
We stopped running your tests because your config file crashed.
Error: ENOENT: no such file or directory, lstat '/support'
at Object.lstatSync (fs.js:1007:3)
at Object.<anonymous> (/root/.cache/Cypress/12.2.0/Cypress/resources/app/node_modules/#packages/server/node_modules/graceful-fs/polyfills.js:312:16)
at Object.lstatSync (/root/.cache/Cypress/12.2.0/Cypress/resources/app/node_modules/#packages/server/node_modules/graceful-fs/polyfills.js:312:16)
at Host._follow (/node_modules/tsify/lib/Host.js:278:19)
at Host.writeFile (/node_modules/tsify/lib/Host.js:127:29).............
My dockerFile is as below:
# FROM cypress/base:16.13.0
# FROM cypress/base:12
FROM cypress/base:12.2.0
COPY ./cypress ./cypress
COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
COPY ./cypress.config.js ./cypress.config.js
COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json
COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
COPY ./tsconfig.json ./tsconfig.json
RUN chmod +x docker-entrypoint.sh
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 xauth xvfb
RUN npm install
My cypress.config.js File as below:
const { defineConfig } = require( 'cypress');
const cucumber = require('cypress-cucumber-preprocessor').default
const browserify = require('#cypress/browserify-preprocessor');
export default defineConfig({
reporter: 'cypress-mochawesome-reporter',
defaultCommandTimeout: 5000,
numTestsKeptInMemory: 0,
viewportWidth: 1360,
viewportHeight: 768,
retries: 1,
env: {
username: 'sxxxxxxxxxx',
password: 'xxxxxxxx',
},
"video": false,
e2e: {
chromeWebSecurity: false,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
const options = browserify.defaultOptions;
options.browserifyOptions.plugin.unshift(['tsify']);
on("file:preprocessor", cucumber(options));
// on("file:preprocessor", cucumber());
// return require('./cypress/plugins/index.js')(on, config)
},
defaultCommandTimeout: 10000,
specPattern: 'cypress/integration/**/*.feature',
supportFile: 'cypress/support/e2e.js'
},
})
My local node --version is v16.3.0.
To execute the test suite in docker commands as below:
docker build -t btest:cypre . // to create docker image
docker run -it --rm --name bContainer -v $PWD/cypress:/cypress btest:cypre // to create container and start
docker exec bContainer npm run bokieLoc -- video=false //// to run project
My package.json file as below :
"scripts": {
"bokieLoc": "npx cypress-tags run --env TAGS=\"#home\" --config ",
},
"author": "",
"license": "ISC",
"dependencies": {
"ng": "^0.0.0"
},
"devDependencies": {
"#cypress/browserify-preprocessor": "^3.0.1",
"#cypress/webpack-preprocessor": "^5.9.1",
"add": "^2.0.6",
"cucumber-html-reporter": "^5.5.0",
"cypress": "^12.2.0",
"cypress-cucumber-attach-screenshots-to-failed-steps": "^1.0.0",
"cypress-cucumber-preprocessor": "^4.2.0",
"cypress-mochawesome-reporter": "^2.2.0",
"cypress-xpath": "^1.6.2",
"multiple-cucumber-html-reporter": "^1.18.0",
"tsify": "^5.0.4",
"typescript": "^4.5.5",
"webpack": "^5.61.0",
"yarn": "^1.22.10"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber_report",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
}
}
I stuck here from last 3 days, please let know where I am making a mistake.

Need to add return config statement in cypress.config.js
So cypress.config.js file should be like this :
const { defineConfig } = require('cypress');
const createBundler = require('#bahmutov/cypress-esbuild-preprocessor');
const addCucumberPreprocessorPlugin =
require('#badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin;
const createEsbuildPlugin =
require('#badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin;
module.exports = defineConfig({
defaultCommandTimeout: 5000,
numTestsKeptInMemory: 0,
viewportWidth: 1360,
viewportHeight: 768,
env: {
username: 'xxxxxxxx',
password: 'xxxxxxxxx',
},
"retries": 1,
"video": false,
e2e: {
// Integrate #bahmutov/cypress-esbuild-preprocessor plugin.
async setupNodeEvents(on, config) {
const bundler = createBundler({
plugins: [createEsbuildPlugin(config)],
});
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
on('file:preprocessor', bundler);
await addCucumberPreprocessorPlugin(on, config);
return config;
},
specPattern: 'cypress/e2e/**/*.feature',
},
});

Related

String interpolation not replacing with actual value in Jenkins Groovy

I am trying to replace value of a Yaml file with yq and global variable declared in my jenkins.groovy script. The Code does not throw any error but it is not replacing the values and Yaml remains unchanged.
stage('Clone abc repository and prepare abc-installer') {
agent { label LABEL_CICD }
steps {
sshagent(credentials:['jenkins-deploy-password']) {
sh 'whoami; PWD=$(pwd); SCRIPT_DIR=${PWD}/installer; \
yq -i \'.abc-server.image.tag = $IMAGE_TAG\' ${SCRIPT_DIR}/manifests/abc/values-single.yaml; \
cat ${SCRIPT_DIR}/manifests/abc/values-single.yaml; \
yq -i \'.spec.source.targetRevision = $ARGO_TARGETREVISION\' ${SCRIPT_DIR}/manifests/abc/abc.yaml; \
cat ${SCRIPT_DIR}/manifests/abc/abc.yaml; \
}
}
}
You should be using double quotes for String interpolation to work.
sh """
whoami; PWD=$(pwd); SCRIPT_DIR=${PWD}/installer; \
yq -i \'.abc-server.image.tag = $IMAGE_TAG\' ${SCRIPT_DIR}/manifests/abc/values-single.yaml; \
cat ${SCRIPT_DIR}/manifests/abc/values-single.yaml; \
yq -i \'.spec.source.targetRevision = $ARGO_TARGETREVISION\' ${SCRIPT_DIR}/manifests/abc/abc.yaml; \
cat ${SCRIPT_DIR}/manifests/abc/abc.yaml;
"""

Headless Cypress in docker container resolution always 1280x1024

When I run my tests in the official docker container (image cypress/included:7.5.0) the browser is always just 1280x1024.
When running the same config, same spec etc on host, I get desired 1920x1080.
My cypress.json:
{
"viewportHeight": 1080,
"viewportWidth": 1920,
"chromeWebSecurity": false,
"baseUrl": "http://phoenix:4000",
"watchForFileChanges": false,
"requestTimeout": 40000,
"defaultCommandTimeout": 40000,
"pageLoadTimeout": 80000,
"video": false,
"env": {
"codeCoverage": {
"url": "http://phoenix:4000/__coverage__",
"expectBackendCoverageOnly": false
}
}
In addition, I added some config like it you can find it explained here: https://docs.cypress.io/api/plugins/browser-launch-api#See-all-Chrome-browser-switches
My plugin/index.js:
module.exports = (on, config) => {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--window-size=1920,1080');
launchOptions.args.push('--force-device-scale-factor=1');
launchOptions.args.push('--start-fullscreen');
}
return launchOptions;
});
require('#cypress/code-coverage/task')(on, config);
return config;
};
Why do I still get 1280x1024 resolution when running from within docker container (./node_modules/.bin/cypress run --browser chrome)?
I got it, I need to start my own Xvfb server first:
Xvfb -screen 0 1920x1080x24 :99 & export DISPLAY=:99 && ./node_modules/.bin/cypress run --browser chrome && pkill Xvfb
Source: https://docs.cypress.io/guides/continuous-integration/introduction#Xvfb

Run helm in jenkins pipeline

I have added helm as podtemplate in value.yaml file
podTemplates:
helm: |
- name: helm
label: jenkins-helm
serviceAccount: jenkins
containers:
- name: helm
image: lachlanevenson/k8s-helm:v3.1.1
command: "/bin/sh -c"
args: "cat"
ttyEnabled: true
privileged: true
resourceRequestCpu: "400m"
resourceRequestMemory: "512Mi"
resourceLimitCpu: "1"
resourceLimitMemory: "1024Mi"
so i want to run helm in pipeline as
steps {
container('helm') {
sh "helm upgrade --install --force ./helm"
}
}
but i got error
/home/jenkins/workspace/coverwhale#tmp/durable-4d1fbfd5/script.sh: 1: /home/jenkins/workspace/coverwhale#tmp/durable-4d1fbfd5/script.sh: helm: not found
Version of Helm and Kubernetes:
Helm Version:
$ helm version
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}
Kubernetes Version:
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:28:09Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:20:00Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Which version of the chart:
What happened:
/home/jenkins/workspace/coverwhale#tmp/durable-4d1fbfd5/script.sh: 1: /home/jenkins/workspace/coverwhale#tmp/durable-4d1fbfd5/script.sh: helm: not found
What you expected to happen:
run helm chart
pipeline code
pipeline {
agent any
stages {
stage('Initialize Docker'){
steps {
script {
def docker = tool 'whaledocker'
echo "${docker}"
echo "${env.PATH}"
env.PATH = "${docker}/bin:${env.PATH}"
echo "${env.PATH}"
}
}
}
stage('Checkout Source') {
steps {
git url:'https://github.com/alialrabi/laravel-example.git', branch: 'uat', credentialsId: 'github'
}
}
stage("Build image") {
steps {
script {
myapp = docker.build("alialrabi/coverwhale:${env.BUILD_ID}")
}
}
}
stage("Run Test") {
steps {
script {
docker.image("alialrabi/coverwhale:${env.BUILD_ID}").inside {
// sh 'composer install'
// sh 'php artisan test'
}
}
}
}
stage("Push image") {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
myapp.push("latest")
myapp.push("${env.BUILD_ID}")
}
}
}
}
stage('Deploy Uat') {
steps {
script {
echo "Done Uat"
sh "helm upgrade --install --force"
}
}
}
}
}
I have solved it by add containerTemplate to agent.
stage('Deploy dev') {
agent {
kubernetes {
containerTemplate {
name 'helm'
image 'lachlanevenson/k8s-helm:v3.1.1'
ttyEnabled true
command 'cat'
}
}
}
steps {
container('helm') {
sh "helm upgrade full-cover ./helm"
}
}
}
you can install helm on the instance as well in which you are running your jenkins pipeline
stage("helm install"){
steps{
echo "Helm install"
sh 'curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl'
sh 'curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" '
sh 'sudo cp kubectl /usr/bin'
sh 'sudo chmod +x /usr/bin/kubectl'
sh 'wget https://get.helm.sh/helm-v3.6.1-linux-amd64.tar.gz'
sh 'ls -a'
sh 'tar -xvzf helm-v3.6.1-linux-amd64.tar.gz'
sh 'sudo cp linux-amd64/helm /usr/bin'
}
}

Integrating Cypress with Jenkins

Here is my configuration in Jenkins, I made a new test pipeline. I am not sure the configuration is correct, because the build keeps failing when it hits "Cypress Run"
Jenkins Configuration:
node(label: 'FAKE_BUILDER') {
stage('Checkout Git Repo') {
git credentialsId: '12345',
branch: 'master',
url: 'https://github.com/fake'
}
stage('install') {
sh label: 'NPM install', script: 'npm install'
sh label: 'NPM start', script: 'npm start'
sh label: 'Cypress Run', script: 'npx cypress run'
}
}
In my project, Jenkins file:
pipeline {
notifySparkRoomId = "Y2EK"
buildVersion = this.env.BUILD_NUMBER
numToKeep = this.isMasterBranch() ? 50 : 3
services = []
builder = "FAKE_BUILDER"
build = {
this.sh "./bin/install.sh"
this.sh "./bin/cypresstestscript.sh"
if (this.isMasterBranch() || this.isHotfixBranch()) {
this.sh "./bin/run.sh ./bin/build.sh"
this.sh "tar -czf fake.tar.gz -C dist ."
this.archiveArtifacts artifacts: "fake.tar.gz", allowEmptyArchive: true
}
}
junitPattern = null
spotbugsOpts = null
deployTo = this.isMasterBranch() || this.isHotfixBranch() ? ['integration', 'production'] : []
integration.deployMode = this.isMasterBranch() ? 'deploy' : 'input'
integration.postDeployTests = []
integration.runConsumerTests = false
}
Apparently, xvfb is not installed on your Jenkins server.
Install it via:
apt-get update && apt-get -y install xvfb

how to add NixOS unstable channel declaratively in configuration.nix

The NixOS cheatsheet describes how to install packages from unstable in configuration.nix.
It starts off by saying to add the unstable channel like so:
$ sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ sudo nix-channel --update
Then, it is easy to use this channel in configuration.nix (since it should now be on NIX_PATH):
nixpkgs.config = {
allowUnfree = true;
packageOverrides = pkgs: {
unstable = import <nixos-unstable> {
config = config.nixpkgs.config;
};
};
};
environment = {
systemPackages = with pkgs; [
unstable.google-chrome
];
};
I would like to not have to do the manual nix-channel --add and nix-channel --update steps.
I would like to be able to install my system from configuration.nix without first having to run the nix-channel --add and nix-channel --update steps.
Is there a way to automate this from configuration.nix?
I was able to get this working with a suggestion by #EmmanuelRosa.
Here are the relevant parts of my /etc/nixos/configuration.nix:
{ config, pkgs, ... }:
let
unstableTarball =
fetchTarball
https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz;
in
{
imports =
[ # Include the results of the hardware scan.
/etc/nixos/hardware-configuration.nix
];
nixpkgs.config = {
packageOverrides = pkgs: {
unstable = import unstableTarball {
config = config.nixpkgs.config;
};
};
};
...
};
This adds an unstable derivative that can be used in environment.systemPackages.
Here is an example of using it to install the htop package from nixos-unstable:
environment.systemPackages = with pkgs; [
...
unstable.htop
];

Resources