Added make env #21
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: 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: | | |
# cd ./kubernetes/bases/app | |
# kustomize edit set image app-imag=${{ env.ACR_NAME }}/${{ env.IMAGE_NAME }} | |
# cd .. | |
# kubectl apply -f ./app/ | |
# kubectl get nodes | |
# env: | |
# ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
# IMAGE_NAME: "nestjs-app:latest" | |
- name: Make envfile | |
uses: SpicyPizza/create-envfile@v1.3 | |
with: | |
envkey_ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
envkey_IMAGE_NAME: "nestjs-app:latest" | |
directory: ./kubernetes/environments/${{ matrix.stage }} | |
file_name: .env | |
fail_on_empty: false | |
- name: Make envfile | |
uses: SpicyPizza/create-envfile@v1.3 | |
with: | |
envkey_ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
envkey_IMAGE_NAME: "nestjs-app:latest" | |
directory: ./kubernetes/bases/app/ | |
file_name: .env | |
fail_on_empty: false | |
- name: "Deploy NestJS to AKS" | |
run: | | |
echo ${{ env.IMAGE_NAME }} | |
echo ${{ env.ACR_NAME }} | |
cd ./kubernetes/environments/${{ matrix.stage }} | |
kubectl kustomize . | |
kubectl apply -k ../../bases/app/ | |
env: | |
ACR_NAME: ${{ steps.myGetSecretAction.outputs.acrLoginServer }} | |
IMAGE_NAME: "nestjs-app:latest" |