Skip to content

Commit 0f94547

Browse files
committed
ok...
1 parent 556ab28 commit 0f94547

File tree

13 files changed

+533
-3
lines changed

13 files changed

+533
-3
lines changed

.github/workflows/build_push_AKS.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,23 @@ jobs:
6767
with:
6868
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
6969
resourceGroupName: ${{ env.RESOURCE_GROUP }}
70-
template: IaC/acr.bicep
70+
template: azd/modules/acr.bicep
7171
parameters: "registryName=${{ env.AZURE_CONTAINER_REGISTRY }}"
7272
failOnStdErr: false # Deploy AKS using Bicep
7373
- name: Deploy AKS using Bicep
7474
uses: azure/arm-deploy@v2
7575
with:
7676
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
7777
resourceGroupName: ${{ env.RESOURCE_GROUP }}
78-
template: IaC/aks.bicep
78+
template: azd/modules/aks.bicep
7979
parameters: "aksClusterName=${{ env.CLUSTER_NAME }} acrResourceId=/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.RESOURCE_GROUP }}/providers/Microsoft.ContainerRegistry/registries/${{ env.AZURE_CONTAINER_REGISTRY }}"
8080
failOnStdErr: false
8181

82+
# Ensures AKS has access to the ACR
83+
- name: Ensure AKS has access to the ACR # REcommended permission is Role Based Access Control Administrator
84+
run: |
85+
az aks update --name ${{ env.CLUSTER_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --attach-acr ${{ env.AZURE_CONTAINER_REGISTRY }}
86+
8287
# Builds and pushes an image up to your Azure Container Registry
8388
- name: Build and push image to ACR
8489
run: |

.github/workflows/deploy_to_aca.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This workflow will build and deploy an application to Azure Container Apps (ACA)
2+
# It uses the same container registry as the AKS deployment workflow
3+
4+
name: Deploy to ACA
5+
6+
on:
7+
push:
8+
branches: ["aca-deploy"]
9+
workflow_dispatch:
10+
11+
env:
12+
AZURE_CONTAINER_REGISTRY: "jaz400acr"
13+
CONTAINER_NAME: "docker-app"
14+
RESOURCE_GROUP: "az400"
15+
ACA_NAME: "docker-app-aca"
16+
17+
jobs:
18+
buildAndDeploy:
19+
permissions:
20+
contents: read
21+
id-token: write
22+
runs-on: ubuntu-latest
23+
environment: production
24+
steps:
25+
# Checks out the repository this file is in
26+
- uses: actions/checkout@v4
27+
28+
# Logs in with your Azure credentials
29+
- name: Azure login
30+
uses: azure/login@v2
31+
with:
32+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
33+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
34+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
35+
enable-AzPSSession: true
36+
37+
# Deploy ACR using Bicep if it doesn't exist
38+
- name: Deploy ACR using Bicep
39+
uses: azure/arm-deploy@v2
40+
with:
41+
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
42+
resourceGroupName: ${{ env.RESOURCE_GROUP }}
43+
template: IaC/acr.bicep
44+
parameters: "registryName=${{ env.AZURE_CONTAINER_REGISTRY }}"
45+
failOnStdErr: false
46+
47+
# Builds and pushes an image up to your Azure Container Registry
48+
- name: Build and push image to ACR
49+
run: |
50+
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:latest --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
51+
52+
# Deploy to Azure Container Apps using Bicep
53+
- name: Deploy to Azure Container Apps
54+
uses: azure/arm-deploy@v2
55+
with:
56+
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
57+
resourceGroupName: ${{ env.RESOURCE_GROUP }}
58+
template: IaC/aca.bicep
59+
parameters: >
60+
containerAppName=${{ env.ACA_NAME }}
61+
acrName=${{ env.AZURE_CONTAINER_REGISTRY }}
62+
imageName=${{ env.CONTAINER_NAME }}
63+
failOnStdErr: false
64+
65+
# Get Container App URL for output
66+
- name: Get Container App URL
67+
id: get-aca-url
68+
run: |
69+
ACA_URL=$(az containerapp show --name ${{ env.ACA_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --query properties.configuration.ingress.fqdn -o tsv)
70+
echo "Container App is accessible at: https://$ACA_URL"
71+
echo "ACA_URL=$ACA_URL" >> $GITHUB_OUTPUT
72+
73+
- name: Output deployment URL
74+
run: echo "Application deployed to https://${{ steps.get-aca-url.outputs.ACA_URL }}"

.github/workflows/deploy_to_aci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This workflow will build and deploy an application to Azure Container Instances (ACI)
2+
# It uses the same container registry as the AKS deployment workflow
3+
4+
name: Deploy to ACI
5+
6+
on:
7+
push:
8+
branches: ["aci-deploy"]
9+
workflow_dispatch:
10+
11+
env:
12+
AZURE_CONTAINER_REGISTRY: "jaz400acr"
13+
CONTAINER_NAME: "docker-app"
14+
RESOURCE_GROUP: "az400"
15+
ACI_NAME: "docker-app-aci"
16+
17+
jobs:
18+
buildAndDeploy:
19+
permissions:
20+
contents: read
21+
id-token: write
22+
runs-on: ubuntu-latest
23+
environment: production
24+
steps:
25+
# Checks out the repository this file is in
26+
- uses: actions/checkout@v4
27+
28+
# Logs in with your Azure credentials
29+
- name: Azure login
30+
uses: azure/login@v2
31+
with:
32+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
33+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
34+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
35+
enable-AzPSSession: true
36+
37+
# Deploy ACR using Bicep if it doesn't exist
38+
- name: Deploy ACR using Bicep
39+
uses: azure/arm-deploy@v2
40+
with:
41+
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
42+
resourceGroupName: ${{ env.RESOURCE_GROUP }}
43+
template: IaC/acr.bicep
44+
parameters: "registryName=${{ env.AZURE_CONTAINER_REGISTRY }}"
45+
failOnStdErr: false
46+
47+
# Builds and pushes an image up to your Azure Container Registry
48+
- name: Build and push image to ACR
49+
run: |
50+
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:latest --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
51+
52+
# Deploy to ACI using Bicep
53+
- name: Deploy to Azure Container Instances
54+
uses: azure/arm-deploy@v2
55+
with:
56+
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
57+
resourceGroupName: ${{ env.RESOURCE_GROUP }}
58+
template: IaC/aci.bicep
59+
parameters: >
60+
containerInstanceName=${{ env.ACI_NAME }}
61+
acrName=${{ env.AZURE_CONTAINER_REGISTRY }}
62+
imageName=${{ env.CONTAINER_NAME }}
63+
failOnStdErr: false
64+
65+
# Get ACI IP address for output
66+
- name: Get ACI IP Address
67+
id: get-aci-ip
68+
run: |
69+
IP_ADDRESS=$(az container show --name ${{ env.ACI_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --query ipAddress.ip -o tsv)
70+
echo "Container is accessible at: http://$IP_ADDRESS"
71+
echo "ACI_IP=$IP_ADDRESS" >> $GITHUB_OUTPUT
72+
73+
- name: Output deployment URL
74+
run: echo "Application deployed to http://${{ steps.get-aci-ip.outputs.ACI_IP }}"

acr-nginx.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx0-deployment
5+
labels:
6+
app: nginx0-deployment
7+
spec:
8+
replicas: 2
9+
selector:
10+
matchLabels:
11+
app: nginx0
12+
template:
13+
metadata:
14+
labels:
15+
app: nginx0
16+
spec:
17+
containers:
18+
- name: nginx
19+
image: nginx:latest
20+
ports:
21+
- containerPort: 80
22+
resources:
23+
requests:
24+
memory: "32Mi"
25+
cpu: "50m"
26+
limits:
27+
memory: "64Mi"
28+
cpu: "100m"

azd/aci/infra.bicep

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
targetScope = 'subscription'
2+
3+
@minLength(1)
4+
@maxLength(64)
5+
@description('Name of the the environment which is used to generate a short unique hash used in all resources.')
6+
param environmentName string
7+
8+
@minLength(1)
9+
@description('Primary location for all resources')
10+
param location string
11+
12+
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
13+
var tags = { 'azd-env-name': environmentName }
14+
15+
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
16+
name: 'rg-${environmentName}'
17+
location: location
18+
tags: tags
19+
}
20+
21+
module containerRegistry 'modules/container-registry.bicep' = {
22+
name: 'registry'
23+
scope: resourceGroup
24+
params: {
25+
location: location
26+
tags: tags
27+
name: 'acr${resourceToken}'
28+
}
29+
}
30+
31+
module containerInstance 'modules/container-instance.bicep' = {
32+
name: 'container-instance'
33+
scope: resourceGroup
34+
params: {
35+
location: location
36+
tags: tags
37+
name: 'aci-${resourceToken}'
38+
containerImage: '${containerRegistry.outputs.loginServer}/docker-app:latest'
39+
containerPort: 80
40+
cpuCores: '1.0'
41+
memoryInGb: '1.5'
42+
registryLoginServer: containerRegistry.outputs.loginServer
43+
registryUsername: containerRegistry.outputs.adminUsername
44+
registryPassword: containerRegistry.outputs.adminPassword
45+
}
46+
}
47+
48+
output AZURE_LOCATION string = location
49+
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry.outputs.loginServer
50+
output AZURE_CONTAINER_REGISTRY_NAME string = containerRegistry.outputs.name
51+
output ACI_URI string = containerInstance.outputs.uri

azd/aci/main.bicep

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
targetScope = 'subscription'
2+
3+
@minLength(1)
4+
@maxLength(64)
5+
@description('Name of the the environment which is used to generate a short unique hash used in all resources.')
6+
param environmentName string
7+
8+
@minLength(1)
9+
@description('Primary location for all resources')
10+
param location string
11+
12+
@description('The container image to deploy')
13+
param containerImage string = ''
14+
15+
@description('Port the container listens on')
16+
param containerPort int = 80
17+
18+
@description('CPU cores allocated to the container instance')
19+
param cpuCores string = '1.0'
20+
21+
@description('Memory allocated to the container instance in GB')
22+
param memoryInGb string = '1.5'
23+
24+
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
25+
var tags = { 'azd-env-name': environmentName }
26+
27+
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
28+
name: 'rg-${environmentName}'
29+
location: location
30+
tags: tags
31+
}
32+
33+
module containerRegistry './modules/acr.bicep' = {
34+
name: 'registry'
35+
scope: resourceGroup
36+
params: {
37+
location: location
38+
registryName: 'acr${resourceToken}'
39+
sku: 'Basic'
40+
addAdminUser: true
41+
}
42+
}
43+
44+
module containerInstance './modules/container-instance.bicep' = {
45+
name: 'container-instance'
46+
scope: resourceGroup
47+
params: {
48+
location: location
49+
tags: tags
50+
name: 'aci-${resourceToken}'
51+
containerImage: !empty(containerImage) ? containerImage : 'mcr.microsoft.com/azuredocs/aci-helloworld'
52+
containerPort: containerPort
53+
cpuCores: cpuCores
54+
memoryInGb: memoryInGb
55+
registryLoginServer: containerRegistry.outputs.loginServer
56+
registryUsername: containerRegistry.outputs.adminUsername
57+
registryPassword: containerRegistry.outputs.adminPassword
58+
}
59+
}
60+
61+
output AZURE_LOCATION string = location
62+
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry.outputs.loginServer
63+
output AZURE_CONTAINER_REGISTRY_NAME string = containerRegistry.outputs.name
64+
output ACI_URI string = containerInstance.outputs.uri

0 commit comments

Comments
 (0)