Skip to content

Update pipeline

Update pipeline #44

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/login-action@v3.0.0
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
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_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: Debugging
run: env
- name: Terraform Init
run: terraform init
- 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