Skip to content

Commit d4691aa

Browse files
authored
Support args on container.{v0,v1} (#4236)
We were not handling the `args` property on `container.v0` or `container.v1` resources. This adds support and a test to confirm we don't regress. Fixes #4220
1 parent fee5a78 commit d4691aa

File tree

6 files changed

+181
-2
lines changed

6 files changed

+181
-2
lines changed

cli/azd/pkg/apphost/generate.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func Containers(manifest *Manifest) map[string]genContainer {
154154
Inputs: comp.Inputs,
155155
Volumes: comp.Volumes,
156156
BindMounts: comp.BindMounts,
157+
Args: comp.Args,
157158
}
158159
}
159160
}
@@ -543,7 +544,7 @@ func (b *infraGenerator) LoadManifest(m *Manifest) error {
543544
case "project.v0":
544545
b.addProject(name, *comp.Path, comp.Env, comp.Bindings, comp.Args)
545546
case "container.v0":
546-
b.addContainer(name, *comp.Image, comp.Env, comp.Bindings, comp.Inputs, comp.Volumes, comp.BindMounts)
547+
b.addContainer(name, *comp.Image, comp.Env, comp.Bindings, comp.Inputs, comp.Volumes, comp.BindMounts, comp.Args)
547548
case "dapr.v0":
548549
err := b.addDapr(name, comp.Dapr)
549550
if err != nil {
@@ -836,7 +837,8 @@ func (b *infraGenerator) addContainer(
836837
bindings custommaps.WithOrder[Binding],
837838
inputs map[string]Input,
838839
volumes []*Volume,
839-
bindMounts []*BindMount) {
840+
bindMounts []*BindMount,
841+
args []string) {
840842
b.requireCluster()
841843

842844
if len(volumes) > 0 {
@@ -855,6 +857,7 @@ func (b *infraGenerator) addContainer(
855857
Inputs: inputs,
856858
Volumes: volumes,
857859
BindMounts: bindMounts,
860+
Args: args,
858861
}
859862
}
860863

@@ -1157,6 +1160,10 @@ func (b *infraGenerator) Compile() error {
11571160
return fmt.Errorf("configuring environment for resource %s: %w", resourceName, err)
11581161
}
11591162

1163+
if err := b.buildArgsBlock(container.Args, &projectTemplateCtx); err != nil {
1164+
return err
1165+
}
1166+
11601167
b.containerAppTemplateContexts[resourceName] = projectTemplateCtx
11611168
}
11621169

@@ -1180,6 +1187,10 @@ func (b *infraGenerator) Compile() error {
11801187
return fmt.Errorf("configuring environment for resource %s: %w", resourceName, err)
11811188
}
11821189

1190+
if err := b.buildArgsBlock(bc.Args, &projectTemplateCtx); err != nil {
1191+
return err
1192+
}
1193+
11831194
b.containerAppTemplateContexts[resourceName] = projectTemplateCtx
11841195
}
11851196

cli/azd/pkg/apphost/generate_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var aspireBicepManifest []byte
3333
//go:embed testdata/aspire-container.json
3434
var aspireContainerManifest []byte
3535

36+
//go:embed testdata/aspire-container-args.json
37+
var aspireContainerArgsManifest []byte
38+
3639
// mockPublishManifest mocks the dotnet run --publisher manifest command to return a fixed manifest.
3740
func mockPublishManifest(mockCtx *mocks.MockContext, manifest []byte, files map[string]string) {
3841
mockCtx.CommandRunner.When(func(args exec.RunArgs, command string) bool {
@@ -258,6 +261,28 @@ func TestAspireContainerGeneration(t *testing.T) {
258261
require.NoError(t, err)
259262
}
260263

264+
func TestAspireContainerArgs(t *testing.T) {
265+
if runtime.GOOS == "windows" {
266+
t.Skip("Skipping due to EOL issues on Windows with the baselines")
267+
}
268+
269+
ctx := context.Background()
270+
mockCtx := mocks.NewMockContext(ctx)
271+
mockPublishManifest(mockCtx, aspireContainerArgsManifest, nil)
272+
mockCli := dotnet.NewCli(mockCtx.CommandRunner)
273+
274+
m, err := ManifestFromAppHost(ctx, filepath.Join("testdata", "AspireDocker.AppHost.csproj"), mockCli, "")
275+
require.NoError(t, err)
276+
277+
for _, name := range []string{"container0", "container1"} {
278+
t.Run(name, func(t *testing.T) {
279+
tmpl, err := ContainerAppManifestTemplateForProject(m, name, AppHostOptions{})
280+
require.NoError(t, err)
281+
snapshot.SnapshotT(t, tmpl)
282+
})
283+
}
284+
}
285+
261286
func TestEvaluateForOutputs(t *testing.T) {
262287
value := "{resource.outputs.output1} and {resource.secretOutputs.output2}"
263288

cli/azd/pkg/apphost/generate_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type genContainer struct {
4444
Inputs map[string]Input
4545
Volumes []*Volume
4646
BindMounts []*BindMount
47+
Args []string
4748
}
4849

4950
type genDockerfile struct {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
api-version: 2024-02-02-preview
2+
location: {{ .Env.AZURE_LOCATION }}
3+
identity:
4+
type: UserAssigned
5+
userAssignedIdentities:
6+
? "{{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}"
7+
: {}
8+
properties:
9+
environmentId: {{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_ID }}
10+
configuration:
11+
activeRevisionsMode: single
12+
runtime:
13+
dotnet:
14+
autoConfigureDataProtection: true
15+
ingress:
16+
additionalPortMappings:
17+
- targetPort: 3306
18+
external: false
19+
external: false
20+
targetPort: {{ targetPortOrDefault 80 }}
21+
transport: http
22+
allowInsecure: true
23+
registries:
24+
- server: {{ .Env.AZURE_CONTAINER_REGISTRY_ENDPOINT }}
25+
identity: {{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}
26+
template:
27+
containers:
28+
- image: {{ .Image }}
29+
name: container0
30+
args:
31+
- arg1
32+
- https://project.internal.{{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}
33+
env:
34+
- name: AZURE_CLIENT_ID
35+
value: {{ .Env.MANAGED_IDENTITY_CLIENT_ID }}
36+
scale:
37+
minReplicas: 1
38+
tags:
39+
azd-service-name: container0
40+
aspire-resource-name: container0
41+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
api-version: 2024-02-02-preview
2+
location: {{ .Env.AZURE_LOCATION }}
3+
identity:
4+
type: UserAssigned
5+
userAssignedIdentities:
6+
? "{{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}"
7+
: {}
8+
properties:
9+
environmentId: {{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_ID }}
10+
configuration:
11+
activeRevisionsMode: single
12+
runtime:
13+
dotnet:
14+
autoConfigureDataProtection: true
15+
ingress:
16+
additionalPortMappings:
17+
- targetPort: 3306
18+
external: false
19+
external: false
20+
targetPort: {{ targetPortOrDefault 8080 }}
21+
transport: http
22+
allowInsecure: true
23+
registries:
24+
- server: {{ .Env.AZURE_CONTAINER_REGISTRY_ENDPOINT }}
25+
identity: {{ .Env.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}
26+
template:
27+
containers:
28+
- image: {{ .Image }}
29+
name: container1
30+
args:
31+
- arg1
32+
- https://project.internal.{{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}
33+
env:
34+
- name: AZURE_CLIENT_ID
35+
value: {{ .Env.MANAGED_IDENTITY_CLIENT_ID }}
36+
scale:
37+
minReplicas: 1
38+
tags:
39+
azd-service-name: container1
40+
aspire-resource-name: container1
41+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"resources": {
3+
"project" : {
4+
"type": "project.v0",
5+
"path": "../Test1.Web/Test1.Web.csproj",
6+
"env": {
7+
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
8+
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true"
9+
},
10+
"bindings": {
11+
"http": {
12+
"scheme": "http",
13+
"protocol": "tcp",
14+
"transport": "http"
15+
},
16+
"https": {
17+
"scheme": "https",
18+
"protocol": "tcp",
19+
"transport": "http"
20+
}
21+
}
22+
},
23+
"container0": {
24+
"type": "container.v0",
25+
"image": "mysql:latest",
26+
"args": [ "arg1", "{project.bindings.https.url}" ],
27+
"bindings": {
28+
"tcp": {
29+
"scheme": "tcp",
30+
"protocol": "tcp",
31+
"transport": "tcp",
32+
"targetPort": 3306
33+
},
34+
"http" : {
35+
"scheme": "http",
36+
"protocol": "http",
37+
"transport": "http"
38+
}
39+
}
40+
},
41+
"container1": {
42+
"type": "container.v1",
43+
"image": "mysql:latest",
44+
"args": [ "arg1", "{project.bindings.https.url}" ],
45+
"bindings": {
46+
"tcp": {
47+
"scheme": "tcp",
48+
"protocol": "tcp",
49+
"transport": "tcp",
50+
"targetPort": 3306
51+
},
52+
"http" : {
53+
"scheme": "http",
54+
"protocol": "http",
55+
"transport": "http"
56+
}
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)