AKS Deployment #12
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: 'AKS Deployment' | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/docker-build-push.yml' | |
workflow_dispatch: | |
#pull_request: | |
# env: | |
# ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} | |
# ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | |
# ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} | |
# ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} | |
# GIT_REPOSITORY: https://github.com/leomozzer/nestjs-mysql-aks | |
# PROJECT_NAME: nestjs-mysql-aks | |
# TERRAFORM_WORKING_DIR: "terraform-live" | |
# TERRAFORM_MODULES_DIR: "terraform-modules" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
stage: [dev] | |
concurrency: ${{ matrix.stage }} | |
steps: | |
# checkout the repo | |
- uses: actions/checkout@v2 | |
- uses: Azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_SP }} | |
- uses: Azure/get-keyvault-secrets@v1 | |
id: myGetSecretAction | |
with: | |
keyvault: nestjs-mysql-aks-${{ matrix.stage }}-kv | |
secrets: 'acrLoginServer, acrUsername, acrPassword' | |
- uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ steps.myGetSecretAction.outputs.acrLoginServer}} | |
username: ${{ steps.myGetSecretAction.outputs.acrUsername }} | |
password: ${{ steps.myGetSecretAction.outputs.acrPassword }} | |
- name: "Build and Push NestJS app" | |
run: | | |
cd app/ | |
docker build -t ${{ steps.myGetSecretAction.outputs.acrLoginServer}}/nestjs-app:latest . | |
docker push ${{ steps.myGetSecretAction.outputs.acrLoginServer}}/nestjs-app:latest | |
- name: "Set AKS context" | |
id: set-context | |
uses: azure/aks-set-context@v3 | |
with: | |
resource-group: 'nestjs-mysql-aks-${{ matrix.stage }}-rg' | |
cluster-name: 'nestjs-mysql-aks-${{ matrix.stage }}-aks' | |
- name: "Setup kubectl" | |
id: install-kubectl | |
uses: azure/setup-kubectl@v3 | |
- name: "Deploy NestJS to AKS" | |
run: | | |
echo ${{ env.IMAGE_NAME }} | |
echo ${{ env.ACR_NAME }} | |
cd ./kubernetes/environments/${{ matrix.stage }} | |
#ACR_NAME=${{ env.ACR_NAME }} IMAGE_NAME=${{ env.IMAGE_NAME }} kubectl kustomize . | |
kustomize edit set image nestjs-app=${{ env.ACR_NAME }}/${{ env.IMAGE_NAME }} | |
kubectl apply -k ../../bases/app/ | |
env: | |
ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
IMAGE_NAME: "nestjs-app:latest" |