Skip to content

Commit f545dbc

Browse files
committed
dockerfile
1 parent 2243066 commit f545dbc

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed

lambdas/id_sync/Dockerfile

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,37 @@ RUN mkdir -p /home/appuser && \
66
echo 'appuser:x:1001:' >> /etc/group && \
77
chown -R 1001:1001 /home/appuser && pip install "poetry~=1.5.0"
88

9-
# Install Poetry as root
10-
COPY poetry.lock pyproject.toml README.md ./
9+
# Install Poetry dependencies
10+
# Copy shared Poetry files first
11+
COPY shared/poetry.lock shared/pyproject.toml shared/README.md ./shared/
12+
# Copy id_sync Poetry files
13+
COPY id_sync/poetry.lock id_sync/pyproject.toml id_sync/README.md ./
14+
15+
# Install shared dependencies first
16+
WORKDIR /var/task/shared
17+
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main
18+
19+
# Install id_sync dependencies
20+
WORKDIR /var/task
1121
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi --no-root --only main
1222

1323
# -----------------------------
1424
FROM base AS build
15-
COPY src .
16-
COPY ../shared/src/common ./common
25+
26+
# Set working directory back to Lambda task root
27+
WORKDIR /var/task
28+
29+
# Copy shared source code
30+
COPY shared/src/common ./common
31+
32+
# Copy id_sync source code
33+
COPY id_sync/src .
34+
35+
# Set correct permissions
1736
RUN chmod 644 $(find . -type f) && chmod 755 $(find . -type d)
37+
1838
# Build as non-root user
1939
USER 1001:1001
40+
41+
# Set the Lambda handler
2042
CMD ["id_sync.handler"]

terraform/id_sync_lambda.tf

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
# Define the directory containing the Docker image and calculate its SHA-256 hash for triggering redeployments
22
locals {
3+
lambdas_dir = abspath("${path.root}/../lambdas")
4+
shared_dir = abspath("${path.root}/../lambdas/shared")
35
id_sync_lambda_dir = abspath("${path.root}/../lambdas/id_sync")
6+
7+
# Get files from both directories
8+
shared_files = fileset(local.shared_dir, "**")
49
id_sync_lambda_files = fileset(local.id_sync_lambda_dir, "**")
10+
11+
# Calculate SHA for both directories
12+
shared_dir_sha = sha1(join("", [for f in local.shared_files : filesha1("${local.shared_dir}/${f}")]))
513
id_sync_lambda_dir_sha = sha1(join("", [for f in local.id_sync_lambda_files : filesha1("${local.id_sync_lambda_dir}/${f}")]))
14+
15+
# Combined SHA to trigger rebuild when either directory changes
16+
combined_sha = sha1("${local.shared_dir_sha}${local.id_sync_lambda_dir_sha}")
17+
}
18+
19+
output "debug_build_paths" {
20+
value = {
21+
lambdas_dir = local.lambdas_dir
22+
shared_dir = local.shared_dir
23+
id_sync_lambda_dir = local.id_sync_lambda_dir
24+
shared_files_count = length(local.shared_files)
25+
id_sync_files_count = length(local.id_sync_lambda_files)
26+
combined_sha = local.combined_sha
27+
dockerfile_exists = fileexists("${local.id_sync_lambda_dir}/Dockerfile")
28+
shared_common_exists = fileexists("${local.shared_dir}/src/common/__init__.py")
29+
}
30+
}
31+
32+
# Debug: List some files from each directory
33+
output "debug_file_listing" {
34+
value = {
35+
shared_files_sample = slice(local.shared_files, 0, min(5, length(local.shared_files)))
36+
id_sync_files_sample = slice(local.id_sync_lambda_files, 0, min(5, length(local.id_sync_lambda_files)))
37+
}
638
}
739

840
# Reference the existing SQS queue
@@ -44,9 +76,39 @@ module "id_sync_docker_image" {
4476

4577
platform = "linux/amd64"
4678
use_image_tag = false
47-
source_path = local.id_sync_lambda_dir
79+
source_path = local.lambdas_dir # parent lambdas directory
4880
triggers = {
49-
dir_sha = local.id_sync_lambda_dir_sha
81+
dir_sha = local.combined_sha # Changed to combined SHA
82+
}
83+
}
84+
85+
# Add a local provisioner to debug build context
86+
resource "null_resource" "debug_build_context" {
87+
triggers = {
88+
dir_sha = local.combined_sha
89+
}
90+
91+
provisioner "local-exec" {
92+
command = <<-EOT
93+
echo "=== BUILD CONTEXT DEBUG ==="
94+
echo "Build context: ${local.lambdas_dir}"
95+
echo "Dockerfile location: ${local.id_sync_lambda_dir}/Dockerfile"
96+
echo ""
97+
echo "Checking Dockerfile exists:"
98+
ls -la "${local.id_sync_lambda_dir}/Dockerfile" || echo "Dockerfile NOT FOUND!"
99+
echo ""
100+
echo "Checking shared directory structure:"
101+
ls -la "${local.shared_dir}/src/common/" || echo "Shared common directory NOT FOUND!"
102+
echo ""
103+
echo "Files in build context (lambdas dir):"
104+
ls -la "${local.lambdas_dir}/"
105+
echo ""
106+
echo "Shared files structure:"
107+
find "${local.shared_dir}" -type f -name "*.py" | head -10
108+
echo ""
109+
echo "ID Sync files structure:"
110+
find "${local.id_sync_lambda_dir}" -type f -name "*.py" | head -10
111+
EOT
50112
}
51113
}
52114

0 commit comments

Comments
 (0)