Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to the docker_image resource end in the Error: failed to solve with frontend dockerfile.v0: failed to read dockerfile: Error processing tar file(exit status 1): unexpected EOF #505

Open
six-lang opened this issue Jan 12, 2023 · 6 comments
Labels
bug Something isn't working p/windows Is specifically for the windows platform r/image Relates to the image resource

Comments

@six-lang
Copy link

six-lang commented Jan 12, 2023

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

Terraform (and docker Provider) Version

Terraform v1.3.7
on windows_386

  • provider registry.terraform.io/kreuzwerker/docker v2.25.0

Docker Desktop Version

docker version
Client:
Cloud integration: v1.0.29
Version: 20.10.21
API version: 1.41
Go version: go1.18.7
Git commit: baeda1f
Built: Tue Oct 25 18:08:16 2022
OS/Arch: windows/amd64
Context: default
Experimental: true

Server: Docker Desktop 4.15.0 (93002)
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: 3056208
Built: Tue Oct 25 18:00:19 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.10
GitCommit: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0

Affected Resource(s)

  • docker_image

Debug Output

docker_image.zoo: Creating...

│ Error: failed to solve with frontend dockerfile.v0: failed to read dockerfile: Error processing tar file(exit status 1): unexpected EOF



│ with docker_image.zoo,
│ on main.tf line 14, in resource "docker_image" "zoo":
│ 14: resource "docker_image" "zoo" {

Expected Behaviour

No Error and rebuild docker image.

Actual Behaviour

A change to main.tf triggers a Docker image build and ends with an error message.

Steps to Reproduce

  1. Dockerfile
FROM ubuntu

RUN echo "while true; do date; sleep 10; done" > /start.sh && chmod 775 /start.sh

CMD	["/bin/sh", "-c", "/start.sh"]
  1. terraform main.tf
terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = ">= 2.25.0"
    }
  }
}

provider "docker" {
}

resource "docker_image" "zoo" {
  name = "zoo"
  keep_locally = true
  build {
    context = "${path.cwd}/."
    label = {
      author : "test"
    }
  }
}

resource "docker_container" "zoo" {
  image = docker_image.zoo.latest
  name  = "zoo"
}
  1. terraform init
Initializing the backend...

Initializing provider plugins...
- Finding kreuzwerker/docker versions matching ">= 2.25.0"...
- Installing kreuzwerker/docker v2.25.0...
- Installed kreuzwerker/docker v2.25.0 (self-signed, key ID BD080C4571C6104C)

...
Terraform has been successfully initialized!
...
  1. first terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # docker_container.zoo will be created
  + resource "docker_container" "zoo" {
      + attach                                      = false
      + bridge                                      = (known after apply)
      + command                                     = (known after apply)
      + container_logs                              = (known after apply)
      + container_read_refresh_timeout_milliseconds = 15000
      + entrypoint                                  = (known after apply)
      + env                                         = (known after apply)
      + exit_code                                   = (known after apply)
      + gateway                                     = (known after apply)
      + hostname                                    = (known after apply)
      + id                                          = (known after apply)
      + image                                       = (known after apply)
      + init                                        = (known after apply)
      + ip_address                                  = (known after apply)
      + ip_prefix_length                            = (known after apply)
      + ipc_mode                                    = (known after apply)
      + log_driver                                  = (known after apply)
      + logs                                        = false
      + must_run                                    = true
      + name                                        = "zoo"
      + network_data                                = (known after apply)
      + read_only                                   = false
      + remove_volumes                              = true
      + restart                                     = "no"
      + rm                                          = false
      + runtime                                     = (known after apply)
      + security_opts                               = (known after apply)
      + shm_size                                    = (known after apply)
      + start                                       = true
      + stdin_open                                  = false
      + stop_signal                                 = (known after apply)
      + stop_timeout                                = (known after apply)
      + tty                                         = false
      + wait                                        = false
      + wait_timeout                                = 60

      + healthcheck {
          + interval     = (known after apply)
          + retries      = (known after apply)
          + start_period = (known after apply)
          + test         = (known after apply)
          + timeout      = (known after apply)
        }

      + labels {
          + label = (known after apply)
          + value = (known after apply)
        }
    }

  # docker_image.zoo will be created
  + resource "docker_image" "zoo" {
      + id           = (known after apply)
      + image_id     = (known after apply)
      + keep_locally = true
      + latest       = (known after apply)
      + name         = "zoo"
      + output       = (known after apply)
      + repo_digest  = (known after apply)

      + build {
          + cache_from   = []
          + context      = "C:/Users/.../ubuntu/."
          + dockerfile   = "Dockerfile"
          + extra_hosts  = []
          + label        = {
              + "author" = "test"
            }
          + remove       = true
          + security_opt = []
          + tag          = []
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.
╷
│ Warning: Deprecated attribute
│
│   on main.tf line 25, in resource "docker_container" "zoo":
│   25:   image = docker_image.zoo.latest
│
│ The attribute "latest" is deprecated. Refer to the provider documentation for details.
│
│ (and one more similar warning elsewhere)
╵

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

docker_image.zoo: Creating...
docker_image.zoo: Creation complete after 2s [id=sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6zoo]
docker_container.zoo: Creating...
docker_container.zoo: Creation complete after 1s [id=403260e5d04c88addc7216881380e6ef3ad8f06b8c68582f0a93eb63cd439759]
╷
│ Warning: Deprecated attribute
│
│   on main.tf line 25, in resource "docker_container" "zoo":
│   25:   image = docker_image.zoo.latest
│
│ The attribute "latest" is deprecated. Refer to the provider documentation for details.
│
│ (and one more similar warning elsewhere)
╵

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
  1. Change the main.tf e.g. docker_image.build.label.author
  2. second terraform apply
docker_image.zoo: Refreshing state... [id=sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6zoo]
docker_container.zoo: Refreshing state... [id=403260e5d04c88addc7216881380e6ef3ad8f06b8c68582f0a93eb63cd439759]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # docker_container.zoo must be replaced
-/+ resource "docker_container" "zoo" {
      + bridge                                      = (known after apply)
      ~ command                                     = [
          - "/bin/sh",
          - "-c",
          - "/start.sh",
        ] -> (known after apply)
      + container_logs                              = (known after apply)
      - cpu_shares                                  = 0 -> null
      - dns                                         = [] -> null
      - dns_opts                                    = [] -> null
      - dns_search                                  = [] -> null
      ~ entrypoint                                  = [] -> (known after apply)
      ~ env                                         = [] -> (known after apply)
      + exit_code                                   = (known after apply)
      ~ gateway                                     = "192.168.0.1" -> (known after apply)
      - group_add                                   = [] -> null
      ~ hostname                                    = "403260e5d04c" -> (known after apply)
      ~ id                                          = "403260e5d04c88addc7216881380e6ef3ad8f06b8c68582f0a93eb63cd439759" -> (known after apply)
      ~ image                                       = "sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6" -> (known after apply) # forces replacement
      ~ init                                        = false -> (known after apply)
      ~ ip_address                                  = "192.168.0.3" -> (known after apply)
      ~ ip_prefix_length                            = 24 -> (known after apply)
      ~ ipc_mode                                    = "private" -> (known after apply)
      - links                                       = [] -> null
      ~ log_driver                                  = "json-file" -> (known after apply)
      - log_opts                                    = {} -> null
      - max_retry_count                             = 0 -> null
      - memory                                      = 0 -> null
      - memory_swap                                 = 0 -> null
        name                                        = "zoo"
      ~ network_data                                = [
          - {
              - gateway                   = "192.168.0.1"
              - global_ipv6_address       = ""
              - global_ipv6_prefix_length = 0
              - ip_address                = "192.168.0.3"
              - ip_prefix_length          = 24
              - ipv6_gateway              = ""
              - network_name              = "bridge"
            },
        ] -> (known after apply)
      - network_mode                                = "default" -> null
      - privileged                                  = false -> null
      - publish_all_ports                           = false -> null
      ~ runtime                                     = "runc" -> (known after apply)
      ~ security_opts                               = [] -> (known after apply)
      ~ shm_size                                    = 64 -> (known after apply)
      + stop_signal                                 = (known after apply)
      ~ stop_timeout                                = 0 -> (known after apply)
      - storage_opts                                = {} -> null
      - sysctls                                     = {} -> null
      - tmpfs                                       = {} -> null
        # (13 unchanged attributes hidden)

      + healthcheck {
          + interval     = (known after apply)
          + retries      = (known after apply)
          + start_period = (known after apply)
          + test         = (known after apply)
          + timeout      = (known after apply)
        }

      + labels {
          + label = (known after apply)
          + value = (known after apply)
        }
    }

  # docker_image.zoo must be replaced
-/+ resource "docker_image" "zoo" {
      ~ id           = "sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6zoo" -> (known after apply)
      ~ image_id     = "sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6" -> (known after apply)
      ~ latest       = "sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6" -> (known after apply)
        name         = "zoo"
      + output       = (known after apply)
      + repo_digest  = (known after apply)
        # (1 unchanged attribute hidden)

      - build { # forces replacement
          - build_arg       = {} -> null
          - build_args      = {} -> null
          - cache_from      = [] -> null
          - context         = "C:/Users/.../ubuntu/." -> null
          - cpu_period      = 0 -> null
          - cpu_quota       = 0 -> null
          - cpu_shares      = 0 -> null
          - dockerfile      = "Dockerfile" -> null
          - extra_hosts     = [] -> null
          - force_remove    = false -> null
          - label           = {
              - "author" = "test"
            } -> null
          - labels          = {} -> null
          - memory          = 0 -> null
          - memory_swap     = 0 -> null
          - no_cache        = false -> null
          - pull_parent     = false -> null
          - remove          = true -> null
          - security_opt    = [] -> null
          - shm_size        = 0 -> null
          - squash          = false -> null
          - suppress_output = false -> null
          - tag             = [] -> null
        }
      + build { # forces replacement
          + cache_from   = []
          + context      = "C:/Users/.../ubuntu/."
          + dockerfile   = "Dockerfile"
          + extra_hosts  = []
          + label        = {
              + "author" = "test2"
            }
          + remove       = true
          + security_opt = []
          + tag          = []
        }
    }

Plan: 2 to add, 0 to change, 2 to destroy.
╷
│ Warning: Deprecated attribute
│
│   on main.tf line 25, in resource "docker_container" "zoo":
│   25:   image = docker_image.zoo.latest
│
│ The attribute "latest" is deprecated. Refer to the provider documentation for details.
│
│ (and one more similar warning elsewhere)
╵

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

docker_container.zoo: Destroying... [id=403260e5d04c88addc7216881380e6ef3ad8f06b8c68582f0a93eb63cd439759]
docker_container.zoo: Destruction complete after 1s
docker_image.zoo: Destroying... [id=sha256:ddfc623f4b0fcd93eb5b4f1dfc4d454b4072ed066905f60b6ec2829d8e2f9cf6zoo]
docker_image.zoo: Destruction complete after 0s
docker_image.zoo: Creating...
╷
│ Error: failed to solve with frontend dockerfile.v0: failed to read dockerfile: Error processing tar file(exit status 1): unexpected EOF
│
│
│
│   with docker_image.zoo,
│   on main.tf line 13, in resource "docker_image" "zoo":
│   13: resource "docker_image" "zoo" {
│
╵

All subsequent terraform apply will give the same result.

By deleting the terraform.tfstate file, you can start over with the same result.

Important Factoids

  • Docker Desktop Windows configuration
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": false
  }
}
  • enable or disable the buildkit has no effect
  • enable or disable of firewall and virus scanner has no effect

References

nothing really comparable found on the net

  • #0000
@Junkern Junkern added r/image Relates to the image resource p/windows Is specifically for the windows platform bug Something isn't working labels Jan 12, 2023
@mariyan-marinov
Copy link

I have the same problem

@Junkern
Copy link
Contributor

Junkern commented Feb 28, 2023

I am running on Apple Silicon and I cannot reproducce this issue. Can you run TF_LOG=DEBUG terraform apply so that we can get debug logs of the failing apply.
Can you also try to change your context value, so that it does not point to hidden files?

@SteelAndMagnum
Copy link

Hey Junkern,

I encountered this same issue on Windows 10 Pro.
After hours of switching different OS' (Windows 10, Windows WSL, Virtualbox Ubuntu, Amazon Linux EC2) and trying different things, this issue only occurred and persisted in Windows 10.
What i found to cause mine was in the build context's absolute path. If any of the folders or directories and sub-directories (pointing to where the Dockerfile and other files used in the build context is located) contains spaces in its name, like iac tests in C:\Users\[USER]\Desktop\iac tests\deployments versus iac-tests in C:\Users\[USER]\Desktop\iac-tests\deployments for instance, then context path resolution will fail.
I ran terraform apply for folder name containing spaces, with logs enabled as requested and have attached log file for your viewing.
$env:TF_LOG=DEBUG
$env:TF_LOG_PATH="terraform.txt"

terraform.txt

@dustinbrooks
Copy link

Same issue. Seems Windows specific. It will work the first time with zero state, but not after. If I jump into my linux distro in WSL and run the terraform apply on the same directory I have no issues.

Here is the only thing that stood out in the Windows side of the logging with some errors on locked state files that I don't see in the Linux logs.

2023-10-05T10:18:49.965-0500 [INFO]  Starting apply for docker_image.zoo
2023-10-05T10:18:49.965-0500 [DEBUG] docker_image.zoo: applying the planned Create change
2023-10-05T10:18:49.967-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] Building docker image: timestamp=2023-10-05T10:18:49.967-0500
2023-10-05T10:18:49.967-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] DockerClientVersion: 1.41, minBuildKitDockerVersion: 1.39: timestamp=2023-10-05T10:18:49.967-0500
2023-10-05T10:18:49.967-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] Enabling BuildKit: timestamp=2023-10-05T10:18:49.967-0500
2023-10-05T10:18:49.968-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] contextDir C:\Temp\docker: timestamp=2023-10-05T10:18:49.968-0500
2023-10-05T10:18:49.968-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] relDockerfile Dockerfile: timestamp=2023-10-05T10:18:49.968-0500
2023-10-05T10:18:49.968-0500 [INFO]  provider.terraform-provider-docker_v3.0.2.exe: 2023/10/05 10:18:49 [DEBUG] Excludes: []: timestamp=2023-10-05T10:18:49.968-0500
2023-10-05T10:18:51.660-0500 [DEBUG] provider.terraform-provider-docker_v3.0.2.exe: time="2023-10-05T10:18:51-05:00" level=error msg="Can't add file \\\\?\\C:\\Temp\\docker\\terraform.tfstate to tar: read \\\\?\\C:\\Temp\\docker\\terraform.tfstate: The process cannot access the file because another process has locked a portion of the file."
2023-10-05T10:18:51.661-0500 [DEBUG] provider.terraform-provider-docker_v3.0.2.exe: time="2023-10-05T10:18:51-05:00" level=error msg="Can't add file \\\\?\\C:\\Temp\\docker\\terraform.tfstate.backup to tar: archive/tar: missed writing 181 bytes"
2023-10-05T10:18:51.661-0500 [DEBUG] provider.terraform-provider-docker_v3.0.2.exe: time="2023-10-05T10:18:51-05:00" level=error msg="Can't add file \\\\?\\C:\\Temp\\docker\\terraform.txt to tar: archive/tar: missed writing 181 bytes"
2023-10-05T10:18:51.661-0500 [DEBUG] provider.terraform-provider-docker_v3.0.2.exe: time="2023-10-05T10:18:51-05:00" level=error msg="Can't close tar writer: archive/tar: missed writing 181 bytes"
2023-10-05T10:18:51.904-0500 [ERROR] provider.terraform-provider-docker_v3.0.2.exe: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/diag/diagnostics.go:55 tf_req_id=7a20f471-b4fd-20d2-31ab-e90d6f40da9d @module=sdk.proto diagnostic_detail= diagnostic_severity=ERROR diagnostic_summary="failed to read dockerfile: unexpected EOF

" tf_proto_version=5.3 tf_provider_addr=provider tf_resource_type=docker_image tf_rpc=ApplyResourceChange timestamp=2023-10-05T10:18:51.904-0500
2023-10-05T10:18:51.907-0500 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2023-10-05T10:18:51.907-0500 [ERROR] vertex "docker_image.zoo" error: failed to read dockerfile: unexpected EOF

@matifali
Copy link

matifali commented Oct 9, 2023

@dustinbrooks, you may try forcing LF line endings to see if it fixes the issue. This can be done quite easily in VSCode.

@trpalmer
Copy link

Confirmed Windows only, regardless of the EOL markers of the Dockerfile. Same LF ended file works on WSL/Linux, fails with this error in Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p/windows Is specifically for the windows platform r/image Relates to the image resource
Projects
None yet
Development

No branches or pull requests

7 participants