This was running fine before when I was deploying a website in azure app service. Before there were separate backend and frontend app service and this is how files for backend looks like -
change_orders
view loc requests
last month
common
added line of credit app
last month
contracts
moved input fields to OCR
last month
factoring_bids
loc bid status changes
last month
fininst
create LOC offer views
last month
invoices
create LOC offer views
last month
line_of_credit
end loc
last month
marketplace
debug for local
last month
notifications
refactoring
last month
partnerships
view loc requests
last month
subs
created ocr admin page
last month
templates
loc bid status changes
last month
users
loc bid status changes
last month
.gitignore
Merge branch 'main' of github.com:EllisDon-Data/fintech-marketplace-BE
3 months ago
README.md
added offer email notifications
2 months ago
azure-pipelines.yaml
Update azure-pipelines.yaml for Azure Pipelines
2 minutes ago
manage.py
setup auth
4 months ago
requirements.txt
add openai library
last month
Now I made changes and combined both FE and BE into one and I am using docker for this. I also have docker compose file and this is the files look for this -
backend-app
change_orders
common
contracts
equipment_financing
factoring_bids
fininst
invoices
line_of_credit
marketplace
notifications
partnerships
subs
templates
users
Dockerfile
README.md
azure-pipelines.yaml
manage.py
requirements.txt
frontend-app
public
src
.DS_Store
Dockerfile
README.md
azure-pipelines.yaml
package-lock.json
package.json
tailwind.config.js
tsconfig.json
.gitignore
README.md
azure-pipelines.yaml
docker-compose.yml
This is my docker-compase.yaml file -
services:
This is what I found in azure support website regarding this -
Docker Compose options
The following lists show supported and unsupported Docker Compose configuration options:
Supported options
command
entrypoint
environment
image
ports
restart
services
volumes (mapping to Azure Storage is unsupported)
Unsupported options
build (not allowed)
depends_on (ignored)
networks (ignored)
secrets (ignored)
ports other than 80 and 8080 (ignored)
default environment variables like variableand{variable} unlike in docker
Syntax Limitations
"version x.x" always needs to be the first YAML statement in the file
ports section must use quoted numbers
image > volume section must be quoted and can't have permissions definitions
volumes section must not have an empty curly brace after the volume name
Do I need to make some changes somewhere to make the new changes work?
If we need to use acr then my acr has username and password as well for login
Tell me all steps in details that I need to perform to make it work.
To successfully migrate your Azure Pipelines deployment from separate frontend and backend App Services to a combined Docker-based setup using Docker Compose, you'll need to make several adjustments. This involves modifying your docker-compose.yml, updating your azure-pipelines.yaml to build and push Docker images to Azure Container Registry (ACR), and configuring Azure App Service to deploy these images.
Here's a comprehensive, step-by-step guide to achieve this:
1. Set Up Azure Container Registry (ACR)
a. Create an ACR Instance (If Not Already Existing):
Click on "Create a resource" and search for "Container Registry".
Click "Create" and fill in the necessary details:
Subscription: Choose your subscription.
Resource Group: Select an existing one or create a new one.
Registry Name: Provide a unique name (e.g., youracrname).
Location: Choose a region close to your resources.
SKU: Standard is usually sufficient, but choose based on your needs.
Click "Review + create" and then "Create".
b. Obtain ACR Credentials:
Navigate to Your ACR:
In the Azure Portal, go to your created ACR.
Access Credentials:
Under "Settings", click on "Access keys".
Note down the Username and Password; you'll need these for pipeline authentication.
2. Modify docker-compose.yml
Azure App Service's Docker Compose support has specific limitations. To comply:
a. Remove Unsupported Sections:
Remove build: Azure App Service cannot build images from your docker-compose.yml. Instead, it expects pre-built images from a container registry.
Remove depends_on, networks, and secrets: These are either ignored or unsupported.
b. Update to Use ACR Images:
Modify your docker-compose.yml to reference images stored in ACR. Here's an example template:
yaml
version: '3.8' # Ensure version is specified at the top
services:
be-app:
image: youracrname.azurecr.io/be-app:$(IMAGE_TAG) # Use ACR with tag
ports:
- "8000:8000"
env_file:
- .env
command: >
sh -c "python3 manage.py migrate &&
python3 manage.py makegroups &&
python3 manage.py runserver 0.0.0.0:8000"
fe-app:
image: youracrname.azurecr.io/fe-app:$(IMAGE_TAG) # Use ACR with tag
ports:
- "3000:3000"
env_file:
- .env
command: >
sh -c "npm start"
redis:
image: redis:bullseye # Public image from Docker Hub
celery:
image: youracrname.azurecr.io/celery:$(IMAGE_TAG) # Use ACR with tag
command: celery -A marketplace worker --loglevel=info
# Note: 'depends_on' is ignored; ensure services start in the correct order
Notes:
Replace youracrname with your actual ACR name.
$(IMAGE_TAG) is a placeholder that you'll replace with the actual build ID during the pipeline.
3. Update azure-pipelines.yaml
Your pipeline needs to:
Build Docker Images for Backend and Frontend.
Push These Images to ACR.
Update docker-compose.yml with the Correct Image Tags.
Deploy to Azure App Service Using the Updated docker-compose.yml.
Here's an updated version of your azure-pipelines.yaml to perform these steps:
yaml
trigger:
- main
pool:
vmImage: ubuntu-latest
variables:
ACR_NAME: youracrname # Replace with your ACR name
ACR_LOGIN_SERVER: youracrname.azurecr.io # Replace accordingly
IMAGE_TAG: $(Build.BuildId) # Unique tag per build
steps:
# 1. Checkout the code
- checkout: self
# 2. Log in to Azure Container Registry
- task: Docker@2
displayName: Login to ACR
inputs:
command: login
containerRegistry: $(ACR_NAME) # Service connection name
# 3. Build and Push Backend Image
- task: Docker@2
displayName: Build and Push be-app
inputs:
command: buildAndPush
repository: $(ACR_LOGIN_SERVER)/be-app
Dockerfile: backend-app/Dockerfile
tags: |
$(IMAGE_TAG)
# 4. Build and Push Frontend Image
- task: Docker@2
displayName: Build and Push fe-app
inputs:
command: buildAndPush
repository: $(ACR_LOGIN_SERVER)/fe-app
Dockerfile: frontend-app/Dockerfile
tags: |
$(IMAGE_TAG)
# 5. Build and Push Celery Image (If Separate Dockerfile Needed)
- task: Docker@2
displayName: Build and Push celery
inputs:
command: buildAndPush
repository: $(ACR_LOGIN_SERVER)/celery
Dockerfile: backend-app/Dockerfile # Use a separate Dockerfile if necessary
tags: |
$(IMAGE_TAG)
# 6. Replace Image Tags in docker-compose.yml
- task: Bash@3
displayName: Update docker-compose.yml with Image Tags
inputs:
targetType: inline
script: |
sed -i 's|youracrname.azurecr.io/be-app:.*|youracrname.azurecr.io/be-app:$(IMAGE_TAG)|' docker-compose.yml
sed -i 's|youracrname.azurecr.io/fe-app:.*|youracrname.azurecr.io/fe-app:$(IMAGE_TAG)|' docker-compose.yml
sed -i 's|youracrname.azurecr.io/celery:.*|youracrname.azurecr.io/celery:$(IMAGE_TAG)|' docker-compose.yml
# 7. Publish docker-compose.yml as an Artifact (Optional)
- publish: docker-compose.yml
artifact: docker-compose
# 8. Deploy to Azure App Service
- task: AzureWebAppContainer@1
displayName: Deploy to Azure App Service Using Docker Compose
inputs:
azureSubscription: <Your-Service-Connection> # Replace with your service connection name
appName: <Your-App-Service-Name> # Replace with your App Service name
configurationFile: docker-compose.yml
# Ensure the App Service is configured for multi-container and linked to ACR
Detailed Breakdown:
Variables:
ACR_NAME: Your ACR instance name.
ACR_LOGIN_SERVER: Typically youracrname.azurecr.io.
IMAGE_TAG: Using the build ID ensures each image is uniquely tagged.
Docker Login Task:
Use the Docker@2 task to log in to ACR. Ensure you've set up a Docker Registry service connection in Azure DevOps pointing to your ACR.
Build and Push Docker Images:
Backend (be-app): Builds from backend-app/Dockerfile and pushes to ACR with the build ID as the tag.
Frontend (fe-app): Builds from frontend-app/Dockerfile and pushes similarly.
Celery: If it requires a separate image, ensure a distinct Dockerfile is used.
Update docker-compose.yml:
Use sed to replace the image tags in your docker-compose.yml with the current build's tag. This ensures Azure App Service pulls the correct image versions.
Optional - Publish docker-compose.yml:
Publishing it as an artifact can be useful for debugging or future steps.
Deploy to Azure App Service:
AzureWebAppContainer@1: This task deploys your Docker Compose setup to Azure App Service.
Ensure your App Service is configured to use Docker Compose and has access to pull images from ACR.
Important Considerations:
Service Connections:
ACR Service Connection: In Azure DevOps, navigate to Project Settings > Service connections and ensure you have a Docker Registry connection pointing to your ACR.
Azure Subscription Service Connection: Needed for the AzureWebAppContainer@1 task to deploy to App Service.
Security:
Secrets Handling: Use Azure DevOps Variable Groups with secrets or Azure Key Vault to handle sensitive information like ACR credentials.
Azure App Service Configuration:
Multi-Container: Ensure your App Service is set to use a Linux OS and is configured for multi-container deployment.
ACR Integration: Under "Container settings" in your App Service, link it to your ACR and provide necessary authentication details.
4. Configure Azure App Service for Multi-Container Deployment
a. Configure Container Settings:
Navigate to Your App Service:
In the Azure Portal, find and select your App Service.
Access Container Settings:
Under "Settings", click on "Container settings" or "Configuration > Containers".
Set Up Docker Compose:
Choose "Docker Compose" as the option.
You can reference your docker-compose.yml directly or use Azure DevOps to deploy it.
Link to ACR:
If not already linked, provide the ACR login server, username, and password.
Alternatively, use managed identities for authentication if preferred.
b. Ensure Networking and Permissions:
Network Access: Ensure your App Service has network access to ACR, especially if ACR is in a private network.
Permissions: The service principal or identity used should have Pull permissions on ACR.
5. Test the Pipeline
Commit Changes:
Push your updated docker-compose.yml and azure-pipelines.yaml to the main branch.
Monitor Pipeline Execution:
Navigate to Azure DevOps > Pipelines and watch the pipeline run.
Ensure each step completes successfully: build, push, tag update, and deployment.
Verify Deployment:
Once the pipeline completes, navigate to your Azure App Service.
Confirm that both frontend and backend containers are running correctly.
Check application functionality to ensure everything operates as expected.
6. Additional Recommendations
Use Specific Image Tags:
Instead of latest, using specific tags like $(IMAGE_TAG) (e.g., build ID) ensures version control and easier rollbacks if needed.
Separate Dockerfiles for Different Services:
If services like Celery require different configurations, consider maintaining separate Dockerfiles to encapsulate their unique requirements.
Automate docker-compose.yml Tag Insertion:
For larger projects, consider templating your docker-compose.yml or using tools like Helm for Kubernetes deployments.
Implement Health Checks:
Incorporate health checks in your docker-compose.yml to ensure that containers are running as expected.
Logging and Monitoring:
Utilize Azure Monitor and Application Insights to monitor the health and performance of your applications.
By following these detailed steps, you'll successfully transition your deployment pipeline to a Docker-based architecture using Docker Compose on Azure App Service. This setup ensures scalable, maintainable, and efficient deployments for both your frontend and backend services.