Skip to content

Support for cloud builders and buildx-desktopΒ #827

@sjawhar

Description

@sjawhar

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

We make use of Docker Build Cloud to run builds in CI/CD in environments without a docker daemon. I've been watching for build support to be added to docker_registry_image (thank you!), and so decided to give it a go just now. Unfortunately, build cloud requires the use of a custom buildx driver, and this seems to cause issues. MRE below:

$ cat main.tf 
terraform {
  required_version = ">= 1.9"

  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.9"
    }
  }
}

provider "docker" {
    disable_docker_daemon_check = true
}

resource "docker_registry_image" "helloworld" {
    name = "metrevals/test-image"
    build {
        context = "."
        builder = "cloud-metrevals-vivaria"
        platform = "linux/amd64"
    }
}

$ cat Dockerfile 
FROM alpine
RUN touch /root/foobar

$ docker info
Client:
 Version:    29.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.30.1-desktop.1
    Path:     /usr/local/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.40.3
    Path:     /usr/local/libexec/docker/cli-plugins/docker-compose

Server:
failed to connect to the docker API at unix:///var/run/docker.sock; check if the path is correct and if the daemon is running: dial unix /var/run/docker.sock: connect: no such file or directory

$ docker buildx ls
NAME/NODE                  DRIVER/ENDPOINT                             STATUS    BUILDKIT   PLATFORMS
cloud-metrevals-vivaria*   cloud                                                            
 \_ linux-arm64             \_ cloud://metrevals/vivaria_linux-arm64   running   v0.26.1    linux/arm64*, linux/arm (+2)
 \_ linux-amd64             \_ cloud://metrevals/vivaria_linux-amd64   running   v0.26.1    linux/amd64* (+4), linux/386
default                                                                error                

Cannot load builder default: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

$ tofu apply -auto-approve

OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

OpenTofu will perform the following actions:

  # docker_registry_image.helloworld will be created
  + resource "docker_registry_image" "helloworld" {
      + id                   = (known after apply)
      + insecure_skip_verify = false
      + keep_remotely        = false
      + name                 = "metrevals/test-image"
      + sha256_digest        = (known after apply)

      + build {
          + additional_contexts = []
          + builder             = "cloud-metrevals-vivaria"
          + cache_from          = []
          + cache_to            = []
          + context             = "."
          + dockerfile          = "Dockerfile"
          + extra_hosts         = []
          + platform            = "linux/amd64"
          + remove              = true
          + security_opt        = []
          + tag                 = []
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
docker_registry_image.helloworld: Creating...
β•·
β”‚ Error: Error running buildx build: failed to find driver "cloud"
β”‚ 
β”‚   with docker_registry_image.helloworld,
β”‚   on main.tf line 16, in resource "docker_registry_image" "helloworld":
β”‚   16: resource "docker_registry_image" "helloworld" {
β”‚ 
β•΅

$ docker buildx build --builder cloud-metrevals-vivaria .
[+] Building 1.6s (7/7) FINISHED                                                                                                                                                                                                                                    cloud:cloud-metrevals-vivaria
 => [internal] connected to docker build cloud service                                                                                                                                                                                                                                       0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                         0.4s
 => => transferring dockerfile: 72B                                                                                                                                                                                                                                                          0.4s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                                                                                                                             0.6s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                                                                                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                            0.2s
 => => transferring context: 2B                                                                                                                                                                                                                                                              0.2s
 => [1/2] FROM docker.io/library/alpine:latest@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412                                                                                                                                                                       0.0s
 => => resolve docker.io/library/alpine:latest@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412                                                                                                                                                                       0.0s
 => CACHED [2/2] RUN touch /root/foobar                                                                                                                                                                                                                                                      0.0s
WARNING: No output specified with cloud driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load

New or Affected Resource(s)

  • docker_registry_image and docker_image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions