|
3 | 3 |
|
4 | 4 | #pragma warning disable ASPIREACADOMAINS001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
5 | 5 | #pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
| 6 | +#pragma warning disable ASPIREAZURE002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. |
6 | 7 |
|
7 | 8 | using System.Text.Json.Nodes;
|
8 | 9 | using Aspire.Hosting.ApplicationModel;
|
@@ -516,40 +517,6 @@ await Verify(manifest.ToString(), "json")
|
516 | 517 | .AppendContentAsFile(bicep, "bicep");
|
517 | 518 | }
|
518 | 519 |
|
519 |
| - [Fact] |
520 |
| - public async Task PublishAsContainerAppJobInfluencesContainerAppDefinition() |
521 |
| - { |
522 |
| - var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); |
523 |
| - |
524 |
| - builder.AddAzureContainerAppEnvironment("env"); |
525 |
| - builder.AddContainer("api", "myimage") |
526 |
| - .PublishAsAzureContainerAppJob((module, j) => |
527 |
| - { |
528 |
| - Assert.Contains(j, module.GetProvisionableResources()); |
529 |
| - |
530 |
| - j.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule; |
531 |
| - j.Configuration.ScheduleTriggerConfig.CronExpression = "*/5 * * * *"; |
532 |
| - }); |
533 |
| - |
534 |
| - using var app = builder.Build(); |
535 |
| - |
536 |
| - await ExecuteBeforeStartHooksAsync(app, default); |
537 |
| - |
538 |
| - var model = app.Services.GetRequiredService<DistributedApplicationModel>(); |
539 |
| - |
540 |
| - var container = Assert.Single(model.GetContainerResources()); |
541 |
| - |
542 |
| - container.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var target); |
543 |
| - |
544 |
| - var resource = target?.DeploymentTarget as AzureProvisioningResource; |
545 |
| - |
546 |
| - Assert.NotNull(resource); |
547 |
| - |
548 |
| - var (manifest, bicep) = await GetManifestWithBicep(resource); |
549 |
| - |
550 |
| - await Verify(bicep, "bicep"); |
551 |
| - } |
552 |
| - |
553 | 520 | [Fact]
|
554 | 521 | public async Task ConfigureCustomDomainMutatesIngress()
|
555 | 522 | {
|
@@ -729,11 +696,11 @@ public async Task MultipleVolumesHaveUniqueNamesInBicep()
|
729 | 696 | Assert.Contains("my_ace_outputs_volumes_druid_0", bicep);
|
730 | 697 | Assert.Contains("my_ace_outputs_volumes_druid_1", bicep);
|
731 | 698 | Assert.Contains("my_ace_outputs_bindmounts_druid_0", bicep);
|
732 |
| - |
| 699 | + |
733 | 700 | // Also verify the container app environment resource output
|
734 | 701 | var containerAppEnvResource = Assert.Single(model.Resources.OfType<AzureContainerAppEnvironmentResource>());
|
735 | 702 | var (envManifest, envBicep) = await GetManifestWithBicep(containerAppEnvResource);
|
736 |
| - |
| 703 | + |
737 | 704 | await Verify(manifest.ToString())
|
738 | 705 | .AppendContentAsFile(bicep)
|
739 | 706 | .AppendContentAsFile(envManifest.ToString())
|
@@ -1650,4 +1617,134 @@ public async Task MultipleAzureContainerAppEnvironmentsSupported()
|
1650 | 1617 |
|
1651 | 1618 | await VerifyFile(Path.Combine(tempDir.Path, "aspire-manifest.json"));
|
1652 | 1619 | }
|
| 1620 | + |
| 1621 | + [Fact] |
| 1622 | + public async Task PublishAsContainerAppJobInfluencesContainerAppDefinition() |
| 1623 | + { |
| 1624 | + var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); |
| 1625 | + builder.AddAzureContainerAppEnvironment("env"); |
| 1626 | + builder.AddContainer("api", "myimage") |
| 1627 | + .PublishAsAzureContainerAppJob((module, j) => |
| 1628 | + { |
| 1629 | + Assert.Contains(j, module.GetProvisionableResources()); |
| 1630 | + |
| 1631 | + j.Configuration.TriggerType = ContainerAppJobTriggerType.Schedule; |
| 1632 | + j.Configuration.ScheduleTriggerConfig.CronExpression = "*/5 * * * *"; |
| 1633 | + }); |
| 1634 | + |
| 1635 | + using var app = builder.Build(); |
| 1636 | + |
| 1637 | + await ExecuteBeforeStartHooksAsync(app, default); |
| 1638 | + |
| 1639 | + var model = app.Services.GetRequiredService<DistributedApplicationModel>(); |
| 1640 | + var container = Assert.Single(model.GetContainerResources()); |
| 1641 | + container.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var target); |
| 1642 | + var resource = target?.DeploymentTarget as AzureProvisioningResource; |
| 1643 | + Assert.NotNull(resource); |
| 1644 | + |
| 1645 | + var (manifest, bicep) = await GetManifestWithBicep(resource); |
| 1646 | + |
| 1647 | + await Verify(bicep, "bicep"); |
| 1648 | + } |
| 1649 | + |
| 1650 | + [Fact] |
| 1651 | + public async Task PublishAsContainerAppJob_WorksForProjectResource() |
| 1652 | + { |
| 1653 | + var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); |
| 1654 | + builder.AddAzureContainerAppEnvironment("env"); |
| 1655 | + builder.AddProject<Project>("job", launchProfileName: null) |
| 1656 | + .PublishAsAzureContainerAppJob((infra, job) => { }); |
| 1657 | + |
| 1658 | + using var app = builder.Build(); |
| 1659 | + await ExecuteBeforeStartHooksAsync(app, default); |
| 1660 | + |
| 1661 | + var model = app.Services.GetRequiredService<DistributedApplicationModel>(); |
| 1662 | + var project = Assert.Single(model.GetProjectResources()); |
| 1663 | + project.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var target); |
| 1664 | + var resource = target?.DeploymentTarget as AzureProvisioningResource; |
| 1665 | + Assert.NotNull(resource); |
| 1666 | + |
| 1667 | + var (manifest, bicep) = await GetManifestWithBicep(resource); |
| 1668 | + |
| 1669 | + await Verify(bicep, "bicep"); |
| 1670 | + } |
| 1671 | + |
| 1672 | + [Fact] |
| 1673 | + public async Task PublishAsContainerAppJob_ThrowsForAzureFunctions() |
| 1674 | + { |
| 1675 | + var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); |
| 1676 | + builder.AddAzureContainerAppEnvironment("env"); |
| 1677 | + |
| 1678 | + builder.AddAzureFunctionsProject<TestFunctionsProject>("funcjob") |
| 1679 | + .PublishAsAzureContainerAppJob((infra, job) => { }); |
| 1680 | + |
| 1681 | + using var app = builder.Build(); |
| 1682 | + await ExecuteBeforeStartHooksAsync(app, default); |
| 1683 | + |
| 1684 | + var model = app.Services.GetRequiredService<DistributedApplicationModel>(); |
| 1685 | + var funcjob = model.Resources.Single(r => r.Name == "funcjob"); |
| 1686 | + funcjob.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var target); |
| 1687 | + var resource = target?.DeploymentTarget as AzureProvisioningResource; |
| 1688 | + Assert.NotNull(resource); |
| 1689 | + |
| 1690 | + await Assert.ThrowsAsync<NotSupportedException>(async () => await GetManifestWithBicep(resource)); |
| 1691 | + } |
| 1692 | + |
| 1693 | + private sealed class TestFunctionsProject : IProjectMetadata |
| 1694 | + { |
| 1695 | + public string ProjectPath => "functions-project"; |
| 1696 | + |
| 1697 | + public LaunchSettings LaunchSettings => new() |
| 1698 | + { |
| 1699 | + Profiles = new Dictionary<string, LaunchProfile> |
| 1700 | + { |
| 1701 | + ["funcapp"] = new() |
| 1702 | + { |
| 1703 | + CommandLineArgs = "--port 7071", |
| 1704 | + LaunchBrowser = false, |
| 1705 | + } |
| 1706 | + } |
| 1707 | + }; |
| 1708 | + } |
| 1709 | + |
| 1710 | + [Fact] |
| 1711 | + public async Task CanMixContainerAppsAndJobsInSameManifest() |
| 1712 | + { |
| 1713 | + var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); |
| 1714 | + builder.AddAzureContainerAppEnvironment("env"); |
| 1715 | + |
| 1716 | + builder.AddContainer("web", "nginx:latest") |
| 1717 | + .PublishAsAzureContainerApp((infra, app) => { }); |
| 1718 | + |
| 1719 | + builder.AddContainer("batch", "image:latest") |
| 1720 | + .PublishAsAzureContainerAppJob((infra, job) => |
| 1721 | + { |
| 1722 | + job.Configuration.TriggerType = ContainerAppJobTriggerType.Manual; |
| 1723 | + }); |
| 1724 | + |
| 1725 | + using var app = builder.Build(); |
| 1726 | + await ExecuteBeforeStartHooksAsync(app, default); |
| 1727 | + |
| 1728 | + var model = app.Services.GetRequiredService<DistributedApplicationModel>(); |
| 1729 | + var containers = model.GetContainerResources().ToArray(); |
| 1730 | + Assert.Equal(2, containers.Length); |
| 1731 | + |
| 1732 | + var batch = containers.First(c => c.Name == "batch"); |
| 1733 | + var web = containers.First(c => c.Name == "web"); |
| 1734 | + |
| 1735 | + var batchTarget = batch.Annotations.OfType<DeploymentTargetAnnotation>().FirstOrDefault(); |
| 1736 | + var webTarget = web.Annotations.OfType<DeploymentTargetAnnotation>().FirstOrDefault(); |
| 1737 | + |
| 1738 | + var batchResource = batchTarget?.DeploymentTarget as AzureProvisioningResource; |
| 1739 | + var webResource = webTarget?.DeploymentTarget as AzureProvisioningResource; |
| 1740 | + |
| 1741 | + Assert.NotNull(batchResource); |
| 1742 | + Assert.NotNull(webResource); |
| 1743 | + |
| 1744 | + var (batchManifest, batchBicep) = await GetManifestWithBicep(batchResource); |
| 1745 | + var (webManifest, webBicep) = await GetManifestWithBicep(webResource); |
| 1746 | + |
| 1747 | + Assert.Contains("Microsoft.App/jobs", batchBicep); |
| 1748 | + Assert.Contains("Microsoft.App/containerApps", webBicep); |
| 1749 | + } |
1653 | 1750 | }
|
0 commit comments