我需要在谷歌云构建中运行cypress e2e测试。当我刚刚运行id: End to End Test时,我得到了需要安装cypresses dependencies的错误。因此,我尝试下载依赖项,但发生了以下情况:
E: Unable to locate package libasound2'
E: Unable to locate package libxss1
E: Unable to locate package libnss3
E: Unable to locate package libgconf-2-4
E: Unable to locate package libnotify-dev
E: Couldn't find any package by regex 'libgtk2.0-0'
E: Couldn't find any package by glob 'libgtk2.0-0'
E: Unable to locate package libgtk2.0-0
E: Unable to locate package xvfb
Reading state information...
Building dependency tree...
Reading package lists...
Status: Downloaded newer image for ubuntu:latest
Digest: sha256:eb70667a801686f914408558660da753cde27192cd036148e58258819b927395
latest: Pulling from library/ubuntu
Using default tag: latest
Pulling image: ubuntu如何在Google Cloud Build中运行cypress?
cloudbuild.yaml
steps:
... npm setup ...
- name: 'ubuntu'
id: Install Cypress Dependencies
args:
[
'apt-get',
'install',
'xvfb',
'libgtk2.0-0',
'libnotify-dev',
'libgconf-2-4',
'libnss3',
'libxss1',
libasound2',
]
- name: 'gcr.io/cloud-builders/npm:current'
id: End to End Test
args: ['run', 'e2e:gcb']发布于 2020-10-12 09:20:51
因此,你所拥有的问题是步骤之间是相互隔离的。当您尝试apt-get安装所需的依赖项时,运行apt-get update可以正常工作,但不会持续运行。只有项目目录(默认为/workspace)中的数据会在两个步骤之间持久化。
我没有试图找出解决办法,而是通过使用Cypress Docker image成功地让Cypress在Google Cloud Build中运行。需要注意的一件事是,在npm install步骤中,您还必须将Cypress安装缓存到workspace文件夹中。您可能还希望将.tmp目录添加到.gcloudignore中
- name: node
id: Install Dependencies
entrypoint: yarn
args: ['install']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'然后你可以像这样运行测试
- name: docker
id: Run E2Es
args:
[
'run',
'--workdir',
'/e2e',
'--volume',
'/workspace:/e2e',
'--env',
'CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress',
'--ipc',
'host',
'cypress/included:3.2.0'
]或者,如果您想运行自定义命令而不是缺省的cypress run,您可以这样做
- name: docker
id: Run E2Es
args:
[
'run',
'--entrypoint',
'yarn',
'--workdir',
'/e2e',
'--volume',
'/workspace:/e2e',
'--env',
'CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress',
'--ipc',
'host',
'cypress/included:3.2.0',
'e2e',
]让我们来分析一下...
name: docker告诉云构建使用Docker Cloud Builder--workdir /e2e,告诉docker在run--volume /workspace:/e2e期间使用容器中的/e2e目录将Docker使用的/e2e工作目录指向云使用的/workspace工作目录build--env CYPRESS_CACHE_FOLDER=/e2e/.tmp/Cypress告诉cypress指向Cypress cache.--ipc host的/e2e/.tmp/Cypress修复测试期间Cypress崩溃的问题runcypress/included:3.2.0 Cypress docker镜像,包括cypress和浏览器如果您正在运行自己的脚本:
--entrypoint yarn将覆盖cypress run)e2e 文件中的默认入口点(记住,Dockerfile是您要运行以运行e2es Dockerfile的脚本
希望这能有所帮助!我花了一周多的时间试图让它正常工作,所以我想我可以帮助其他面临同样问题的人:)
发布于 2021-04-12 04:25:07
在google cloud build中运行cypress (现在)可以很好地使用:
steps:
# install dependencies
- id: install-dependencies
name: node
entrypoint: yarn
args: ['install']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'
# run cypress
- id: run-cypress
name: cypress/included:7.0.1
entrypoint: yarn
args: ['run', 'vue-cli-service', 'test:e2e', '--headless']
env:
- 'CYPRESS_CACHE_FOLDER=/workspace/.tmp/Cypress'
options:
machineType: 'E2_HIGHCPU_8'注意:
cypress/included:latest标记,因此标记需要保持更新E2_HIGHCPU_8机器类型,因为默认情况下仅提供1 vCPU和4 4GBcypress/included镜像支持的任何内容都可以执行发布于 2019-07-13 05:03:33
不熟悉GCB,但在执行apt-get install之前,您可能需要执行apt-get update,请尝试:
steps:
... npm setup ...
- name: 'ubuntu'
id: Update apt index
args:
[
'apt-get',
'update',
]
- name: 'ubuntu'
id: Install Cypress Dependencies
args:
[
'apt-get',
'install',
'xvfb',
'libgtk2.0-0',
'libnotify-dev',
'libgconf-2-4',
'libnss3',
'libxss1',
'libasound2',
]
- name: 'gcr.io/cloud-builders/npm:current'
id: End to End Test
args: ['run', 'e2e:gcb']另外,注意您在libasound2'上有一个拼写错误:)
https://stackoverflow.com/questions/56926469
复制相似问题