Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/setup-runtimes-caching/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
docker-password:
description: "The Docker password"
required: true
docker-registry:
description: "The Docker registry"
required: true
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -107,6 +110,7 @@ runs:
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}
registry: ${{ inputs.docker-registry }}

- uses: dapr/setup-dapr@v2
name: Setup Dapr
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
name: "Full"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
docker-registry: ${{ secrets.CUSTOM_CONTAINER_REGISTRY }}

- name: Restore dependencies
run: dotnet restore
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
name: "Full"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
docker-registry: ${{ secrets.CUSTOM_CONTAINER_REGISTRY }}

- name: Restore dependencies
run: dotnet restore
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
name: "Full"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
docker-registry: ${{ secrets.CUSTOM_CONTAINER_REGISTRY }}

- name: Restore dependencies
run: dotnet restore
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
name: ${{ matrix.name }}
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
docker-registry: ${{ secrets.CUSTOM_CONTAINER_REGISTRY }}

- name: Verify Docker is running
run: docker info
Expand All @@ -94,6 +95,8 @@ jobs:
--collect "XPlat Code Coverage"
--no-restore
--no-build -- RunConfiguration.CollectSourceInformation=true
env:
CUSTOM_CONTAINER_REGISTRY: ${{ secrets.CUSTOM_CONTAINER_REGISTRY }}

- name: Dump docker info
if: always()
Expand Down
31 changes: 31 additions & 0 deletions tests/CommunityToolkit.Aspire.Testing/AspireIntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aspire.Components.Common.Tests;
using Aspire.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace CommunityToolkit.Aspire.Testing;
Expand Down Expand Up @@ -28,6 +29,36 @@ protected override void OnBuilderCreated(DistributedApplicationBuilder applicati
})
.ConfigureHttpClientDefaults(clientBuilder => clientBuilder.AddStandardResilienceHandler());

if (Environment.GetEnvironmentVariable("CUSTOM_CONTAINER_REGISTRY") is not null)
{
// We can't use the built-in Aspire container override feature because that changes the registry for all
// containers, and we only want to change the registry for the default Docker Hub registry. So we need to
// override the registry in the BeforeStartEvent handler (essentially implementing a subset of the built-in
// functionality ourselves).
applicationBuilder.Eventing.Subscribe<BeforeStartEvent>((@event, ct) =>
{
var resourcesWithContainerImages = @event.Model.Resources.SelectMany(
r => r.Annotations.OfType<ContainerImageAnnotation>()
.Select(cia => new { Resource = r, Annotation = cia })
);

foreach (var resourceWithContainerImage in resourcesWithContainerImages)
{
string? dockerHubOverride = Environment.GetEnvironmentVariable("CUSTOM_CONTAINER_REGISTRY");

// We only override the registry if the resource is using the default Docker Hub registry, as that is
// rate limited. Microsoft Artifact Registry and GitHub Container Registry are not rate limited, or at
// least we don't pull enough images to hit the rate limit.
if (dockerHubOverride is not null && resourceWithContainerImage.Annotation.Registry == "docker.io")
{
resourceWithContainerImage.Annotation.Registry = dockerHubOverride;
}
}

return Task.CompletedTask;
});
}

base.OnBuilderCreated(applicationBuilder);
}

Expand Down
Loading