From b8547a13529aff9b83e95e39d8e4e1b7e21a69e7 Mon Sep 17 00:00:00 2001 From: reda Date: Fri, 8 Dec 2023 15:23:21 -0500 Subject: [PATCH] issue #57 #55: change secret, add yml and update doc --- .../workflow-build-push-container-azure.md | 5 ++- .../workflow-build-push-container-azure.yml | 14 +++--- .github/workflows/workflow-deploy-azure.md | 10 +++++ .github/workflows/workflow-deploy-azure.yml | 43 +++++++++++++++++++ 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/workflow-deploy-azure.md create mode 100644 .github/workflows/workflow-deploy-azure.yml diff --git a/.github/workflows/workflow-build-push-container-azure.md b/.github/workflows/workflow-build-push-container-azure.md index 68023b6..160877b 100644 --- a/.github/workflows/workflow-build-push-container-azure.md +++ b/.github/workflows/workflow-build-push-container-azure.md @@ -3,6 +3,7 @@ - **Purpose:** Build and push a docker container to Azure Container Registry (ACR). - **Usage:** Call this workflow and provide the `container-name` and `tag` as inputs. - **Required Secrets:** - - `ACR_REGISTRY_NAME`: The Azure container registry name. + - `ACR_SERVER`: The Azure container registry link. - `ACR_USERNAME`: The Azure container registry username. - - `ACR_PASSWORD`: The Azure container registry password. \ No newline at end of file + > Note: The username must be all lowercase letters. + - `ACR_PASSWORD`: The Azure container registry password. diff --git a/.github/workflows/workflow-build-push-container-azure.yml b/.github/workflows/workflow-build-push-container-azure.yml index 9d861de..77130fb 100644 --- a/.github/workflows/workflow-build-push-container-azure.yml +++ b/.github/workflows/workflow-build-push-container-azure.yml @@ -18,17 +18,17 @@ jobs: - name: Login to ACR uses: docker/login-action@v2 with: - registry: ${{ secrets.ACR_REGISTRY_NAME }} + registry: ${{ secrets.ACR_SERVER }} username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_PASSWORD }} - + # Checkout the current repository. - uses: actions/checkout@v3 - + # Setup Docker Buildx for advanced build features. - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - + # Cache Docker layers to improve build speed. - name: Cache Docker layers uses: actions/cache@v2 @@ -37,17 +37,17 @@ jobs: key: ${{ runner.os }}-${{inputs.container-name}}-${{ github.sha }} restore-keys: | ${{ runner.os }}-${{inputs.container-name}} - + # Build and push the Docker image with the specified tag. - name: Build and push the Docker image uses: docker/build-push-action@v4 with: context: . push: true - tags: ${{ secrets.ACR_REGISTRY_NAME }}/${{inputs.container-name}}:${{inputs.tag}} + tags: ${{ secrets.ACR_SERVER }}/${{inputs.container-name}}:${{inputs.tag}} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - + # Cleanup and move cache for future builds. - name: Move cache run: | diff --git a/.github/workflows/workflow-deploy-azure.md b/.github/workflows/workflow-deploy-azure.md new file mode 100644 index 0000000..b64ae23 --- /dev/null +++ b/.github/workflows/workflow-deploy-azure.md @@ -0,0 +1,10 @@ +## Reusable Docker Container Deployment to Azure + + - **Purpose:** Deploy a Docker container to Azure App Service. + - **Usage:** Call this workflow and provide the `container-name` and `tag` as inputs. + - **Required Secrets:** + - `AZURE_CREDENTIALS`: JSON object containing Azure service principal credentials for authentication. + - `ACR_SERVER`: DNS to the Azure Container Registry where the Docker image is stored ex.: 'aciacfiaacr.azurecr.io'. + - `ACR_USERNAME`: Username for logging into Azure Container Registry. + - `ACR_PASSWORD`: Password for logging into Azure Container Registry. + - `AZURE_PUBLISH_PROFILE`: Publish profile for the Azure App Service. This contains deployment and configuration settings. diff --git a/.github/workflows/workflow-deploy-azure.yml b/.github/workflows/workflow-deploy-azure.yml new file mode 100644 index 0000000..ca6cd54 --- /dev/null +++ b/.github/workflows/workflow-deploy-azure.yml @@ -0,0 +1,43 @@ +name: Reusable Docker container deployment to Azure + +on: + workflow_call: + inputs: + container-name: + required: true + type: string + tag: + required: true + type: string + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Azure Docker Login + uses: azure/docker-login@v1 + with: + login-server: ${{ secrets.ACR_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build and push Docker image + run: | + docker build -t ${{ secrets.ACR_SERVER }}/${{ inputs.container-name }}:${{ inputs.tag }} . + docker push ${{ secrets.ACR_SERVER }}/${{ inputs.container-name }}:${{ inputs.tag }} + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ github.event.repository.name }} + slot-name: production + publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }} + images: ${{ secrets.ACR_SERVER }}/${{ inputs.container-name }}:${{ inputs.tag }}