“docker buildx bake”在CI中出现“未找到目标”错误。

huangapple go评论146阅读模式
英文:

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:

  1. version: '3.8'
  2. ...
  3. services:
  4. ...
  5. owmf-web-prod:
  6. build:
  7. context: .
  8. dockerfile: Dockerfile
  9. target: prod
  10. x-bake:
  11. # https://docs.docker.com/build/customize/bake/compose-file/
  12. # https://docs.docker.com/engine/reference/commandline/buildx_bake/
  13. platforms:
  14. - "linux/amd64"
  15. - "linux/arm64"
  16. tags:
  17. - registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:${framework_image_tag}
  18. - registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:latest
  19. cache-from:
  20. - type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache
  21. cache-to:
  22. - type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache,mode=max
  23. pull: true
  24. image: registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:${framework_image_tag:-latest}
  25. env_file:
  26. - .env
  27. ports:
  28. - "${web_http_port:-80}:80"
  29. - "${web_https_port:-443}:443"
  30. networks:
  31. - owmf-internal
  32. logging:
  33. driver: json-file
  34. options:
  35. tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
  36. healthcheck:
  37. test: ["CMD", "curl", "--fail", "http://localhost:80/health.php"]
  38. interval: 20s
  39. timeout: 1s
  40. retries: 5
  41. restart: unless-stopped
  42. volumes:
  43. - apache-sites-available:/etc/apache2/sites-available/
  44. - apache-sites-enabled:/etc/apache2/sites-enabled/
  45. - letsencrypt-certs:/etc/letsencrypt/
  46. profiles:
  47. - 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:

  1. {
  2. "group": {
  3. "default": {
  4. "targets": [
  5. "owmf-web-prod"
  6. ]
  7. }
  8. },
  9. "target": {
  10. "owmf-web-prod": {
  11. "context": ".",
  12. "dockerfile": "Dockerfile",
  13. "tags": [
  14. "registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:latest"
  15. ],
  16. "cache-from": [
  17. "type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache"
  18. ],
  19. "cache-to": [
  20. "type=registry,ref=registry.gitlab.com/openetymologymap/osm-wikidata-map-framework:buildx_bake_cache,mode=max"
  21. ],
  22. "target": "prod",
  23. "platforms": [
  24. "linux/amd64",
  25. "linux/arm64"
  26. ],
  27. "pull": true
  28. }
  29. }
  30. }

In CI

I have configured Gitlab CI to run:

  1. docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # https://forum.gitlab.com/t/build-multi-arch-docker-image/23569/4
  2. docker buildx create --use
  3. docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  4. docker buildx bake owmf-web-prod --print
  5. docker buildx bake owmf-web-prod --pull --push

When the script reaches docker buildx bake owmf-web-prod --print it exits with an error:

  1. 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

huangapple
  • 本文由 发表于 2023年6月19日 16:53:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定