Skip to content

Update Configuration #47

Update Configuration

Update Configuration #47

name: "build_nd_deploy_to_AKS"
on:
push:
branches:
- main
permissions:
contents: read
id-token: write
jobs:
build:
name: Build Container Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/flaskblog-app:latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/flaskblog-app:${{ github.sha }}
labels: ${{ steps.metadata.outputs.labels }}
deploy:
defaults:
run:
shell: bash
working-directory: ./terraform
name: Deploy to AKS with Terraform
runs-on: ubuntu-latest
needs: build
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
CONTAINER_NAME: ${{ secrets.STORAGE_CONTAINER_NAME }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v1
with:
client-id: $ARM_CLIENT_ID
tenant-id: $ARM_TENANT_ID
subscription-id: $ARM_SUBSCRIPTION_ID
# allow-no-subscriptions: true
# - name: Echo TFVARS
# run: echo "${{ secrets.TFVARS }}" > .env
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: latest
# - name: Terraform Init
# run: terraform init -backend-config="resource_group_name=${{ secrets.AZURE_RESOURCE_GROUP }}" -backend-config="storage_account_name=${{ secrets.AZURE_STORAGE_ACCOUNT }}" -backend-config="container_name=${{ secrets.AZURE_CONTAINER_NAME }}"
# - name: Terraform fmt
# id: fmt
# run: terraform fmt -check -recursive
# continue-on-error: true
# - name: Terraform Validate
# id: validate
# run: terraform validate -no-color
# - name: Terraform Plan
# id: plan
# run: terraform plan -var 'docker_image=${{ secrets.DOCKER_USERNAME }}/flaskblog-app:${{ github.sha }}' -input=false -var-file=./.env
# run: terraform plan -no-color -out=plan.tfplan -var="docker_image=jojodocker10/flaskblog-app:latest" -input=false --var-file=./.env
# - name: Terraform Apply
# run: terraform apply -auto-approve