Fixed deployment #26
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' | |
- 'kubernetes/**' | |
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: ${{ env.PROJECT_NAME }}-${{ 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: '${{ env.PROJECT_NAME }}-${{ matrix.stage }}-rg' | |
cluster-name: '${{ env.PROJECT_NAME }}-${{ matrix.stage }}-aks' | |
- name: "Setup kubectl" | |
id: install-kubectl | |
uses: azure/setup-kubectl@v3 | |
- name: "Deploy NestJS to AKS" | |
run: | | |
cd ./kubernetes/bases/ | |
kubectl apply -f ./app/ | |
kubectl set image deployment.apps/nestjs nestjs=${{ env.ACR_NAME }}/${{ env.IMAGE_NAME }} | |
kubectl get services | |
env: | |
ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
IMAGE_NAME: "nestjs-app:latest" |