-
Notifications
You must be signed in to change notification settings - Fork 756
[release/9.0] Fixed AddDockerFile to work with compute customization #6446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Use an official Python runtime as a parent image | ||
| FROM python:3.8-slim | ||
|
|
||
| # Set the working directory in the container | ||
| WORKDIR /app | ||
|
|
||
| # Copy the current directory contents into the container at /app | ||
| COPY . /app | ||
|
|
||
| # Run the command to execute app.py when the container starts | ||
| CMD ["python", "app.py"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import time | ||
| from datetime import datetime | ||
|
|
||
| while True: | ||
| print(datetime.now(), flush=True) | ||
| time.sleep(3) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| @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 | ||
|
|
||
| param outputs_azure_container_registry_endpoint string | ||
|
|
||
| param pythonapp_containerimage string | ||
|
|
||
| resource pythonapp 'Microsoft.App/containerApps@2024-03-01' = { | ||
| name: 'pythonapp' | ||
| location: location | ||
| properties: { | ||
| configuration: { | ||
| activeRevisionsMode: 'Single' | ||
| registries: [ | ||
| { | ||
| server: outputs_azure_container_registry_endpoint | ||
| identity: outputs_azure_container_registry_managed_identity_id | ||
| } | ||
| ] | ||
| } | ||
| environmentId: outputs_azure_container_apps_environment_id | ||
| template: { | ||
| containers: [ | ||
| { | ||
| image: pythonapp_containerimage | ||
| name: 'pythonapp' | ||
| 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}': { } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,114 @@ param outputs_azure_container_apps_environment_id string | |
| Assert.Equal(expectedBicep, bicep); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task AddDockerfileWithAppsInfrastructureAddsDeploymentTargetWithContainerAppToContainerResources() | ||
| { | ||
| var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); | ||
|
|
||
| builder.AddAzureContainerAppsInfrastructure(); | ||
|
|
||
| var directory = Directory.CreateTempSubdirectory(".aspire-test"); | ||
|
|
||
| // Contents of the Dockerfile are not important for this test | ||
| File.WriteAllText(Path.Combine(directory.FullName, "Dockerfile"), ""); | ||
|
|
||
| builder.AddDockerfile("api", directory.FullName); | ||
|
|
||
| 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 m = manifest.ToString(); | ||
|
|
||
| var expectedManifest = | ||
| """ | ||
| { | ||
| "type": "azure.bicep.v0", | ||
| "path": "api.module.bicep", | ||
| "params": { | ||
| "outputs_azure_container_registry_managed_identity_id": "{.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID}", | ||
| "outputs_managed_identity_client_id": "{.outputs.MANAGED_IDENTITY_CLIENT_ID}", | ||
| "outputs_azure_container_apps_environment_id": "{.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_ID}", | ||
| "outputs_azure_container_registry_endpoint": "{.outputs.AZURE_CONTAINER_REGISTRY_ENDPOINT}", | ||
| "api_containerimage": "{api.containerImage}" | ||
| } | ||
| } | ||
| """; | ||
|
Comment on lines
+131
to
+152
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be baselining the entire resource's manifest? And not just the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could but it's not really relevant for this test.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "pythonapp": {
"type": "container.v1",
"build": {
"context": "AppWithDocker",
"dockerfile": "AppWithDocker/Dockerfile"
},I don't understand how that part isn't relevant. Seems pretty important for the scenario to work. |
||
|
|
||
| Assert.Equal(expectedManifest, m); | ||
|
|
||
| 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 | ||
|
|
||
| param outputs_azure_container_registry_endpoint string | ||
|
|
||
| param api_containerimage string | ||
|
|
||
| resource api 'Microsoft.App/containerApps@2024-03-01' = { | ||
| name: 'api' | ||
| location: location | ||
| properties: { | ||
| configuration: { | ||
| activeRevisionsMode: 'Single' | ||
| registries: [ | ||
| { | ||
| server: outputs_azure_container_registry_endpoint | ||
| identity: outputs_azure_container_registry_managed_identity_id | ||
| } | ||
| ] | ||
| } | ||
| environmentId: outputs_azure_container_apps_environment_id | ||
| template: { | ||
| containers: [ | ||
| { | ||
| image: api_containerimage | ||
| name: 'api' | ||
| 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 AddContainerAppsInfrastructureAddsDeploymentTargetWithContainerAppToProjectResources() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change.