From eb7a984dd4b79456d7e2245a04641d4ead551932 Mon Sep 17 00:00:00 2001 From: Amad Ud Din Gakkhar <51159316+AmadGakkhar@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:24:19 +0500 Subject: [PATCH] Create azure-deploy.yml --- .github/workflows/azure-deploy.yml | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/azure-deploy.yml diff --git a/.github/workflows/azure-deploy.yml b/.github/workflows/azure-deploy.yml new file mode 100644 index 0000000..880baf5 --- /dev/null +++ b/.github/workflows/azure-deploy.yml @@ -0,0 +1,65 @@ +name: CD-Azure + +env: + AZURE_CONTAINER_APP_NAME: demo-container + AZURE_GROUP_NAME: demo-container + +# When this action will be executed +on: + # Automatically trigger it when detected changes in repo. Remove comments to enable + #push: + # branches: + # [ main ] + + # Allow mannually trigger + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout to the branch + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to GitHub container registry + uses: docker/login-action@v1.10.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Lowercase the repo name and username + run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} + + - name: Build and push container image to registry + uses: docker/build-push-action@v2 + with: + push: true + tags: ghcr.io/${{ env.REPO }}:${{ github.sha }} + file: ./Dockerfile + + deploy: + runs-on: ubuntu-latest + needs: build + + steps: + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Lowercase the repo name and username + run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} + + - name: Deploy to containerapp + uses: azure/CLI@v1 + with: + inlineScript: | + az config set extension.use_dynamic_install=yes_without_prompt + az containerapp registry set -n ${{ env.AZURE_CONTAINER_APP_NAME }} -g ${{ env.AZURE_GROUP_NAME }} --server ghcr.io --username ${{ github.actor }} --password ${{ secrets.PAT }} + az containerapp update -n demo-container -g demo-container --cpu 2 --memory 4Gi + az containerapp update -n ${{ env.AZURE_CONTAINER_APP_NAME }} -g ${{ env.AZURE_GROUP_NAME }} --image ghcr.io/${{ env.REPO }}:${{ github.sha }}