Skip to content

Commit 217d079

Browse files
committed
update Docker image source hash calculation to use git for accuracy
1 parent f7695b5 commit 217d079

File tree

1 file changed

+4
-5
lines changed
  • terraform/modules/run-service

1 file changed

+4
-5
lines changed

terraform/modules/run-service/main.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ provider "docker" {
1818
}
1919
}
2020

21-
# Calculate hash of source files to determine if rebuild is needed
22-
locals {
23-
source_files = fileset(path.root, "${var.source_directory}/*")
24-
source_hash = substr(sha1(join("", [for f in local.source_files : filesha1(f)])), 0, 8)
21+
# Calculate hash of source files using git (respects .gitignore)
22+
data "external" "source_hash" {
23+
program = ["bash", "-c", "cd ${var.source_directory} && echo '{\"hash\":\"'$(git ls-files -s | sha1sum | cut -c1-8)'\"}'"]
2524
}
2625

2726
# Build Docker image
2827
resource "docker_image" "function_image" {
29-
name = "${var.region}-docker.pkg.dev/${var.project}/report-api/${var.service_name}:${local.source_hash}"
28+
name = "${var.region}-docker.pkg.dev/${var.project}/report-api/${var.service_name}:${data.external.source_hash.result.hash}"
3029

3130
build {
3231
context = var.source_directory

0 commit comments

Comments
 (0)