Skip to main content

部署到 Azure 容器应用

note

本指南由社区贡献,尚未经过 Remotion 团队测试。

本指南提供了在 Azure Container Apps 上部署带有基本渲染队列的 Remotion 渲染服务的操作步骤。

🌐 This guide provides a walkthrough for deploying Remotion rendering service with basic render queuing on Azure Container Apps.

先决条件

🌐 Prerequisites

  • 一个可运行的 Remotion 项目(例如,来自 npm create video),并提供使用 Docker 的功能。
  • 一个 Azure 账户
  • 需要对 Docker 有基本了解,并在系统上安装它。
  • 已安装 Azure CLI、完成身份验证(azure login)并在身份验证后选择了订阅。
  • Azure 账户已配置为在 Azure Container Apps 上使用 GPU,如果没有,请在 这里 申请。
  • 一个 docker hub 账户 用于托管 docker 镜像并进行身份验证(docker login)。

第1步:选择一个项目

🌐 Step 1: Pick a project

为了简便起见,我们将使用 remotion-gpu,它配置为利用 GPU 加速。该项目基于 Remotion render server template,并使用来自 gpu-scene 项目的 scene 组合。

🌐 For simplicity, we'll use remotion-gpu which is configured to leverage GPU acceleration. This project is based with Remotion render server template and uses the scene composition from gpu-scene project.

步骤2:构建并标记 Docker 镜像

🌐 Step 2: Build and tag the docker image

在项目目录下,构建 Docker 镜像并使用你的账号将其推送到 Docker Hub,指定镜像名称和版本标签。image-nameremotion-docker-gpuversion1.0.0

🌐 From the project directory, build the Docker image and push it to Docker Hub with your account, specifying an image name and version tag. The image-name is remotion-docker-gpu and version is 1.0.0.

docker build -t your-dockerhub-username/remotion-docker-gpu:1.0.0 .

步骤3:将镜像推送到Docker Hub

🌐 Step 3: Push the image to docker hub

docker push your-dockerhub-username/remotion-docker-gpu:1.0.0

第4步:设置环境变量

🌐 Step 4: Set environment variables

azure cli 设置环境变量

🌐 Set the environment variables for the azure cli

Set environment variables
CONTAINER_IMAGE="docker.io/your-dockerhub-username/remotion-docker-gpu:1.0.0" RESOURCE_GROUP="<RESOURCE_GROUP>" ENVIRONMENT_NAME="<ENVIRONMENT_NAME>" LOCATION="swedencentral" CONTAINER_APP_NAME="<CONTAINER_APP_NAME>" WORKLOAD_PROFILE_NAME="NC8as-T4" WORKLOAD_PROFILE_TYPE="Consumption-GPU-NC8as-T4"

变量表示

🌐 Variable representation

  • CONTAINER_IMAGE 代表 docker.io 域和 Docker 镜像。
  • LOCATION 表示分配 GPU 的区域。
  • WORKLOAD_PROFILE_NAMEWORKLOAD_PROFILE_TYPE 是来自 Azure 文档 的常量变量,表示要使用的 GPU 系列。

第5步:创建资源组

🌐 Step 5: Create the resource group

az group create \
  --name $RESOURCE_GROUP \
  --location $LOCATION \
  --query "properties.provisioningState"

第6步:注册洞察以进行监控

🌐 Step 6: Register insights for monitoring

az provider register -n Microsoft.OperationalInsights --wait

第7步:创建容器应用环境

🌐 Step 7: Create a Container Apps environment

az containerapp env create \
  --name $ENVIRONMENT_NAME \
  --resource-group $RESOURCE_GROUP \
  --location "$LOCATION" \
  --query "properties.provisioningState"

步骤 8:向你的环境添加工作负载配置文件

🌐 Step 8: Add a workload profile to your environment

az containerapp env workload-profile add \
  --name $ENVIRONMENT_NAME \
  --resource-group $RESOURCE_GROUP \
  --workload-profile-name $WORKLOAD_PROFILE_NAME \
  --workload-profile-type $WORKLOAD_PROFILE_TYPE

第9步:部署容器应用

🌐 Step 9: Deploy container app

az containerapp create \
  --name $CONTAINER_APP_NAME \
  --resource-group $RESOURCE_GROUP \
  --environment $ENVIRONMENT_NAME \
  --image $CONTAINER_IMAGE \
  --target-port 3000 \
  --ingress external \
  --cpu 8.0 \
  --memory 56.0Gi \
  --workload-profile-name $WORKLOAD_PROFILE_NAME \
  --query properties.configuration.ingress.fqdn

Azure CLI 将把镜像部署到 Azure Container Apps,完成后会提供一个接受 HTTP 请求的 URL。

Deployment Output (example)
Container app created. Access your app at https://remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io/ "remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io"
note

target-portportNode.js 服务器用它来监听传入请求。步骤 4 到 9 基于 Azure 容器应用 文档。

第10步:触发渲染

🌐 Step 10: Trigger a Render

向服务的 /renders 端点发送 POST 请求。将 YOUR_SERVICE_URL 替换为部署输出中的 URL,即 https://remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io/

🌐 Send a POST request to the service's /renders endpoint. Replace YOUR_SERVICE_URL with the URL from the deployment output, https://remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io/.

curl -X POST {YOUR_SERVICE_URL}/renders \
-H "Content-Type: application/json" \
-d '{}'

Response

如果成功,API将响应JSON,其中包含可用于获取渲染状态的jobId

🌐 If successful, the API will respond with JSON containing the jobId which can be used to get the status of render.

Example Response
{ "jobId": "955338f6-2607-48bd-bedb-6d4c98f7b4dc" }

第11步:获取渲染状态

🌐 Step 11: Get render status

发送 GET 请求以获取渲染状态,将 YOUR_SERVICE_URL 替换为部署输出中的 URL,将 jobId 替换为渲染请求输出中的值。

🌐 Send a GET request to get the render status, replace YOUR_SERVICE_URL with the URL from the deployment output and the jobId from the render request output.

curl  {YOUR_SERVICE_URL}/renders/{jobId}

Response

Example Response
{ "status": "completed", "videoUrl": "/renders/955338f6-2607-48bd-bedb-6d4c98f7b4dc.mp4", "data": {"titleText": "Hello, world!"} }

如果 statuscompleted,将 YOUR_SERVICE_URLvideoUrl 的响应结合起来生成下载链接(https://remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io/renders/955338f6-2607-48bd-bedb-6d4c98f7b4dc.mp4)。

🌐 If status is completed, combine YOUR_SERVICE_URL and the videoUrl response to generate the download link (https://remotion-gpu.grayocean-24741fc9.australiaeast.azurecontainerapps.io/renders/955338f6-2607-48bd-bedb-6d4c98f7b4dc.mp4).

步骤12:(Optional)删除资源组

🌐 Step 12: (Optional) Delete the resource group

az group delete --name $RESOURCE_GROUP

这将删除资源组内的所有资源,包括应用容器。

🌐 This will delete all the resources inside the resource group including the application container.

warning

成本:此实现不包括成本管理。有关使用量估算,请参考 Azure 定价文档。使用风险自担。 性能:生成的视频可能会显得模糊。项目中已配置 GPU 加速 config,但实际 GPU 利用率尚未确认。

另请参阅

🌐 See also