-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (93 loc) · 3.34 KB
/
main.yml
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
102
103
104
105
106
107
name: Build & Deploy
on:
push:
workflow_dispatch:
env:
AZURE_CONTAINER_REGISTRY: "warshipregistry"
CONTAINER_NAME: "warshipssearchapi"
DOCKER_PATH: "./WarshipSearchAPI/Dockerfile"
APPSETTINGS_PATH: "./WarshipSearchAPI/appsettings.json"
CLUSTER_NAME: "aks"
jobs:
BuildImage:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
env:
RESOURCE_GROUP: "CombatWarships"
steps:
# Checks out the repository this file is in
- uses: actions/checkout@v3
#substitute production appsettings entries to appsettings json file
- name: App Settings Variable Substitution
uses: microsoft/variable-substitution@v2
with:
files: ${{ env.APPSETTINGS_PATH }}
env:
ConnectionStrings.dbConnection: "GITHUB DB"
App.seqConnection: "GITHUB seq"
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Builds and pushes an image up to your Azure Container Registry
- name: Build and push image to ACR
run: |
az acr build -f ${{env.DOCKER_PATH}} --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} --registry ${{ env.AZURE_CONTAINER_REGISTRY }} -g ${{ env.RESOURCE_GROUP }} .
Deploy-to-AKS:
permissions:
actions: read
contents: read
id-token: write
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs: [BuildImage]
env:
RESOURCE_GROUP: "aks"
steps:
# Checks out the repository this file is in
- uses: actions/checkout@v3
# Logs in with your Azure credentials
- name: Azure login
uses: azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Use kubelogin to configure your kubeconfig for Azure auth
- name: Set up kubelogin for non-interactive login
uses: azure/use-kubelogin@v1
with:
kubelogin-version: 'v0.0.25'
# Update K8 variables with information from this CI.
- name: Update K8 variables
uses: cschleiden/replace-tokens@v1
with:
files: '["manifests/*.yml"]'
tokenPrefix: __
tokenSuffix: __
env:
IMAGE_NAME: ${{ env.CONTAINER_NAME }}
IMAGE_TAG: ${{ github.sha }}
# Retrieves your Azure Kubernetes Service cluster's kubeconfig file
- 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'
# Deploys application based on manifest files from previous step
- name: Deploy application
uses: Azure/k8s-deploy@v4
with:
action: deploy
manifests: |
manifests/deployment.yml
manifests/service.yml
images: |
${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }}