Skip to content

Instantly share code, notes, and snippets.

@notheotherben
Last active April 2, 2020 20:07
Show Gist options
  • Save notheotherben/7c57eb9864824e06be8af63dcc40e9fa to your computer and use it in GitHub Desktop.
Save notheotherben/7c57eb9864824e06be8af63dcc40e9fa to your computer and use it in GitHub Desktop.
COVID-19 F@H AzureVM Template

COVID-19 F@H Azure VM Template

Deploy an Azure VM to help Folding@Home

⚠️ For the latest version, please take a look at the new repo.

This is an Azure VM template which deploys a GPU-enabled VM of your choice to help the Folding@Home project find ways to combat COVID-19. It is expected that the default VM (Standard_NC6_Promo) will cost about $350 per month to run (depending on your choice of region etc) which means that on the stock Azure trial benefit you should be able to get about 2 weeks of runtime before running out of free credits.

Instructions

To deploy this template, you'll need to first create a Resource Group and then deploy this template to it. You'll find instructions for how to do so over here:

Once your VM has been deployed, it will install the F@H client and start folding. You can monitor its progress by running ssh folding@<your VM's IP> tail -f /var/lib/fahclient/log.txt.

Parameters

Name (default: covid19folding)

This is the name of the virtual machine which will be deployed. Feel free to customize this if you want to.

Location (default: [resourceGroup().location])

This is the location in which the virtual machine will be deployed. Some locations are cheaper than others, so feel free to change this if it makes sense for you. By default, it will use the location that your resource group is created in.

Sku (default: Standard_NC6_Promo)

The type of virtual machine which will be provisioned. The Standard_NC6_Promo SKU includes an NVIDIA Tesla K80 accelerator card which will greatly speed up your contributions to the F@H project. Other options may have more modern, or a greater number, of accelerator cards. You can find out more here.

Fah_team (default: 240722)

The Folding@Home team you wish to contribute towards. By default this is the Azure SRE team (since we're using this template on our personal subscriptions to help out) but feel free to change this to your own if you prefer.

Ssh_key

This should be your SSH public key and is used to allow you to SSH into your machine to check on its status at any time. You can get it by running cat ~/.ssh/id_rsa.pub on your machine, or using ssh-keygen to create a key-pair if you haven't already.

IMPORTANT if you want to SSH into your instance, you can do so with the username folding.

Credits

Thank you to @lupino3 and @nickstenning for their contributions to building this template.

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"defaultValue": "covid19folding",
"metadata": {
"description": "The name used to identify your virtual machine."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location in which your virtual machine will be deployed."
}
},
"sku": {
"type": "string",
"defaultValue": "Standard_NC6_Promo",
"allowedValues": [
"Standard_NC6_Promo",
"Standard_NC12_Promo",
"Standard_NC24_Promo",
"Standard_NC6",
"Standard_NC12",
"Standard_NC24",
"Standard_NC6s_v2",
"Standard_NC12s_v2",
"Standard_NC24s_v2",
"Standard_NC6s_v3",
"Standard_NC12s_v3",
"Standard_NC24s_v3"
],
"metadata": {
"description": "The virtual machine SKU to use when running F@H."
}
},
"fah_team": {
"type": "int",
"defaultValue": 240722,
"minValue": 0,
"metadata": {
"description": "The ID of the Folding@Home team you wish to contribute towards."
}
},
"ssh_key": {
"type": "securestring",
"metadata": {
"description": "Your SSH public key"
}
}
},
"variables": {
"adminUsername": "folding",
"cloudinit-lines": [
"#cloud-config",
"package_upgrade: true",
"",
"write_files:",
" - path: /etc/fahclient/config.xml",
" content: |",
" <config>",
" <!-- Client Control -->",
" <fold-anon v='true' />",
" ",
" <!-- Folding Slot Configuration -->",
" <gpu v='true' />",
" ",
" <!-- Slot Control -->",
" <power v='full' />",
" ",
" <!-- User Information -->",
" <user v='Anonymous' />",
"[concat(' <team v=''', parameters('fah_team'), ''' />')]",
" ",
" <!-- Folding Slots -->",
" <slot id='0' type='CPU' />",
" <slot id='1' type='GPU' />",
" ",
" </config>",
"",
"runcmd:",
" - [ add-apt-repository, 'ppa:graphics-drivers/ppa' ]",
" - [ apt, install, -y, nvidia-headless-440, ocl-icd-opencl-dev ]",
" - [ sh, -xc, 'echo fahclient fahclient/autostart boolean true | debconf-set-selections' ]",
" - [ wget, 'https://download.foldingathome.org/releases/public/release/fahclient/debian-stable-64bit/v7.5/fahclient_7.5.1_amd64.deb', -O, '/tmp/fahclient.deb' ]",
" - [ dpkg, -i, --force-depends, /tmp/fahclient.deb ]",
""
],
"cloudinit": "[utils.join(variables('cloudinit-lines'))]",
"nsgName": "[concat(parameters('name'), '_nsg')]",
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('nsgName'))]",
"nicName": "[concat(parameters('name'), '_nic')]",
"ipName": "[concat(parameters('name'), 'ip')]",
"vnetName": "[concat(parameters('name'), '-vnet')]",
"subnetName": "default",
"vnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks', variables('vnetName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]"
},
"functions": [
{
"namespace": "utils",
"members": {
"join": {
"parameters": [
{
"name": "lines",
"type": "array"
}
],
"output": {
"type": "string",
"value": "[replace(replace(replace(string(parameters('lines')), '[\"', ''), '\"]', ''), '\",\"', '\n')]"
}
}
}
}
],
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-11-01",
"name": "[variables('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.27.0.0/24"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "10.27.0.0/24",
"delegations": [
],
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
}
],
"virtualNetworkPeerings": [
],
"enableDdosProtection": false,
"enableVmProtection": false
}
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2019-11-01",
"name": "[concat(variables('vnetName'), '/', variables('subnetName'))]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
],
"properties": {
"addressPrefix": "10.27.0.0/24",
"delegations": [
],
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
},
{
"name": "[variables('nicName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), variables('subnetName'))]",
"[concat('Microsoft.Network/networkSecurityGroups/', variables('nsgName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', variables('ipName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', variables('ipName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
}
},
{
"name": "[variables('nsgName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "SSH",
"properties": {
"priority": 300,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "22"
}
}
]
}
},
{
"name": "[variables('ipName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIpAllocationMethod": "Dynamic",
"idleTimeoutInMinutes": 4
},
"sku": {
"name": "Basic"
}
},
{
"name": "[parameters('name')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('sku')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "18.04-LTS",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('name')]",
"adminUsername": "[variables('adminUsername')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', variables('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('ssh_key')]"
}
]
}
},
"customData": "[base64(variables('cloudinit'))]"
}
}
}
],
"outputs": {
"foldingAtHomeTeam": {
"type": "int",
"value": "[parameters('fah_team')]"
},
"adminUsername": {
"type": "string",
"value": "[variables('adminUsername')]"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment