
This project automates the deployment process using GitHub Actions for continuous integration and continuous deployment (CI/CD). The Docker image is built and pushed to Azure Container Registry (ACR), from where it is deployed to Azure App Service.
This diagram visually explains the flow from GitHub to Azure App Service using Docker containers stored in Azure Container Registry.
The architecture follows a streamlined CI/CD pipeline:
- GitHub: Hosts the source code.
- GitHub Actions: Automates the building and pushing of Docker images.
- Azure Container Registry (ACR): Stores the Docker images.
- Azure App Service: Pulls the images from ACR and deploys them.
- Code Push β‘οΈ GitHub triggers GitHub Actions.
- Build & Push Docker Image β‘οΈ Docker image is built and pushed to ACR.
- Deploy β‘οΈ Azure App Service pulls the latest image from ACR and deploys it.
Step | Description |
---|---|
1. Code Push | Code pushed to the master branch triggers the CI/CD workflow in GitHub Actions. |
2. Build Docker Image | GitHub Actions builds a Docker image from the codebase. |
3. Push to ACR | The built image is pushed to Azure Container Registry for storage. |
4. Deploy to App Service | Azure App Service pulls the image from ACR and redeploys the app. |
5. Build Summary | GitHub Actions generates a summary for the completed build and deployment. |
Component | Description |
---|---|
GitHub | The source control platform where code is stored and updated. |
GitHub Actions | The CI/CD pipeline that automates building, pushing, and deploying the Docker image. |
Docker | A platform used to build the application into a containerized image. |
Azure Container Registry | Stores the Docker image for future deployments. |
Azure App Service | Hosts the application and pulls the latest Docker image from ACR for deployment. |
- Code Push: When you push code to the
master
branch, the CI/CD workflow is triggered. - GitHub Actions: Automatically builds the Docker image and pushes it to ACR.
- Azure App Service: Fetches the latest image from ACR and deploys it.
- Automated Deployment: No need for manual deployment, every push to
master
results in an automated build and deployment. - Scalable: With Azure App Service, you can easily scale your app without changing the pipeline.
- Versioned Docker Images: Each build is tagged with a unique Git commit SHA to maintain versioning.
- Containerized Workflow: Leveraging Docker ensures consistency between development and production environments.
- Clone the repository and push your code changes to the
master
branch. - The GitHub Actions pipeline will automatically build and push the Docker image to ACR.
- Azure App Service will pull the latest image and redeploy the app.
- You can view the build summary in the GitHub Actions page for every commit.
Follow these steps to create Azure App Service from the Azure GUI:
-
Log in to Azure Portal:
- Go to Azure Portal and log in with your credentials.
-
Create an App Service:
- From the Azure Portal, click Create a resource on the left sidebar.
- Search for App Service in the Search Box and select it.
- Click Create to start the setup.
-
Fill in the App Service details:
- Subscription: Select your Azure subscription.
- Resource Group: Choose an existing resource group or create a new one.
- Name: Enter a unique name for your app (e.g.,
my-vite-app
). - Publish: Choose Code (since we are deploying code directly from GitHub).
- Runtime stack: Select Node 18+ (ensure compatibility with Vite).
- Region: Select Southeast Asia from the dropdown to deploy in the desired region.
-
Configure App Service Plan:
- Choose Pricing Plan: Select an existing plan or create a new one based on your requirements (e.g., B1 - Basic, S1 - Standard).
- Set the Operating System to Linux.
-
Review and Create:
- Review your configurations and click Create.
- Wait a few minutes for the deployment to complete.
Follow these steps to create Azure Container Registry from the Azure GUI:
-
Go to Azure Portal:
- From the Azure Portal, click Create a resource.
-
Search for Container Registry:
- In the Search Box, type Container Registry and select it.
- Click Create to begin.
-
Fill in the Container Registry details:
- Subscription: Select your Azure subscription.
- Resource Group: Use the same resource group as the App Service.
- Registry Name: Enter a name for your registry (e.g.,
myacrregistry
). - SKU: Choose Basic for basic needs or Standard for more advanced features.
- Region: Select Southeast Asia to deploy in the same region as the App Service.
-
Review and Create:
- Review your configurations and click Create.
- Wait for the registry to be provisioned.
Yaml file can be found in the ".github" directory in the source code. This workflow automates the process of building and pushing the Docker image to Azure Container Registry (ACR), followed by deploying the image to Azure App Service. Below is a breakdown of the steps involved in the App Build and Push to Azure Container Registry GitHub Action:
-
Checkout:
- The first step uses the
actions/checkout@v4
action to clone the GitHub repository, ensuring that the latest code is pulled into the workflow.
- The first step uses the
-
Login to Azure Container Registry (ACR):
- The
azure/docker-login@v2
action is used to log in to Azure Container Registry with credentials stored securely in GitHub Secrets. The secrets include:AZCR_REGISTRY_SERVER
: The Azure Container Registry server URL.AZCR_USERNAME
: The username for the Azure Container Registry login.AZCR_PASSWORD
: The password or token for authenticating with the registry.
- The
-
Build and Push Docker Image:
- The
docker build
command is used to build the Docker image from the Dockerfile located in the repository. The image is tagged using the commit hash (github.sha
) to ensure unique identification of the image. - The
docker push
command pushes the built image to the Azure Container Registry using the tagged image name:${{secrets.AZCR_REGISTRY_SERVER}}/${{secrets.AZCR_REPO_NAME}}:${{ github.sha }}
.
- The
-
Deploy to Azure App Service:
- The
azure/webapps-deploy@v2
action is used to deploy the Docker image from the Azure Container Registry to Azure App Service. Thepublish-profile
is stored as a GitHub secret (AZURE_APP_SERVICES_PUBLISH_PROFILE
), and it provides the credentials needed for deployment. - The action deploys the Docker image tagged with the commit hash to the Azure App Service defined by the secret
AZAS_APP_NAME
.
- The
-
Download the Azure publish profile from Azure App Service β Deployment Center.
- In your Azure App Service, go to the Deployment Center tab.
- Under Publish Profile, click Download Publish Profile.
-
Go to GitHub β Settings β Secrets β New Repository Secret.
- Name the secret
AZURE_WEBAPP_PUBLISH_PROFILE
and paste the contents of the publish profile.
- Name the secret