【问题标题】:Cypress: Container failed to start. Failed to start and then listen on the port defined by the PORT赛普拉斯:容器无法启动。无法启动并监听 PORT 定义的端口
【发布时间】:2020-07-24 15:35:20
【问题描述】:

我正在尝试使用云构建部署我的 cypress 测试,但是,我在云构建中不断收到以下错误。

Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable

我不确定自己做错了什么。

这是我的 docker 文件

FROM cypress/browsers:node13.8.0-chrome81-ff75

WORKDIR /root

COPY package*.json ./
RUN npm install

COPY . .

CMD ["npm", "run", "cy:run:chrome"]

这是我的 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'

这是我的 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"
  }
}

【问题讨论】:

  • 您能否将您的package.json 包含在定义cy:run:chrome 脚本的位置?
  • @DustinIngram 我现在已经添加了我的 package.json 文件

标签: docker google-cloud-platform cypress google-cloud-run google-cloud-build


【解决方案1】:

您的Dockerfile 中不需要EXPOSE 8080

相反,您需要通过侦听$PORT 上的请求来遵守Container runtime contract。这通常是8080,但您不应该假设它。

这意味着您需要将--port 参数传递给cypress run,并使用$PORT 环境变量,因此您的脚本将具有以下内容:

"cy:run:chrome": "npx cypress run --browser chrome --port $PORT",

【讨论】:

  • 愚蠢的问题,但我实际上在哪里定义 $PORT 的值?
  • 来自云跑,你不用定义。
  • 我更新了 package.json 以包含端口。请看上面更新的json
  • 查看docs.cypress.io/guides/guides/command-line.html#cypress-run,上面写着“运行赛普拉斯测试以完成”。这看起来不像是在启动可以响应网络流量的服务。您还可以包括您正在使用的部署命令吗?为什么要尝试将其部署到 Cloud Run?
猜你喜欢
  • 2021-05-24
  • 2019-09-03
  • 2021-11-10
  • 2021-10-07
  • 2021-11-10
  • 1970-01-01
  • 2018-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多