Update Pipeline #51
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: "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: ./build_deploy | |
name: Deploy to AKS with Terraform | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }} | |
STORAGE_ACCOUNT: ${{ vars.AZURE_STORAGE_ACCOUNT }} | |
CONTAINER_NAME: ${{ vars.STORAGE_CONTAINER_NAME }} | |
TF_LOG: INFO | |
TF_INPUT: false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: $ARM_CLIENT_ID | |
tenant-id: ${{ secrets.AZURE_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 |