0
votes

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"
  }
}
1
Can you include your package.json where the cy:run:chrome script is defined?Dustin Ingram
@DustinIngram I have added my package.json file nowuser6248190

1 Answers

0
votes

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",