forked from RayMaAU/github-actions-workflow-simple-app
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (83 loc) · 2.77 KB
/
build-deploy-azure.yml
File metadata and controls
101 lines (83 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Build and Deploy to Azure
env:
AZURE_CONTAINER_REGISTRY_NAME: "ACR31102024peter"
AZURE_CONTAINER_REGISTRY: "acr31102024peter.azurecr.io"
CONTAINER_NAME: "hello-world"
RESOURCE_GROUP: "rg-github-actions-demo"
CLUSTER_NAME: "aks-peter-aue"
on:
push:
branches: [ "master" ]
workflow_dispatch:
permissions:
contents: read
jobs:
buildContainerImage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
- name: Set up Docker Builx
uses: docker/setup-buildx-action@v3.7.1
- name: Azure Container Registry Login
uses: Azure/docker-login@v1
with:
# Container registry username
username: ${{ env.AZURE_CONTAINER_REGISTRY_NAME }}
# Container registry password
password: ${{ secrets.AZURE_CONTAINER_REGISTRY_PASSWORD }}
# Container registry server url
login-server: ${{ env.AZURE_CONTAINER_REGISTRY }}
- name: Build and push Docker images
uses: docker/build-push-action@v6.9.0
with:
push: true
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ env.CONTAINER_NAME }}:${{ github.sha }}
file: ./Dockerfile
deployToAKS:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
id-token: write
environment: Production
needs: [buildContainerImage]
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
- name: Azure Login
uses: Azure/login@v2.2.0
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup kubelogin
uses: Azure/use-kubelogin@v1
with:
kubelogin-version: 'v0.0.25'
- name: Get K8s Context
uses: Azure/aks-set-context@v3
with:
resource-group: ${{ env.RESOURCE_GROUP }}
cluster-name: ${{ env.CLUSTER_NAME }}
admin: 'false'
use-kubelogin: 'true'
- name: envsubst-action
uses: danielr1996/envsubst-action@1.1.0
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
AZURE_CONTAINER_REGISTRY: ${{ env.AZURE_CONTAINER_REGISTRY }}
CONTAINER_NAME: ${{ env.CONTAINER_NAME }}
with:
input:
kubernetes/hello-world-deployment.yaml
output:
hello-world-deployment.yaml
- name: Deploy to Kubernetes cluster
uses: Azure/k8s-deploy@v4.9
with:
action: deploy
manifests: |
hello-world-deployment.yaml
kubernetes/hello-world-service.yaml
images: ${{ env.AZURE_CONTAINER_REGISTRY }}/${{ env.CONTAINER_NAME }}:${{ github.sha }}