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 @@ -12,13 +12,13 @@ namespace Aspire.Deployment.EndToEnd.Tests;
/// TypeScript-AppHost variant of the AKS cert-manager E2E test. Mirrors
/// <see cref="AksAzureKubernetesEnvironmentCertManagerDeploymentTests"/> but uses the
/// TypeScript Express/React starter (<c>aspire new</c> --&gt; <c>Starter App (Express/React, TypeScript AppHost)</c>)
/// and patches <c>apphost.ts</c> to wire <c>addAzureKubernetesEnvironment</c> +
/// and patches <c>apphost.mts</c> to wire <c>addAzureKubernetesEnvironment</c> +
/// <c>addCertManager</c> + <c>addIssuer().withLetsEncryptProductionParam(acmeEmail).withHttp01Solver()</c>
/// + <c>gateway.withGatewayTlsIssuer(letsEncrypt)</c> around the Express API.
///
/// Proves that the cert-manager API surface generated for TypeScript via <c>[AspireExport]</c>
/// works end-to-end against a real AKS cluster (this complements the polyglot type-check
/// validation in <c>tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.ts</c>).
/// validation in <c>tests/PolyglotAppHosts/Aspire.Hosting.Kubernetes/TypeScript/apphost.mts</c>).
///
/// Uses Let's Encrypt <em>production</em> so the served cert chains to a publicly-trusted root
/// (mirrors a realistic deployment). Production is rate-limited (50 certs / registered
Expand Down Expand Up @@ -117,7 +117,7 @@ private async Task DeployTypeScriptApiWithCertManagerToAzureKubernetesEnvironmen
await auto.WaitForSuccessPromptAsync(counter, TimeSpan.FromSeconds(180));
}

// Patch apphost.ts. The Express/React starter creates an Express API at ./api
// Patch apphost.mts. The Express/React starter creates an Express API at ./api
// exposing an HTTP endpoint, plus a Vite frontend bundled in for publish. We
// replace the trailing `await builder.build().run();` with the AKS + cert-manager
// wiring that puts the API behind a Gateway with TLS issued by Let's Encrypt production.
Expand All @@ -129,9 +129,11 @@ private async Task DeployTypeScriptApiWithCertManagerToAzureKubernetesEnvironmen
// addGateway / withLoadBalancer / withRoute / withGatewayTlsIssuer
// publishAsKubernetesService / addManifest
var projectDir = Path.Combine(workspace.WorkspaceRoot.FullName, projectName);
var appHostFilePath = Path.Combine(projectDir, "apphost.ts");
// The TypeScript starter templates (including Express/React) emit apphost.mts
// since PR #16984. Reading apphost.ts here would fail with FileNotFoundException.
var appHostFilePath = Path.Combine(projectDir, "apphost.mts");

output.WriteLine($"Step 6: Modifying apphost.ts at: {appHostFilePath}");
output.WriteLine($"Step 6: Modifying apphost.mts at: {appHostFilePath}");

var content = File.ReadAllText(appHostFilePath);

Expand Down Expand Up @@ -190,7 +192,7 @@ await manifest

content = content.Replace(buildRunPattern, replacement);
File.WriteAllText(appHostFilePath, content);
output.WriteLine("Modified apphost.ts with addCertManager + addIssuer + withGatewayTlsIssuer");
output.WriteLine("Modified apphost.mts with addCertManager + addIssuer + withGatewayTlsIssuer");

output.WriteLine("Step 7: Setting deployment environment variables...");
await auto.TypeAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ private static async Task AddPackageAsync(Hex1bTerminalAutomator auto, SequenceC

private static void WriteContainerAppJobsAppHost(TemporaryWorkspace workspace)
{
File.WriteAllText(Path.Combine(workspace.WorkspaceRoot.FullName, "apphost.ts"), """
import { createBuilder } from './.aspire/modules/aspire.js';
// `aspire init --language typescript` creates apphost.mts (since PR #16984), not
// apphost.ts. Overwrite that file with the test's custom AppHost; otherwise
// `aspire deploy` runs against the empty default apphost.mts and no Azure
// resources get provisioned. The mts variant imports the generated SDK as
// `aspire.mjs` (not `aspire.js`, which is the legacy apphost.ts shape).
File.WriteAllText(Path.Combine(workspace.WorkspaceRoot.FullName, "apphost.mts"), """
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ private static void WriteStaticWebsiteWithNodeApiAppHost(TemporaryWorkspace work
</html>
""");

File.WriteAllText(Path.Combine(workspace.WorkspaceRoot.FullName, "apphost.ts"), """
import { createBuilder } from './.aspire/modules/aspire.js';
// `aspire init --language typescript` creates apphost.mts (since PR #16984), not
// apphost.ts. Overwrite that file with the test's custom AppHost; otherwise
// `aspire deploy` runs against the empty default apphost.mts and no Azure
// resources get provisioned. The mts variant imports the generated SDK as
// `aspire.mjs` (not `aspire.js`, which is the legacy apphost.ts shape).
File.WriteAllText(Path.Combine(workspace.WorkspaceRoot.FullName, "apphost.mts"), """
import { createBuilder } from './.aspire/modules/aspire.mjs';

const builder = await createBuilder();

Expand Down
Loading