Skip to content

feat(ecr-ecs-lambda): wire fakecloud ECR into ECS + Lambda image pull#726

Merged
vieiralucas merged 2 commits intomainfrom
worktree-ecr-ecs-tighten-batch1
Apr 24, 2026
Merged

feat(ecr-ecs-lambda): wire fakecloud ECR into ECS + Lambda image pull#726
vieiralucas merged 2 commits intomainfrom
worktree-ecr-ecs-tighten-batch1

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 24, 2026

Summary

Batch 1 of the ECR+ECS tightening pass — the flagship cross-service integration. Images pushed to fakecloud ECR via the OCI v2 endpoint are now pulled and run by ECS tasks and Lambda functions that reference them by AWS URI.

  • ECR URI translator in fakecloud-core shared between ECS + Lambda
  • ECS runtime pulls from fakecloud ECR transparently when task image is an AWS ECR URI; retags to preserve user-facing image name
  • Lambda PackageType=Image now wired: Code.ImageUri flows through CreateFunction -> GetFunction -> container runtime
  • Isolated DOCKER_CONFIG tempdir carries Basic auth for 127.0.0.1:<port> so pulls work without mutating the user's docker config
  • E2E test proves the full loop: docker push alpine to fakecloud ECR -> RunTask with AWS URI -> captured stdout matches container output

Test plan

  • cargo test -p fakecloud-core -p fakecloud-ecs -p fakecloud-lambda -p fakecloud-ecr — all unit tests pass
  • cargo test -p fakecloud-e2e --test ecr_cross_service — four tests pass (Linux path skipped on macOS as designed)
  • cargo test -p fakecloud-e2e --test ecs --test ecr --test ecr_oci --test lambda — no regressions
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • CI (Linux) runs the docker-push path of ecr_cross_service end-to-end

Summary by cubic

Wired fakecloud ECR into ECS and Lambda image pulls so images pushed to the local OCI v2 registry can be referenced by AWS ECR URIs and run end to end. Tightened URI detection, digest handling, and env var rewriting for a smoother AWS-like flow.

  • New Features

    • Added fakecloud_core::ecr_uri to translate <acct>.dkr.ecr.<region>.amazonaws.com/<repo>[:tag|@sha256] to 127.0.0.1:<port>/<repo>[:tag|@sha256].
    • fakecloud-ecs pulls via the local registry for ECR URIs, retags to the AWS name, and uses an isolated DOCKER_CONFIG with Basic auth.
    • fakecloud-lambda supports PackageType=Image: stores Code.ImageUri, returns it in GetFunction, pulls via the same translator, and rejects Image without ImageUri.
    • fakecloud-server passes the bound port to both runtimes; new E2E test verifies push-to-ECR → ECS RunTask; ECS docs updated.
  • Bug Fixes

    • Restored env-var rewriting for localhosthost.docker.internal in the ECS runtime.
    • Digest-pinned refs (@sha256) skip retagging; ECS and Lambda run under the local 127.0.0.1 URI.
    • Code.ImageUri is parsed only for PackageType=Image; Zip functions ignore it.
    • ECR URI detection is host-anchored to avoid false positives.

Written for commit 26cf0fd. Summary will update on new commits.

The flagship cross-service integration: images pushed to fakecloud ECR
via the OCI v2 endpoint are now pulled and run by ECS tasks and Lambda
functions that reference them by AWS URI. This closes the "three
independent silos" gap called out in the tightening pass brief — ECR,
ECS, and Lambda now act as a real local AWS instead of unconnected
services that happen to coexist.

- New `fakecloud_core::ecr_uri::translate_to_local` recognises
  `<acct>.dkr.ecr.<region>.amazonaws.com/<repo>:<tag>` and translates
  to `127.0.0.1:<server-port>/<repo>:<tag>`. Shared between ECS + Lambda
  runtimes so they resolve identically.

- ECS runtime gets the server port at startup, pulls from fakecloud's
  local OCI v2 endpoint, retags to the AWS URI, runs. An isolated
  DOCKER_CONFIG tempdir carries Basic auth for `127.0.0.1:<port>` so
  pulls work without mutating the user's `~/.docker/config.json` or
  requiring a prior `aws ecr get-login-password | docker login`.

- Lambda gains real `PackageType=Image` support: `Code.ImageUri` is
  parsed, stored on `LambdaFunction`, surfaced in `function_config_json`
  / `GetFunction` responses with `RepositoryType=ECR`, and runs through
  a new `start_image_container` path that pulls via the same ECR
  translator and skips the zip extraction / `docker cp` step. Rejects
  `PackageType=Image` without `ImageUri` with
  `InvalidParameterValueException`, matching AWS.

- New `tests/ecr_cross_service.rs` covers the loop end-to-end: push an
  alpine image to fakecloud ECR via real `docker push`, then RunTask
  against the AWS URI and assert the captured stdout. Gated on Linux
  (CI) since Docker Desktop on macOS runs the daemon in a VM that
  can't reach `127.0.0.1:<port>` without `insecure-registries` config;
  on macOS the test skips with a clear message. Non-docker tests
  cover `ImageUri` roundtrip and the missing-URI rejection.

- Docs: `website/content/docs/services/ecs.md` now documents the
  transparent fakecloud ECR pull path for both ECS tasks and Lambda
  Image functions.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 30.17544% with 199 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-lambda/src/runtime.rs 0.00% 143 Missing ⚠️
crates/fakecloud-ecs/src/runtime.rs 17.02% 39 Missing ⚠️
crates/fakecloud-lambda/src/service.rs 57.57% 14 Missing ⚠️
crates/fakecloud-server/src/main.rs 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-lambda/src/service.rs">

<violation number="1" location="crates/fakecloud-lambda/src/service.rs:98">
P2: `Code.ImageUri` is accepted for non-image functions, which can make `GetFunction` return ECR code metadata for `PackageType=Zip` functions.</violation>
</file>

<file name="crates/fakecloud-ecs/src/runtime.rs">

<violation number="1" location="crates/fakecloud-ecs/src/runtime.rs:210">
P1: `localhost` URL rewriting was accidentally removed and replaced with duplicate `127.0.0.1` replacements, so container env vars using `localhost` will not be translated to `host.docker.internal`.</violation>
</file>

<file name="crates/fakecloud-core/src/ecr_uri.rs">

<violation number="1" location="crates/fakecloud-core/src/ecr_uri.rs:15">
P2: Validate the registry host before classifying an image as private ECR; the current substring check can misroute non-ECR images that contain those tokens in the repository path.</violation>

<violation number="2" location="crates/fakecloud-core/src/ecr_uri.rs:33">
P1: Preserving digest refs here breaks downstream retagging; the ECS/Lambda runtimes use `docker tag ... <aws-uri>`, which cannot target `@sha256` references.</violation>
</file>

<file name="website/content/docs/services/ecs.md">

<violation number="1" location="website/content/docs/services/ecs.md:55">
P3: Clarify the platform caveat here: the ECR pull is not daemon-config-free on every Docker setup (macOS Docker Desktop still needs insecure-registry support).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-ecs/src/runtime.rs Outdated
Comment thread crates/fakecloud-core/src/ecr_uri.rs
Comment thread crates/fakecloud-lambda/src/service.rs Outdated
Comment thread crates/fakecloud-core/src/ecr_uri.rs Outdated
Comment thread website/content/docs/services/ecs.md Outdated
… ImageUri scope, host anchoring

- P1: restore `localhost` env-var -> `host.docker.internal` rewriting in
  the ECS runtime; my earlier `localhost` -> `127.0.0.1` sweep
  accidentally replaced the `localhost` branch with a duplicate
  `127.0.0.1` branch.
- P1: digest-pinned ECR refs (`repo@sha256:...`) can't be `docker tag`
  targets. `is_digest_ref` detects them; the ECS + Lambda runtimes
  skip the retag and run the container under the local 127.0.0.1 URI
  instead. Cosmetic tradeoff vs. failing the pull outright.
- P2: `Code.ImageUri` is now only parsed for `PackageType=Image`
  functions. Zip-package functions that accidentally pass ImageUri no
  longer round-trip ECR metadata via GetFunction.
- P2: `is_aws_ecr_uri` anchors on the registry host (split at first
  `/`, then check `ends_with(".amazonaws.com")`). Paths that happen to
  contain the ECR tokens as a substring no longer misclassify.
- P3: ECS doc clarifies the Linux-vs-Docker-Desktop caveat for the
  transparent ECR pull path.
@vieiralucas vieiralucas merged commit 32e655b into main Apr 24, 2026
19 checks passed
@vieiralucas vieiralucas deleted the worktree-ecr-ecs-tighten-batch1 branch April 24, 2026 11:11
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.

1 participant