Enabled Database! #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v1 | |
with: | |
files: ${{ env.APPSETTINGS_PATH }} | |
env: | |
ConnectionStrings.DBConnection: ${{secrets.DBConnection}} | |
# 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 }} | |