This README describes:
- Running a remote predictoor or trader bot (agent), on Azure
- On a remote network where other bots are remote
- It uses containers
You will build a container, upload it to Azure Container Registry, and finally run it using Azure Container Instances.
This example uses Sapphire testnet; you can modify envvars to run on Sapphire mainnet.
Steps:
- Setup
- Build a container image
- Setup & run bot on Azure
- Install Azure CLI
- Build a container image of bot
- Setup ACR (Azure Container Registry)
- Push image to ACR
- Run image on ACI (Azure Container Instances)
- Monitor container logs
- Appendix
Warning These docs are up-to-date as of August 2023. If you encounter any issues or need the latest instructions, please see Azure docs on running containers.
The actions in this README require Docker or Podman to be installed.
The predictoor/trader bots run code that lives in pdr-backend
repo.
Here, we will build a container image for your bot.
In console, in the root directory of your repo, run:
# if docker
docker build -t pdr-backend-<botname>:latest .
# if podman
podman build -t pdr-backend-<botname>:latest .
Where botname
= the name of your bot.
This command builds a container image using the Dockerfile in the current directory and tag it as pdr-backend-<botname>:latest
. You can use any tag you'd like.
Here, we run the bot on Azure. (The Appendix lists other venues.)
Follow the instructions from Microsoft's website to install. Then type az login
in the terminal to log-in.
Next, create an Azure Container Registry (ACR) where you'll upload your container image.
Click here to view the documentation for az acr create
az acr create --name <ACR_NAME> --resource-group <resource group name> --sku <sku>
Where:
--name
: The name of the container registry. It should be specified in lower case. You will need it in the next step.--resource-group
: The name of the resource group where you want to create the ACR. You can learn more about managing resource groups from Azure's documentation.--sku
: Pricing tier for ACR, accepted values are:Basic
,Standard
,Premium
.
You can now push your container image to ACR. Don't forget to replace <acr_name>
with the name you gave to your ACR in the previous step.
Firstly, you'll need to provide docker or podman with access to your ACR.
Click here to view the documentation for az acr login
az acr login --name <acr_name>
Note If you need to get access token you can use
--expose-token
parameter and login usingpodman/docker login
command.
Push the container image to the registry.
# docker
docker tag pdr-backend-<botname>:latest <acr_name>.azurecr.io/pdr-backend-<botname>:latest
docker push <acr_name>.azurecr.io/pdr-backend-<botname>:latest
# podman
podman tag pdr-backend-<botname>:latest <acr_name>.azurecr.io/pdr-backend-<botname>:latest
podman push <acr_name>.azurecr.io/pdr-backend-<botname>:latest
The tag command is used to assign a new tag to your image. This is necessary because ACR requires a specific naming convention. After tagging the image, the push
command is used to upload the image to the registry.
Finally, you can run your image as a container on Azure Container Instances (ACI). Make sure to replace <acr_name>
with the actual name of your ACR.
To create a container instance with 1 core and 1Gb of memory: in console:
az container create --resource-group <resource-group-name> --name <container-instance-name> --image <acr-name>.azurecr.io/pdr-backend-<botname>:latest --cpu 1 --memory 1
Where:
--name
: The name of the container instance. You will need it in the next step.--resource-group
: The name of the resource group where you want to create the ACR. You can learn more about managing resource groups from Azure's documentation.--image
: The tag of the container image you've pushed to the registry in the previous step.
Note You can set envvars by passing
--environment-variables <env-variables>
parameter to theaz container create
command.
(Azure docs have more details.)
In console:
az container logs --resource-group <resource-group-name> --name <container-instance-name>
(Azure docs have more details.)
The Azure docs have more details, including on CLI commands.
You can also use the Azure Portal. It's a GUI to manage your container instances. Through it, you can create new instances, start & stop containers, scale them, and more.
Above, we focused on Azure. Here are several deployment options: