Skip to content

Commit

Permalink
issue #57 #55: change secret, add yml and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
vivalareda committed Dec 14, 2023
1 parent df978ae commit b8547a1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/workflow-build-push-container-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
> Note: The username must be all lowercase letters.
- `ACR_PASSWORD`: The Azure container registry password.
14 changes: 7 additions & 7 deletions .github/workflows/workflow-build-push-container-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/workflow-deploy-azure.md
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 43 additions & 0 deletions .github/workflows/workflow-deploy-azure.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit b8547a1

Please sign in to comment.