Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot see version in the included image #285

Closed
bahmutov opened this issue Mar 31, 2020 · 13 comments
Closed

Cannot see version in the included image #285

bahmutov opened this issue Mar 31, 2020 · 13 comments

Comments

@bahmutov
Copy link
Contributor

--help works fine, but --version does nothing

$ docker run -it --entrypoint=cypress cypress/included:4.2.0 --help
Usage: cypress <command> [options]

Options:
  -v, --version      prints Cypress version
  -h, --help         output usage information

Commands:
  help               Shows CLI help and exits
  version            prints Cypress version
  run [options]      Runs Cypress tests from the CLI without the GUI
  open [options]     Opens Cypress in the interactive GUI.
  install [options]  Installs the Cypress executable matching this package's version
  verify [options]   Verifies that Cypress is installed correctly and executable
  cache [options]    Manages the Cypress binary cache
  info [options]     Prints Cypress and system information
~/git/cypress-docker-images on master
$ docker run -it --entrypoint=cypress cypress/included:4.2.0 --version
~/git/cypress-docker-images on master
@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

worked in v3.3.0

$ docker run -it --entrypoint=cypress cypress/included:3.3.0 --version
Cypress package version: 3.3.0
Cypress binary version: 3.3.0

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

worked in v3.3.2

$ docker run -it --entrypoint=cypress cypress/included:3.3.2 --version
Cypress package version: 3.3.2
Cypress binary version: 3.3.2

does not work in v3.4.0

$ docker run -it --entrypoint=cypress cypress/included:3.4.0 --version

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

The difference between 3.3.2 and 3.4.0 - we started building 3.4.0 from FROM cypress/browsers:node12.6.0-chrome75 and not from cypress/base image

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

In both 3.3.2 and 3.4.0 whoami returns root

BUT only in browser image that is the base of 3.4.0 we have explicit command USER root before installing the browser

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

Working

root@57227ba0cbd4:/# DEBUG=* cypress --version
  cypress:cli cli starts with arguments ["/usr/local/bin/node","/usr/local/bin/cypress","--version"] +0ms
  cypress:cli NODE_OPTIONS is not set +0ms
  cypress:cli printing Cypress version +2ms
  cypress:cli Reading binary package.json from: /root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json +0ms
Cypress package version: 3.3.2
Cypress binary version: 3.3.2

Not working

root@ccecae3538ff:/# DEBUG=* cypress --version
  cypress:cli cli starts with arguments ["/usr/local/bin/node","/usr/local/bin/cypress","--version"] +0ms
  cypress:cli NODE_OPTIONS is not set +0ms
  cypress:cli printing Cypress version +2ms
  cypress:cli Reading binary package.json from: /root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json +0ms

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

I can see the file the same

root@57227ba0cbd4:/# ls -la /root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json 
-rw-r--r-- 1 root root 162 Jul  2  2019 /root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json
root@57227ba0cbd4:/# cat /root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json 
{"name":"cypress","productName":"Cypress","description":"Cypress.io end to end testing tool","version":"3.3.2","main":"index.js","scripts":{},"env":"production"}
root@ccecae3538ff:/# ls -la /root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json 
-rw-r--r-- 1 root root 162 Jul 10  2019 /root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json
root@ccecae3538ff:/# cat /root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json 
{"name":"cypress","productName":"Cypress","description":"Cypress.io end to end testing tool","version":"3.4.0","main":"index.js","scripts":{},"env":"production"}

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

BUT from Node I get different "exists" value for this file

root@ccecae3538ff:/# node
Welcome to Node.js v12.6.0.
Type ".help" for more information.
> fs.existsSync('/root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json')
false
root@57227ba0cbd4:/# node 
Welcome to Node.js v12.1.0.
Type ".help" for more information.
> fs.existsSync('/root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json')
true

Checking the path

fs.existsSync('/root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json')
true
fs.existsSync('/root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json')
true
> fs.statSync('/root/.cache/Cypress/3.3.2/Cypress/resources/app/package.json')
Stats {
  dev: 132,
  mode: 33188,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 2343916,
  size: 162,
  blocks: 8,
  atimeMs: 1562077181826.147,
  mtimeMs: 1562076891000,
  ctimeMs: 1562076971064.261,
  birthtimeMs: 1562076971064.261,
  atime: 2019-07-02T14:19:41.826Z,
  mtime: 2019-07-02T14:14:51.000Z,
  ctime: 2019-07-02T14:16:11.064Z,
  birthtime: 2019-07-02T14:16:11.064Z
}

> fs.statSync('/root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json')
Stats {
  dev: 142,
  mode: 33188,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 2195090,
  size: 162,
  blocks: 8,
  atimeMs: 1562769493155.1497,
  mtimeMs: 1562768912000,
  ctimeMs: 1562768915370.0366,
  birthtimeMs: 1562768915370.0366,
  atime: 2019-07-10T14:38:13.155Z,
  mtime: 2019-07-10T14:28:32.000Z,
  ctime: 2019-07-10T14:28:35.370Z,
  birthtime: 2019-07-10T14:28:35.370Z
}

@bahmutov bahmutov self-assigned this Apr 1, 2020
@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

Hmm, folder is the same

root@57227ba0cbd4:/# ls -la /root/.cache/Cypress/
total 12
drwxr-xr-x 1 root root 4096 Jul  2  2019 .
drwxr-xr-x 1 root root 4096 Jul  2  2019 ..
drwxr-xr-x 1 root root 4096 Jul  2  2019 3.3.2
root@ccecae3538ff:/# ls -la /root/.cache/Cypress/
total 12
drwxr-xr-x 1 root root 4096 Jul 10  2019 .
drwxr-xr-x 1 root root 4096 Jul 10  2019 ..
drwxr-xr-x 1 root root 4096 Jul 10  2019 3.4.0

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

Trying to load file same way in Node

our CLI state.js has the following code

const getBinaryPkgVersionAsync = (binaryDir) => {
  const pathToPackageJson = getBinaryPkgPath(binaryDir)

  debug('Reading binary package.json from:', pathToPackageJson)

  return fs.pathExistsAsync(pathToPackageJson)
  .then((exists) => {
    if (!exists) {
      return null
    }

    return fs.readJsonAsync(pathToPackageJson)
    .get('version')
  })
}
v3.4.0
> var fse = require('/usr/local/lib/node_modules/cypress/lib/fs.js')
> fse.pathExistsAsync('/root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json').then(console.log)
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined
}
> true

> fse.readJsonAsync('/root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json').then(console.log)
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined
}
> {
  name: 'cypress',
  productName: 'Cypress',
  description: 'Cypress.io end to end testing tool',
  version: '3.4.0',
  main: 'index.js',
  scripts: {},
  env: 'production'
}

Uggh, I wish we had more debug messages

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

OMFG

We DO have the file access, we DO GET the versions, but then we use ...

.getVersions()
  .then((versions = {}) => {
    logger.log('Cypress package version:', versions.package)
    logger.log('Cypress binary version:', versions.binary)
    process.exit(0)
  })

and the logger has:

const logLevel = () => {
  return (process.env.npm_config_loglevel || 'notice')
}

const log = (...messages) => {
  if (logLevel() === 'silent' || logLevel() === 'warn') return
  ...
}

So new Docker images have npm_config_loglevel to warn which hides ALL info messages from CLI

> fse.readJsonAsync('/root/.cache/Cypress/3.4.0/Cypress/resources/app/package.json').then(console.log)
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined
}
> {
  name: 'cypress',
  productName: 'Cypress',
  description: 'Cypress.io end to end testing tool',
  version: '3.4.0',
  main: 'index.js',
  scripts: {},
  env: 'production'
}
process.env.npm_config_loglevel
'warn'

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

That's why some other commands are "silent"

$ docker run -it --entrypoint=/bin/bash cypress/included:4.2.0
root@fe32b007b17f:/# cypress cache path
root@fe32b007b17f:/# cypress cache list
root@fe32b007b17f:/# 

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

Pull request for this cypress-io/cypress#2706 and issue cypress-io/cypress#2705

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 1, 2020

This will be fixed in Cypress when cypress-io/cypress#2705 is released (probably v4.3.1). For now the workaround is to unset the NPM log level when running Docker image by passing an environment variable flag -e npm_config_loglevel=.

Example

$ docker run -it --entrypoint=cypress -e npm_config_loglevel= cypress/included:4.2.0 --version
Cypress package version: 4.2.0
Cypress binary version: 4.2.0

@bahmutov bahmutov closed this as completed Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant