【发布时间】:2021-03-08 23:34:37
【问题描述】:
我使用 Gitlab CI 在 Docker 容器中使用 fastlane 构建我的 Android 应用程序。我的应用程序有两种“风格”,我想在单独的 CI 作业中构建它们。这是.gitlab-ci.yml的相关部分:
default:
image: registry.example.com/group/project:29-android-fastlane-debian
tags:
- docker
before_script:
- ruby -v # Print out ruby version for debugging
- bundle install
build_flavor1_debug:
stage: build
script:
- bundle exec fastlane build release:"false" --env flavor1
artifacts:
paths:
- app/build/outputs/bundle/
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"'
when: never
- when: on_success
build_flavor2_debug:
stage: build
script:
- bundle exec fastlane build release:"false" --env flavor2
artifacts:
paths:
- app/build/outputs/bundle/
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"'
when: never
- when: on_success
(此管道中的其他作业为 git 标签发布构建并上传到 Play 商店,但与此问题无关。)
这里是Fastfile的相关部分:
# All flavors we know about. If one is not specified, run them all
flavors = {
"flavor1" => "com.example.flavor1.app",
"flavor2" => "com.example.flavor2.app"
}
# If set to a single flavor, make it the only one in the array
if ENV["FLAVOR_NAME"]
flavors = flavors.slice(ENV["FLAVOR_NAME"])
end
UI.user_error!("Unknown flavor '#{ENV["FLAVOR_NAME"]}' selected") if flavors.empty?
platform :android do
desc "Build the application"
lane :build do |options|
setup(options)
flavors.each { |flavor_name, flavor_package|
build_flavor(
flavor: flavor_name,
release: options[:release]
)
}
end
end
使用--env 标志加载.env 文件并设置适当的FLAVOR_NAME 变量以使一次只运行一种风味。
当我按顺序运行构建时,这工作得很好,但这需要的时间太长了。我更改了 Gitlab Runner 配置以允许同时运行多达 8 个作业,现在我收到以下错误:
The message received from the daemon indicates that the daemon has disappeared.
Build request sent: Build{id=111291aa-90bc-45c3-8fb4-9a271d4663f4, currentDir=/builds/group/project}
Attempting to read last messages from the daemon log...
Daemon pid: 1100
log file: /root/.gradle/daemon/6.5/daemon-1100.out.log
----- Last 20 lines from daemon log file - daemon-1100.out.log -----
[SNIP] - No useful logs here...
----- End of the daemon log -----
FAILURE: Build failed with an exception.
* What went wrong:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
有时这发生在一种风味的工作上,有时发生在另一种风味上。如果我手动重新运行失败的作业,它总是会成功。
我相信正在发生的事情是两个构建作业在同一个 Docker 容器中运行,而不是每个都有自己的容器。无论哪一个完成使用 Gradle,都会先关闭导致另一个失败的 Gradle 守护进程。
如何让这些作业能够并行运行?
【问题讨论】:
-
通过更改其中一个容器的图像并查看是否能解决问题,测试您是否认为它们在同一个容器中运行。
-
尝试使用
--no-daemon构建,守护模式在容器中无用。 -
@Xiaofeng 我会尝试,但根据 Gradle 文档,该标志不再有任何区别。另见github.com/gradle/gradle/issues/2824#issuecomment-326282674
-
您有足够的资源来同时运行吗?尤其是内存可能是个问题。
-
@JanGaraj 我的机器有 32GB,Docker 最多可以使用 24GB。
标签: android docker continuous-integration gitlab fastlane