Skip to content

Commit 198ddc8

Browse files
2 parents 155d295 + 51c2d70 commit 198ddc8

File tree

4 files changed

+72
-71
lines changed

4 files changed

+72
-71
lines changed

.github/workflows/docker-build-and-push.yml

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
- dev
1919
- demo
2020
- hotfix
21-
workflow_dispatch:
21+
workflow_dispatch:
2222

2323
jobs:
2424
build-and-push:
@@ -32,14 +32,19 @@ jobs:
3232
uses: docker/setup-buildx-action@v1
3333

3434
- name: Log in to Azure Container Registry
35-
if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix') }}
35+
if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
3636
uses: azure/docker-login@v2
3737
with:
3838
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
3939
username: ${{ secrets.ACR_USERNAME }}
4040
password: ${{ secrets.ACR_PASSWORD }}
4141

42-
- name: Set Docker image tag
42+
- name: Get current date
43+
id: date
44+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
45+
46+
- name: Determine Tag Name Based on Branch
47+
id: determine_tag
4348
run: |
4449
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
4550
echo "TAG=latest" >> $GITHUB_ENV
@@ -52,24 +57,30 @@ jobs:
5257
else
5358
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
5459
fi
55-
56-
- name: Build and push Docker images optionally
60+
61+
- name: Set Historical Tag
5762
run: |
58-
cd src/backend
59-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \
60-
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then
61-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \
62-
echo "Backend image built and pushed successfully."
63-
else
64-
echo "Skipping Docker push for backend with tag: ${{ env.TAG }}"
65-
fi
66-
cd ../frontend
67-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \
68-
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then
69-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \
70-
echo "Frontend image built and pushed successfully."
71-
else
72-
echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}"
73-
fi
63+
DATE_TAG=$(date +'%Y-%m-%d')
64+
RUN_ID=${{ github.run_number }}
65+
# Create historical tag using TAG, DATE_TAG, and RUN_ID
66+
echo "HISTORICAL_TAG=${{ env.TAG }}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV
7467
75-
68+
- name: Build and optionally push Backend Docker image
69+
uses: docker/build-push-action@v6
70+
with:
71+
context: ./src/backend
72+
file: ./src/backend/Dockerfile
73+
push: ${{ env.TAG != 'pullrequest-ignore' }}
74+
tags: |
75+
${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }}
76+
${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }}
77+
78+
- name: Build and optionally push Frontend Docker image
79+
uses: docker/build-push-action@v6
80+
with:
81+
context: ./src/frontend
82+
file: ./src/frontend/Dockerfile
83+
push: ${{ env.TAG != 'pullrequest-ignore' }}
84+
tags: |
85+
${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }}
86+
${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }}

infra/deploy_ai_foundry.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ param gptModelName string
66
param gptModelVersion string
77
param managedIdentityObjectId string
88
param aiServicesEndpoint string
9-
param aiServicesKey string
9+
param aiServices object
1010
param aiServicesId string
1111

1212
var storageName = '${solutionName}hubstorage'
@@ -136,7 +136,7 @@ resource aiHub 'Microsoft.MachineLearningServices/workspaces@2023-08-01-preview'
136136
authType: 'ApiKey'
137137
isSharedToAll: true
138138
credentials: {
139-
key: aiServicesKey
139+
key: aiServices.Key.key1
140140
}
141141
metadata: {
142142
ApiType: 'Azure'
@@ -187,7 +187,7 @@ resource azureOpenAIApiKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-pr
187187
parent: keyVault
188188
name: 'AZURE-OPENAI-KEY'
189189
properties: {
190-
value: aiServicesKey //aiServices_m.listKeys().key1
190+
value: aiServices.Key.key1 //aiServices_m.listKeys().key1
191191
}
192192
}
193193

@@ -251,7 +251,7 @@ resource cogServiceKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-previe
251251
parent: keyVault
252252
name: 'COG-SERVICES-KEY'
253253
properties: {
254-
value: aiServicesKey
254+
value: aiServices.Key.key1
255255
}
256256
}
257257

infra/main.bicep

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ param azureOpenAILocation string //= 'eastus2' // The location used for all depl
3232

3333
@minLength(3)
3434
@maxLength(20)
35-
@description('A unique prefix for all resources in this deployment. This should be 3-20 characters long:')
36-
param environmentName string
37-
38-
var uniqueId = toLower(uniqueString(subscription().id, environmentName, resourceGroup().location))
39-
var solutionPrefix = 'ma${padLeft(take(uniqueId, 12), 12, '0')}'
35+
@description('Prefix for all resources created by this template. This prefix will be used to create unique names for all resources. The prefix must be unique within the resource group.')
36+
param prefix string //= 'macae'
4037

4138
@description('Tags to apply to all deployed resources')
4239
param tags object = {}
@@ -63,7 +60,7 @@ param capacity int = 140
6360

6461
var location = resourceGroup().location
6562
var modelVersion = '2024-08-06'
66-
var aiServicesName = '${solutionPrefix}-aiservices'
63+
var aiServicesName = '${prefix}-aiservices'
6764
var deploymentType = 'GlobalStandard'
6865
var gptModelVersion = 'gpt-4o'
6966
var appVersion = 'fnd01'
@@ -74,7 +71,7 @@ var dockerRegistryUrl = 'https://${resgistryName}.azurecr.io'
7471
var backendDockerImageURL = '${resgistryName}.azurecr.io/macaebackend:${appVersion}'
7572
var frontendDockerImageURL = '${resgistryName}.azurecr.io/macaefrontend:${appVersion}'
7673

77-
var uniqueNameFormat = '${solutionPrefix}-{0}-${uniqueString(resourceGroup().id, solutionPrefix)}'
74+
var uniqueNameFormat = '${prefix}-{0}-${uniqueString(resourceGroup().id, prefix)}'
7875
var aoaiApiVersion = '2025-01-01-preview'
7976

8077
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
@@ -124,7 +121,7 @@ resource aiServices 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' =
124121
apiProperties: {
125122
//statisticsEnabled: false
126123
}
127-
//disableLocalAuth: true
124+
disableLocalAuth: true
128125
}
129126
}
130127

@@ -150,7 +147,7 @@ resource aiServicesDeployments 'Microsoft.CognitiveServices/accounts/deployments
150147
module kvault 'deploy_keyvault.bicep' = {
151148
name: 'deploy_keyvault'
152149
params: {
153-
solutionName: solutionPrefix
150+
solutionName: prefix
154151
solutionLocation: location
155152
managedIdentityObjectId: managedIdentityModule.outputs.managedIdentityOutput.objectId
156153
}
@@ -164,14 +161,14 @@ module kvault 'deploy_keyvault.bicep' = {
164161
module aifoundry 'deploy_ai_foundry.bicep' = {
165162
name: 'deploy_ai_foundry'
166163
params: {
167-
solutionName: solutionPrefix
164+
solutionName: prefix
168165
solutionLocation: azureOpenAILocation
169166
keyVaultName: kvault.outputs.keyvaultName
170167
gptModelName: gptModelVersion
171168
gptModelVersion: gptModelVersion
172169
managedIdentityObjectId: managedIdentityModule.outputs.managedIdentityOutput.objectId
173170
aiServicesEndpoint: aiServices.properties.endpoint
174-
aiServicesKey: aiServices.listKeys().key1
171+
aiServices: aiServices
175172
aiServicesId: aiServices.id
176173
}
177174
scope: resourceGroup(resourceGroup().name)
@@ -206,7 +203,7 @@ resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' = {
206203
}
207204
]
208205
capabilities: [{ name: 'EnableServerless' }]
209-
//disableLocalAuth: true
206+
disableLocalAuth: true
210207
}
211208

212209
resource contributorRoleDefinition 'sqlRoleDefinitions' existing = {
@@ -280,7 +277,7 @@ resource acaCosomsRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleA
280277

281278
@description('')
282279
resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
283-
name: '${solutionPrefix}-backend'
280+
name: '${prefix}-backend'
284281
location: location
285282
tags: tags
286283
identity: {
@@ -449,7 +446,7 @@ resource frontendAppService 'Microsoft.Web/sites@2021-02-01' = {
449446
}
450447

451448
resource aiHubProject 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' existing = {
452-
name: '${solutionPrefix}-aiproject' // aiProjectName must be calculated - available at main start.
449+
name: '${prefix}-aiproject' // aiProjectName must be calculated - available at main start.
453450
}
454451

455452
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
@@ -470,7 +467,7 @@ var cosmosAssignCli = 'az cosmosdb sql role assignment create --resource-group "
470467
module managedIdentityModule 'deploy_managed_identity.bicep' = {
471468
name: 'deploy_managed_identity'
472469
params: {
473-
solutionName: solutionPrefix
470+
solutionName: prefix
474471
//solutionLocation: location
475472
managedIdentityId: pullIdentity.id
476473
managedIdentityPropPrin: pullIdentity.properties.principalId

0 commit comments

Comments
 (0)