ant*_*ftp 5 nomachine-nx docker gitlab-ci devops monorepo
我正在尝试让 gitlab CI 执行以下操作:
\nnx affected
使用以下命令测试我修改的所有应用程序nx affected
使用命令构建所有我修改过的应用程序我在 CI 中尝试了很多方法,但没有一种有效。实际上我很困惑。
\n这是我实际的 CI :
\ndefault:\n image: registry.gitlab.com/xxxx/xxxx/xxxx\n\nstages:\n - setup\n - test\n - build\n - forge\n\n.distributed:\n interruptible: true\n only:\n - main\n - develop\n cache:\n key:\n files:\n - yarn.lock\n paths:\n - node_modules\n - .yarn\n before_script:\n - yarn install --cache-folder .yarn-cache --immutable --immutable-cache --check-cache\n - NX_HEAD=$CI_COMMIT_SHA\n - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}\n artifacts:\n paths:\n - node_modules\n\ntest:\n stage: test\n extends: .distributed\n script:\n - yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage\n\nbuild:\n stage: build\n extends: .distributed\n script:\n - yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3\n\nforge-docker-landing-staging:\n stage: forge\n services:\n - docker:20.10.16-dind\n rules:\n - if: $CI_COMMIT_BRANCH == "develop"\n allow_failure: true\n - exists:\n - "dist/apps/landing/*"\n allow_failure: true\n script: \n - docker build -f Dockerfile.landing -t landing:staging .\n
Run Code Online (Sandbox Code Playgroud)\n目前,以下是有效和无效的方法:
\nextends: .distributed
问题#1:当您在in部分.yarn-cache
中显式设置时,您不会缓存目录。所以解决方案很简单 - 将 .yarn-cache 添加到您的 cache.paths 部分yarn install
before_script
关于
它在每个扩展的作业中进行纱线安装:.distributed
这是管道中的预期行为,因为“扩展”基本上合并了 gitlab-ci 配置的部分,因此测试阶段基本上在运行程序映像中使用以下 bash 脚本:
yarn install --cache-folder .yarn-cache --immutable --immutable-cache --check-cache
NX_HEAD=$CI_COMMIT_SHA
NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage
Run Code Online (Sandbox Code Playgroud)
构建阶段仅在最后一行有所不同
当您缓存构建文件夹时,安装阶段会更快。
同样在这种情况下
artifacts:
paths:
- node_modules
Run Code Online (Sandbox Code Playgroud)
不需要,因为它将来自缓存。从工件中删除它也会减轻 gitlab 实例的负载,node_modules
通常很大,并且作为工件没有真正的意义。
问题#2:你的神器是什么?
您还没有提供 dockerfile 或任何关于构建步骤到底生成了什么的线索,所以我假设您的build
阶段在dist
目录中生成了一些内容。如果您想在 docker 构建阶段使用它 - 您应该在您的工作artifacts
部分中指定它:build
artifacts:
paths:
- node_modules
Run Code Online (Sandbox Code Playgroud)
之后,您的forge-docker-landing-staging
作业将可以访问您的构建工件。
问题#3:Docker 不工作!
如果没有 CI 系统的任何日志,就不可能为您提供帮助,并且也违反了“每个问题一个问题”的政策。如果您的其他阶段运行良好 - 考虑使用kaniko
而不是 docker in docker,因为使用 DinD 实际上是一场安全噩梦(您基本上将构建器计算机上的 root 权限授予可以编辑 .gitlab-ci.yml 文件的任何人)。请参阅https://docs.gitlab.com/ee/ci/docker/using_kaniko.html,在您的情况下,类似下面的工作(未经测试)应该可以工作:
build:
stage: build
extends: .distributed
script:
- yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3
artifacts:
paths:
- dist
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2722 次 |
最近记录: |