Feature: Add collision-resistant randomness to container image tags

Open Beginner friendly
#9,201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
cli

Research direction

Start in cli/azd/pkg/project/container_helper.go at DefaultImageTag() and inspect nearby tests or test helpers for ContainerHelper and clock behavior. Done means default tags retain the timestamp while adding collision-resistant randomness, and relevant tests verify the format and distinct tags for deployments in the same second.

Written by the indexing model from the issue text.

Description

Is your feature request related to a problem?

When azd deploy runs for container-based services, the default image tag is generated from time.Now().Unix() (seconds since epoch). If two deployments happen within the same second (e.g. parallel CI pipelines, scripted multi-environment rollouts, or retry logic that re-triggers quickly), they produce identical tags. This means the second push silently overwrites the first image in the registry, and any service still referencing that tag may get unexpected content.

Describe the solution you'd like

Add a short random suffix to DefaultImageTag() so that tags are collision-resistant by construction. For example, changing from:

func (ch *ContainerHelper) DefaultImageTag() string {
    return fmt.Sprintf("azd-deploy-%d", ch.clock.Now().Unix())
}

to something like:

func (ch *ContainerHelper) DefaultImageTag() string {
    buf := make([]byte, 6)
    _, _ = rand.Read(buf)
    return fmt.Sprintf("azd-deploy-%d-%x", ch.clock.Now().Unix(), buf)
}

This produces tags like azd-deploy-1752883200-a3f1b2c4d5e6 that are unique even under same-second concurrency, while remaining human-readable and sortable by timestamp.

Describe alternatives you considered
  • Project-level hook scripts that generate custom tags and store them in azd env vars before the deploy lifecycle runs. This works but forces every project to reimplement the same logic and adds maintenance burden outside of azd.
  • Using git commit SHA as the tag. This is collision-resistant but loses the deployment-time ordering that azd-deploy-{timestamp} provides, and doesn't work for dirty working trees.
Additional context

The current DefaultImageTag() lives in cli/azd/pkg/project/container_helper.go. The change is minimal (one function, one import) and backward-compatible since nothing depends on the exact tag format.

Dominant language
Go
Stars
569
Forks
365
Avg merge
2d 20h
Merged PRs (30d)
132

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/azure-dev

All issues in Azure/azure-dev

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.