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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_image build image even if file context and dockerfile doesn't change #571

Open
IlyesDemineExtVeolia opened this issue Jul 18, 2023 · 3 comments

Comments

@IlyesDemineExtVeolia
Copy link

IlyesDemineExtVeolia commented Jul 18, 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

Affected Resource(s)

  • docker_image

Terraform Configuration Files

resource "docker_image" "this" {
  name = local.ecr_image_name

  build {
    context    = var.source_path
    dockerfile = var.docker_file_path
    build_args = var.build_args
    platform   = var.platform
  }
}

Debug Output

Panic Output

Expected Behaviour

Don't build and deploy if context and dockerfile doesn't change

Actual Behaviour

Build and Deploy at each terraform apply

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000
@vnghia
Copy link

vnghia commented Jul 31, 2023

I found that the build will be retriggered if the content of (file, subfolder, etc) your context folder change, which makes sense because the provider does not know which file in the context folder will be used (e.g COPY or ADD could copy them into the image) while building the Dockerfile.

@asmisha
Copy link

asmisha commented Sep 4, 2023

In my case the build is triggered even if the content has not changed. I suspect that it's auth_config that causes the rebuild due to changing credentials.

@samuelcortinhas
Copy link

I've also come across this bug. Our use case was to build an image from a dockerfile in a folder src/example and push it to an AWS ECR repository. We wanted to only rebuild/push image when there were changes to the code in src/example. However, even with the triggers hash is the same, the docker_image is being rebuilt every time.

resource "docker_registry_image" "registry_image" {
  name = docker_image.image.name
}

resource "docker_image" "image" {
  name = "${aws_ecr_repository.repository.repository_url}:latest"

  build {
    context = "${path.module}/src/example"
  }
  triggers = {
    dir_sha1 = sha1(join("", [for f in fileset(path.module, "src/example/**") : filesha1(f)]))
  }
}

Our solution was to rollback to version 2.25.0 of kreuzwerker/docker. (note the above configuration needs changing for this version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants