Skip to content

Commit 1e29231

Browse files
committed
feat: refactor traffic management logic to use traffic entry variables for preview and production
1 parent de9ddab commit 1e29231

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

infra/api.bicep

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ var previewLabel = activeLabel == 'blue' ? 'green' : 'blue'
4242
var productionLabel = promotePreview ? previewLabel : activeLabel
4343
var targetLabel = promotePreview ? productionLabel : previewLabel
4444
var useLatestForProductionTraffic = promotePreview || empty(productionRevisionName)
45+
var previewTrafficEntry = {
46+
label: previewLabel
47+
latestRevision: true
48+
weight: 0
49+
}
50+
var productionTrafficEntry = useLatestForProductionTraffic
51+
? {
52+
label: productionLabel
53+
latestRevision: true
54+
weight: 100
55+
}
56+
: {
57+
label: productionLabel
58+
revisionName: productionRevisionName
59+
weight: 100
60+
}
4561

4662
var apiEnvironmentVariables = [
4763
{
@@ -98,23 +114,11 @@ resource containerApp 'Microsoft.App/containerApps@2025-10-02-preview' = {
98114
external: true
99115
targetPort: 8080
100116
allowInsecure: false
101-
traffic: [
102-
{
103-
label: previewLabel
104-
latestRevision: true
105-
weight: 0
106-
}
107-
useLatestForProductionTraffic
108-
? {
109-
label: productionLabel
110-
latestRevision: true
111-
weight: 100
112-
}
113-
: {
114-
label: productionLabel
115-
revisionName: productionRevisionName
116-
weight: 100
117-
}
117+
traffic: promotePreview ? [
118+
productionTrafficEntry
119+
] : [
120+
previewTrafficEntry
121+
productionTrafficEntry
118122
]
119123
}
120124
dapr: {

infra/ui.bicep

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ var previewLabel = activeLabel == 'blue' ? 'green' : 'blue'
2121
var productionLabel = promotePreview ? previewLabel : activeLabel
2222
var targetLabel = promotePreview ? productionLabel : previewLabel
2323
var useLatestForProductionTraffic = promotePreview || empty(productionRevisionName)
24+
var previewTrafficEntry = {
25+
label: previewLabel
26+
latestRevision: true
27+
weight: 0
28+
}
29+
var productionTrafficEntry = useLatestForProductionTraffic
30+
? {
31+
label: productionLabel
32+
latestRevision: true
33+
weight: 100
34+
}
35+
: {
36+
label: productionLabel
37+
revisionName: productionRevisionName
38+
weight: 100
39+
}
2440

2541
resource containerApp 'Microsoft.App/containerApps@2025-10-02-preview' = {
2642
name: containerAppName
@@ -50,23 +66,11 @@ resource containerApp 'Microsoft.App/containerApps@2025-10-02-preview' = {
5066
external: true
5167
targetPort: 80
5268
allowInsecure: false
53-
traffic: [
54-
{
55-
label: previewLabel
56-
latestRevision: true
57-
weight: 0
58-
}
59-
useLatestForProductionTraffic
60-
? {
61-
label: productionLabel
62-
latestRevision: true
63-
weight: 100
64-
}
65-
: {
66-
label: productionLabel
67-
revisionName: productionRevisionName
68-
weight: 100
69-
}
69+
traffic: promotePreview ? [
70+
productionTrafficEntry
71+
] : [
72+
previewTrafficEntry
73+
productionTrafficEntry
7074
]
7175
}
7276
}

0 commit comments

Comments
 (0)