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
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void BuildContainerApp(AzureResourceInfrastructure c)
containerAppContainer.Image = containerImageParam is null ? containerImageName! : containerImageParam;
containerAppContainer.Name = resource.Name;

SetEntryPoint(containerAppContainer);
AddEnvironmentVariablesAndCommandLineArgs(containerAppContainer);

foreach (var (_, mountedVolume) in Volumes)
Expand Down Expand Up @@ -824,6 +825,14 @@ private void AddIngress(ContainerAppConfiguration config)
config.Ingress = caIngress;
}

private void SetEntryPoint(ContainerAppContainer container)
{
if (resource is ContainerResource containerResource && containerResource.Entrypoint is { } entrypoint)
{
container.Command = [entrypoint];
}
}

private void AddEnvironmentVariablesAndCommandLineArgs(ContainerAppContainer container)
{
if (EnvironmentVariables.Count > 0)
Expand Down
83 changes: 83 additions & 0 deletions tests/Aspire.Hosting.Azure.Tests/AzureContainerAppsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,89 @@ param minReplicas string
Assert.Equal(expectedBicep, bicep);
}

[Fact]
public async Task AddContainerAppsEntrypointAndArgs()
{
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);

builder.AddAzureContainerAppsInfrastructure();

builder.AddContainer("api", "myimage")
.WithEntrypoint("/bin/sh")
.WithArgs("my", "args with space");

using var app = builder.Build();

await ExecuteBeforeStartHooksAsync(app, default);

var model = app.Services.GetRequiredService<DistributedApplicationModel>();
var container = Assert.Single(model.GetContainerResources());

container.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var target);

var resource = target?.DeploymentTarget as AzureProvisioningResource;

Assert.NotNull(resource);

var (manifest, bicep) = await ManifestUtils.GetManifestWithBicep(resource);

var expectedBicep =
"""
@description('The location for the resource(s) to be deployed.')
param location string = resourceGroup().location

param outputs_azure_container_registry_managed_identity_id string

param outputs_managed_identity_client_id string

param outputs_azure_container_apps_environment_id string

resource api 'Microsoft.App/containerApps@2024-03-01' = {
name: 'api'
location: location
properties: {
configuration: {
activeRevisionsMode: 'Single'
}
environmentId: outputs_azure_container_apps_environment_id
template: {
containers: [
{
image: 'myimage:latest'
name: 'api'
command: [
'/bin/sh'
]
args: [
'my'
'args with space'
]
env: [
{
name: 'AZURE_CLIENT_ID'
value: outputs_managed_identity_client_id
}
]
}
]
scale: {
minReplicas: 1
}
}
}
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${outputs_azure_container_registry_managed_identity_id}': { }
}
}
}
""";

output.WriteLine(bicep);
Assert.Equal(expectedBicep, bicep);
}

[Fact]
public async Task ProjectWithManyReferenceTypes()
{
Expand Down