Skip to content

fix: Attempt docker pull before docker build when image not found locally#748

Open
raman1236 wants to merge 1 commit into
terraform-aws-modules:masterfrom
raman1236:fix/docker-pull-before-build
Open

fix: Attempt docker pull before docker build when image not found locally#748
raman1236 wants to merge 1 commit into
terraform-aws-modules:masterfrom
raman1236:fix/docker-pull-before-build

Conversation

@raman1236

Copy link
Copy Markdown

Description

Fixes #746

When build_in_docker = true and docker_image is set to a pre-built public registry image (e.g. public.ecr.aws/sam/build-python3.12:latest), if the image is not present locally, package.py falls back directly to docker build using docker_build_root as the build context. Since Lambda source directories typically don't contain a Dockerfile, this fails with:

ERROR: failed to build: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

Changes

  • Added docker_pull_command() helper function alongside existing docker_image_id_command() and docker_build_command()
  • Modified all 4 docker image resolution paths (pip, poetry, npm/yarn, uv) to attempt docker pull before falling back to docker build
  • If docker pull fails (e.g. for custom/local images), it falls back to the original docker build behavior

Impact

  • Pre-built registry images: docker pull succeeds, image is available locally
  • Custom images with Dockerfile: docker pull fails, falls back to docker build (same as before)
  • Already-local images: no change (image found in docker images check)

…ally

When docker_image is set to a pre-built registry image (e.g.
public.ecr.aws/sam/build-python3.12:latest) and the image is not
present locally, package.py now attempts 'docker pull' first.

Previously it would fall back directly to 'docker build' using
docker_build_root as the build context, which fails immediately
when no Dockerfile is present (common case for Lambda source dirs).

The fix tries 'docker pull <image>' first, and only falls back to
'docker build' if the pull fails (e.g. for custom/local images).

Fixes terraform-aws-modules#746
@raman1236 raman1236 force-pushed the fix/docker-pull-before-build branch from 46fc9f3 to a309939 Compare May 1, 2026 21:48
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions Bot added the stale label Jun 1, 2026
@baolsen

baolsen commented Jun 10, 2026

Copy link
Copy Markdown

Not stale, still an issue.

@github-actions github-actions Bot removed the stale label Jun 11, 2026
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

Successfully merging this pull request may close these issues.

docker pull not attempted when docker_image is set but not found locally — falls back to docker build causing failure

2 participants