microsoft / microsoft/aspire

Support time-based image pull policies (Daily / Weekly / Every(duration)) in ImagePullPolicy

Open
#19,619 2 comments 1 reaction 0 assignees View on GitHub
area-app-model area-orchestrator needs-area-label triage:bot-seen
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

### Summary

`ImagePullPolicy` currently exposes only `Default`, `Always`, `Missing`, and `Never`. There is no way to express a *periodic* refresh. Docker Compose already supports exactly this via time-based `pull_policy` values (`daily`, `weekly`, `every_`). This issue requests parity in Aspire's `ImagePullPolicy`.

### Motivation

A very common local-dev / CI pattern is a container pinned to a mutable tag such as `:latest` that an upstream pipeline rebuilds roughly once a day:

```csharp
builder.AddContainer("mock", "registry.example.com/org/mock-service", "latest")
.WithLifetime(ContainerLifetime.Session);
```

Today the available options are both unsatisfying:

- **`Missing` / `Default`** — the cached `:latest` is reused forever and silently goes stale; you never pick up the daily rebuild unless you manually `docker pull` or prune.
- **`Always`** — re-pulls on *every* `aspire run` / startup. That adds pull latency to every launch and fails hard with no network (see #10719), even though a day-old cached image would have been perfectly fine.

What's actually wanted is "keep it reasonably fresh, but don't pay the pull cost on every start".

### What Docker Compose already does

The Compose spec supports time-based pull policies:

- `daily`: check the registry if the last pull was more than 24h ago
- `weekly`: same, for 7 days
- `every_`: `every_12h`, `every_2d`, `every_1h30m`

Docs: https://docs.docker.com/reference/compose-file/services/#pull_policy

Because Aspire maps `WithImagePullPolicy(...)` onto the generated Compose `pull_policy` when publishing to a Docker Compose environment, the current enum can't even *emit* these values today.

### Describe the solution you'd like

### Proposed API

Add time-based members / a factory to `ImagePullPolicy`, e.g.:

```csharp
// convenience presets
builder.AddContainer("mock", "registry.example.com/org/mock-service", "latest")
.WithImagePullPolicy(ImagePullPolicy.Daily);

builder.AddContainer("mock", "registry.example.com/org/mock-service", "latest")
.WithImagePullPolicy(ImagePullPolicy.Weekly);

// arbitrary interval
builder.AddContainer("mock", "registry.example.com/org/mock-service", "latest")
.WithImagePullPolicy(ImagePullPolicy.Every(TimeSpan.FromHours(12)));
```

**Semantics:** before creating the container, if the locally cached image's pull/creation time is older than the interval, pull; otherwise reuse the cache.

### Relationship to existing issues

- **#10719** (`ImagePullPolicy.IfPossible`) is related but orthogonal: it asks for "pull if the network is available, otherwise fall back to cache." A time-based policy is about *how often* to attempt a pull, not about network-failure fallback. Ideally the two compose.
- **#7350** exposed `WithImagePullPolicy` in the first place (13.2).

### Additional context

Aspire `ImagePullPolicy` members as of today: `Default`, `Always`, `Missing`, `Never`

Contributor guide

Open the contributing guide

Research direction

Start at ImagePullPolicy and the WithImagePullPolicy entry point, then trace how Default, Always, Missing, and Never become the generated Docker Compose pull_policy. Implement the requested Daily, Weekly, and Every(TimeSpan) behavior according to the stated cache-age semantics, and verify that the corresponding Compose values are emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker, docker-compose
Domain
devops, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.