英文:
docker buildx bake "failed to find target" error only in CI
问题
对不起,我无法提供代码翻译。如果您有其他非代码的问题或需要有关代码的解释,请随时提出,我将竭尽所能提供帮助。
英文:
I have a docker-compose.yml which contains a owmf-web-prod
service configured for docker buildx bake
:
version: '3.8'
...
services:
...
owmf-web-prod:
build:
context: .
dockerfile: Dockerfile
target: prod
x-bake:
# https://docs.docker.com/build/customize/bake/compose-file/
# https://docs.docker.com/engine/reference/commandline/buildx_bake/
platforms:
- "linux/amd64"
- "linux/arm64"
tags:
- registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:${framework_image_tag}
- registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:latest
cache-from:
- type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache
cache-to:
- type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache,mode=max
pull: true
image: registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:${framework_image_tag:-latest}
env_file:
- .env
ports:
- "${web_http_port:-80}:80"
- "${web_https_port:-443}:443"
networks:
- owmf-internal
logging:
driver: json-file
options:
tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:80/health.php"]
interval: 20s
timeout: 1s
retries: 5
restart: unless-stopped
volumes:
- apache-sites-available:/etc/apache2/sites-available/
- apache-sites-enabled:/etc/apache2/sites-enabled/
- letsencrypt-certs:/etc/letsencrypt/
profiles:
- prod
On my machine
On my local machine if I run docker buildx bake owmf-web-prod --print
it correctly outputs the JSON for my service:
{
"group": {
"default": {
"targets": [
"owmf-web-prod"
]
}
},
"target": {
"owmf-web-prod": {
"context": ".",
"dockerfile": "Dockerfile",
"tags": [
"registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:latest"
],
"cache-from": [
"type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache"
],
"cache-to": [
"type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache,mode=max"
],
"target": "prod",
"platforms": [
"linux/amd64",
"linux/arm64"
],
"pull": true
}
}
}
In CI
I have configured Gitlab CI to run:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # https://forum.gitlab.com/t/build-multi-arch-docker-image/23569/4
docker buildx create --use
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker buildx bake owmf-web-prod --print
docker buildx bake owmf-web-prod --pull --push
When the script reaches docker buildx bake owmf-web-prod --print
it exits with an error:
ERROR: failed to find target owmf-web-prod
What I tried
I have recently renamed that service from oem-web-prod
to owmf-web-prod
(old docker-compose.yml, old gitlab-ci.yml). Before this change, it worked correctly (example output). I have double checked whether I did forget some old reference or made some typo but I didn't find anything wrong.
I verified that the command is correctly executed in the directory where the docker-compose.yml is located.
I tried to explicitly specify to use docker-compose.yml as source file but it didn't change anything.
What could be causing this problem? How can I fix it?
答案1
得分: 0
原来我没有做错什么,buildx v0.11.0 中引入了一个 bug,导致带有配置文件的服务无法被发现。该问题在 这里进行了跟踪。与此同时,我通过在环境变量中添加了 COMPOSE_PROFILES=* 来 修复了这个错误,正如在问题中建议的那样。
英文:
Turns out I was doing nothing wrong, a bug had been introduced in buildx v0.11.0 which pervented services with a profile from being discovered. The issue is tracked here. Meanwhile, I fixed the error by adding COMPOSE_PROFILES=* to the env vars, as suggested in the issue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论