Skip to content

Commit

Permalink
Azure Container App one click deployment (#165)
Browse files Browse the repository at this point in the history
* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure HPA one click deployment - DRAFT

* Azure Container App one click deployment
  • Loading branch information
EugeneLightsOn authored Jun 4, 2024
1 parent d089057 commit f5ad3ee
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 6 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build_and_push_docker_proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
name: Create and publish single container image with nginx proxy

on:
release:
types: [published]
workflow_dispatch:
inputs:
tags:
description: "tags to attach to image"
required: false
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: cohere-toolkit-proxy

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/cohere-ai/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
file: ./Dockerfile
- name: Test the Docker image
run: |
docker run -d -p 8000:8000 $REGISTRY/cohere-ai/$IMAGE_NAME
sleep 30
status_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health)
if [ $status_code -eq 200 ]; then
echo "Backend started successfully"
else
echo "Backend failed to start"
exit 1
fi
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN pip3 install --no-cache-dir poetry==1.6.1 \
&& poetry config installer.max-workers 10 \
&& poetry install --without setup \
&& poetry install \
&& (poetry cache clear --all --no-interaction PyPI || true) \
&& (poetry cache clear --all --no-interaction _default_cache || true)

Expand Down
206 changes: 206 additions & 0 deletions azuredeploy.hpa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2022-10-01",
"name": "[parameters('containerAppLogAnalyticsName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "PerGB2018"
}
}
},
{
"type": "Microsoft.App/managedEnvironments",
"apiVersion": "2023-11-02-preview",
"name": "[parameters('containerAppEnvName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Consumption"
},
"properties": {
"appLogsConfiguration": {
"destination": "log-analytics",
"logAnalyticsConfiguration": {
"customerId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces', parameters('containerAppLogAnalyticsName'))).customerId]",
"sharedKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', parameters('containerAppLogAnalyticsName')), '2022-10-01').primarySharedKey]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', parameters('containerAppLogAnalyticsName'))]"
]
},
{
"type": "Microsoft.App/containerApps",
"apiVersion": "2022-06-01-preview",
"name": "[parameters('containerAppName')]",
"location": "[parameters('location')]",
"properties": {
"managedEnvironmentId": "[resourceId('Microsoft.App/managedEnvironments', parameters('containerAppEnvName'))]",
"configuration": {
"ingress": {
"external": true,
"targetPort": "[parameters('targetPort')]",
"allowInsecure": false,
"traffic": [
{
"latestRevision": true,
"weight": 100
}
]
}
},
"template": {
"containers": [
{
"name": "[parameters('containerAppName')]",
"image": "[parameters('image')]",
"resources": {
"cpu": "[json(parameters('cpuCore'))]",
"memory": "[format('{0}Gi', parameters('memorySize'))]"
},
"env": [
{
"name": "DATABASE_URL",
"value": "[parameters('databaseUrl')]"
},
{
"name": "COHERE_API_KEY",
"value": "[parameters('cohereApiKey')]"
}
]
}
],
"scale": {
"minReplicas": "[parameters('minReplicas')]",
"maxReplicas": "[parameters('maxReplicas')]",
"rules": [
{
"name": "http-scale-rule",
"http": {
"metadata": {
"concurrentRequests": "100"
}
}
}
]
}
}
},
"dependsOn": [
"[resourceId('Microsoft.App/managedEnvironments', parameters('containerAppEnvName'))]"
]
}
],
"parameters": {
"containerAppName": {
"type": "string",
"defaultValue": "[format('toolkit-app-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specifies the name of the container app."
}
},
"containerAppEnvName": {
"type": "string",
"defaultValue": "[format('toolkit-env-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specifies the name of the container app environment."
}
},
"containerAppLogAnalyticsName": {
"type": "string",
"defaultValue": "[format('toolkit-log-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specifies the name of the log analytics workspace."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location for all resources."
}
},
"targetPort": {
"type": "int",
"defaultValue": 4000,
"metadata": {
"description": "Specifies the container port."
}
},
"cpuCore": {
"type": "string",
"defaultValue": "2",
"allowedValues": [
"0.25",
"0.5",
"0.75",
"1",
"1.25",
"1.5",
"1.75",
"2"
],
"metadata": {
"description": "Number of CPU cores the container can use. Can be with a maximum of two decimals."
}
},
"memorySize": {
"type": "string",
"defaultValue": "4",
"allowedValues": [
"0.5",
"1",
"1.5",
"2",
"3",
"3.5",
"4"
],
"metadata": {
"description": "Amount of memory (in gibibytes, GiB) allocated to the container up to 4GiB. Can be with a maximum of two decimals. Ratio with CPU cores must be equal to 2."
}
},
"minReplicas": {
"type": "int",
"defaultValue": 1,
"maxValue": 2,
"minValue": 0,
"metadata": {
"description": "Minimum number of replicas that will be deployed"
}
},
"maxReplicas": {
"type": "int",
"defaultValue": 1,
"maxValue": 2,
"minValue": 0,
"metadata": {
"description": "Maximum number of replicas that will be deployed"
}
},
"image": {
"type": "string",
"defaultValue": "ghcr.io/cohere-ai/cohere-toolkit-proxy",
"metadata": {
"description": "Docker image to deploy"
}
},
"databaseUrl": {
"type": "string",
"metadata": {
"description": "Your Database connection URL"
}
},
"cohereApiKey": {
"type": "string",
"metadata": {
"description": "Your Cohere API key for the application"
}
}
}
}
28 changes: 23 additions & 5 deletions docs/service_deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@ Looking to serve your application in production? Deploy the Toolkit to your pref
- [AWS ECS Fargate Deployment](deployment_guides/aws_ecs_single_container.md): Deploy the Toolkit single container to AWS ECS(Fargate).
- [AWS ECS EC2 Deployment](deployment_guides/aws_ecs_single_container_ec2.md): Deploy the Toolkit single container to AWS ECS(EC2).
- [Google Cloud Platform](deployment_guides/gcp_deployment.md): Help setup your Cloud SQL instance, then build, push and deploy backend+frontend containers to Cloud Run.
- Deploying to Azure. You can deploy Toolkit with one click to Microsoft Azure Platform: [<img src="https://aka.ms/deploytoazurebutton" height="24px">](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fcohere-ai%2Fcohere-toolkit%2Fmain%2Fazuredeploy.json). This deployment type uses Azure Container Instances to host the Toolkit. After your deployment is complete click "Go to resource" button.
1) Check the logs to see if the container is running successfully:
- [One Click Deploy to GCP](deployment_guides/gcp_one_click_deployment.md): Help setup your container to Cloud Run.
- Deploying to Azure Container Instance. You can deploy Toolkit with one click to Microsoft Azure Platform: [<img src="https://aka.ms/deploytoazurebutton" height="24px">](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fcohere-ai%2Fcohere-toolkit%2Fmain%2Fazuredeploy.json).
This deployment type uses Azure Container Instances to host the Toolkit. After your deployment is complete click "Go to resource" button.
- Check the logs to see if the container is running successfully:
- click on the "Containers" button on the left side of the screen
- click on the container name
- click on "Logs" tab to see the logs
2) Navigate to the "Overview" tab to see the FQDN of the container instance
3) Open the \<FQDN\>:4000 in your browser to access the Toolkit
- [One Click Deploy to GCP](deployment_guides/gcp_one_click_deployment.md): Help setup your container to Cloud Run.
- Navigate to the "Overview" tab to see the FQDN of the container instance
- Open the \<FQDN\>:4000 in your browser to access the Toolkit
- Deploying to Azure Cloud App. You can deploy Toolkit with one click to Microsoft Azure Platform: [<img src="https://aka.ms/deploytoazurebutton" height="24px">](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fcohere-ai%2Fcohere-toolkit%2Feugene%2FEXT2-69_azure_hpa%2Fazuredeploy.hpa.json).
This deployment type uses Azure Container App to host the Toolkit. Follow these steps to deploy the Toolkit:
- Select your subscription and resource group. If you don't have a resource group, create a new one.
- Enter the connection string of the format `postgresql+psycopg2://USERNAME:PASSWORD@HOST:PORT/DB_NAME`.
The `HOST` value here is the Public IP address or DNS name of your provisioned PostgreSQL database, and the default `PORT` is 5432.
Make sure to use the username and password pair you set when creating your SQL instance. For example, `postgresql+psycopg2://myuser:mypassword@<your-db-public-ip-address>:5432/toolkit`.
- Enter your Cohere API key.
- Click "Review + create" and then "Create" to deploy the Toolkit.
- After the deployment is complete, click on the "Go to resource group" button.
- Click on the Toolkit container app.
- Click on the "Overview" tab to see the "Application Url" of the container app.
- Navigate to the "Application Url" to access the Toolkit.

To scale the Toolkit, you can enable the Automatic Horizontal Scaling by following this [tutorial](https://learn.microsoft.com/en-us/azure/container-apps/tutorial-scaling).



0 comments on commit f5ad3ee

Please sign in to comment.