Open project-oagent-gh-app[bot] opened 1 month ago
The user's code can be wrapped in a bash script as follows:
#!/bin/bash
# Create a file with desired commands
echo "
# Install Azure CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Install .Net Core SDK
wget https://download.visualstudio.microsoft.com/download/pr/95e91e8e-496e-4f22-8d12-573aa5aa67f6/32cc5f113a3a10f6e6c4d8a4e2d6f203/dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz
mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz -C $HOME/dotnet
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet
" > script.sh
# Create a bash shell script file to create resource group and VM with custom data from file
echo "
az group create --name myResourceGroupAutomate --location eastus
az vm create \
--resource-group myResourceGroupAutomate \
--name myAutomatedVM \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys \
--custom-data script.sh
" > setup.sh
# Create a bash shell script file to create a VM extension for installing nginx
echo "
az vm extension set \
--resource-group myResourceGroup \
--vm-name myVM --name customScript \
--publisher Microsoft.Azure.Extensions \
--settings '{\"commandToExecute\": \"apt-get install -y nginx\"}'
" > nginx_setup.sh
This script will create three separate bash scripts: script.sh
that contains the code from the user, setup.sh
that creates a resource group and a VM with Azure CLI, and nginx_setup.sh
that sets up a VM extension for installing Nginx.
{ 'code': "# Install Azure CLI curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Install .Net Core SDK
wget https://download.visualstudio.microsoft.com/download/pr/95e91e8e-496e-4f22-8d12-573aa5aa67f6/32cc5f113a3a10f6e6c4d8a4e2d6f203/dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz -C $HOME/dotnet export DOTNET_ROOT=$HOME/dotnet export PATH=$PATH:$HOME/dotnet" }