This repository was archived by the owner on Nov 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdeploy-to-aca.sh
More file actions
executable file
·114 lines (98 loc) · 3.91 KB
/
Copy pathdeploy-to-aca.sh
File metadata and controls
executable file
·114 lines (98 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
set -e
# Load environment variables from .env file
if [ -f .env ]; then
echo "Loading environment variables from .env file..."
export $(grep -v '^#' .env | xargs)
else
echo ".env file not found. Please create a .env file with the required variables."
exit 1
fi
# Check if required environment variables are set
for var in AZURE_OPENAI_API_KEY AZURE_OPENAI_ENDPOINT AZURE_OPENAI_DEPLOYMENT_NAME AZURE_OPENAI_API_VERSION; do
if [ -z "${!var}" ]; then
echo "Error: $var is not set in the .env file."
exit 1
fi
done
# Configuration Variables
RESOURCE_GROUP="microblog-ai-remix-rg"
LOCATION="eastus"
ACR_NAME="microblogairemixacr"
CONTAINER_APP_ENV="microblog-ai-remix-env"
CONTAINER_APP_NAME="microblog-ai-remix-app"
IMAGE_NAME="microblog-ai-remix"
IMAGE_TAG="latest"
# Step 1: Build the Docker image locally
echo "Building Docker image..."
docker build -t $IMAGE_NAME:$IMAGE_TAG .
# Step 2: Login to Azure if not already logged in
echo "Logging in to Azure..."
az account show &> /dev/null || az login
# Step 3: Create a Resource Group if it doesn't exist
echo "Creating Resource Group if it doesn't exist..."
az group create --name $RESOURCE_GROUP --location $LOCATION
# Step 4: Create an Azure Container Registry if it doesn't exist
echo "Creating Azure Container Registry if it doesn't exist..."
az acr create --resource-group $RESOURCE_GROUP --name $ACR_NAME --sku Basic || true
az acr update --name $ACR_NAME --admin-enabled true
# Step 5: Login to Azure Container Registry
echo "Logging into ACR..."
az acr login --name $ACR_NAME
# Step 6: Tag and push the Docker image to ACR
echo "Tagging and pushing image to ACR..."
docker tag $IMAGE_NAME:$IMAGE_TAG $ACR_NAME.azurecr.io/$IMAGE_NAME:$IMAGE_TAG
docker push $ACR_NAME.azurecr.io/$IMAGE_NAME:$IMAGE_TAG
# Step 7: Create a Container App Environment if it doesn't exist
echo "Creating Container App Environment if it doesn't exist..."
az containerapp env create \
--name $CONTAINER_APP_ENV \
--resource-group $RESOURCE_GROUP \
--location $LOCATION || true
# Step 8: Get ACR credentials
echo "Getting ACR credentials..."
ACR_USERNAME=$ACR_NAME
ACR_PASSWORD=$(az acr credential show --name $ACR_NAME --query "passwords[0].value" -o tsv)
# Step 9: Create or update the Container App
echo "Checking if Container App exists..."
CONTAINER_APP_EXISTS=$(az containerapp show --name $CONTAINER_APP_NAME --resource-group $RESOURCE_GROUP --query name 2>/dev/null || echo "false")
if [ "$CONTAINER_APP_EXISTS" == "false" ]; then
echo "Creating new Container App..."
az containerapp create \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--environment $CONTAINER_APP_ENV \
--image $ACR_NAME.azurecr.io/$IMAGE_NAME:$IMAGE_TAG \
--registry-server $ACR_NAME.azurecr.io \
--registry-username $ACR_USERNAME \
--registry-password $ACR_PASSWORD \
--target-port 80 \
--ingress external \
--env-vars AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY \
AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT \
AZURE_OPENAI_DEPLOYMENT_NAME=$AZURE_OPENAI_DEPLOYMENT_NAME \
AZURE_OPENAI_API_VERSION=$AZURE_OPENAI_API_VERSION
else
echo "Updating existing Container App..."
az containerapp update \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--image $ACR_NAME.azurecr.io/$IMAGE_NAME:$IMAGE_TAG
fi
# Step 10: Configure autoscaling if needed
echo "Configuring autoscaling..."
az containerapp scale rule add \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--type http \
--http-concurrency 20 \
--min-replicas 1 \
--max-replicas 10
# Step 11: Get the application URL
echo "Getting the application URL..."
CONTAINER_APP_URL=$(az containerapp show \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--query properties.configuration.ingress.fqdn -o tsv)
echo "Deployment completed successfully!"
echo "Your application is available at: https://$CONTAINER_APP_URL"