Skip to content

Commit

Permalink
create template for cloud image for Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
StepanBakshayev committed Feb 13, 2023
1 parent 7ad54c2 commit e98b05c
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/manual_azure_stgn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Manual Azure build for STGN

on: [workflow_dispatch]

jobs:
azure-image-build:
defaults:
run:
working-directory: runner
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
strategy:
matrix:
variants: [ azure-image ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download packer
run: |
wget https://releases.hashicorp.com/packer/1.8.0/packer_1.8.0_linux_amd64.zip
unzip packer_1.8.0_linux_amd64.zip
chmod +x packer
cp -R ami/packer/* .
- name: Run packer
run: |
VERSION=${{ github.run_number }}
./packer build -var build_id=$VERSION ${{ matrix.variants }}.json
52 changes: 51 additions & 1 deletion runner/ami/packer/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,54 @@ To run, you need to specify AWS credentials in ENV
## Build Ubuntu AMI (with CUDA)
```shell
packer build packer.json
```
```

# Azure

## Allocate resources (make credentials)

Follow [installation instruction](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt)
for Azure CLI `az`. [Login](https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli) for managing resources:

```commandline
$ az login
```

Steps below follows [HOWTO](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/build-image-with-packer).
Create group as container for result image. Value `packer` is from property `managed_image_resource_group_name` of
`azure-arm` packer's builder. Value `eastus` is property `location` of `azure-arm` (Azure has two kind notation for
the same location).

```commandline
$ az group create -n packer -l eastus
```

Packer allocates resources on its own. It requires access to subscription. Obtain id.

```commandline
$ az account show --query "{ subscription_id: id }"
{
"subscription_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
}
```

Create credentials for packer.

```commandline
$ az ad sp create-for-rbac --role Contributor --scopes /subscriptions/<subscription_id> --query "{ client_id: appId, client_secret: password, tenant_id: tenant }"
{
"client_id": "f5b6a5cf-fbdf-4a9f-b3b8-3c2cd00225a4",
"client_secret": "0e760437-bf34-4aad-9f8d-870be799c55d",
"tenant_id": "72f988bf-86f1-41af-91ab-2d7cd011db47"
}
```

Set environment variables.

| Env | Azure |
|-----|-------|
| AZURE_CLIENT_ID | client_id |
| AZURE_CLIENT_SECRET | client_secret |
| AZURE_TENANT_ID | tenant_id |
| AZURE_SUBSCRIPTION_ID | subscription_id |

86 changes: 86 additions & 0 deletions runner/ami/packer/azure-image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"min_packer_version": "1.8",
"variables": {
"azure_client_id": "{{env `AZURE_CLIENT_ID`}}",
"azure_client_secret": "{{env `AZURE_CLIENT_SECRET`}}",
"azure_tenant_id": "{{env `AZURE_TENANT_ID`}}",
"azure_subscription_id": "{{env `AZURE_SUBSCRIPTION_ID`}}",
"azure_location": "East US",
"azure_vm_size": "Standard_DS2_v2",
"build_id": "{{timestamp}}",
"build_prefix": "stgn-",
"docker_version": "20.10.17",
"dstack_stage": "STGN"
},
"builders": [{
"type": "azure-arm",
"client_id": "{{user `azure_client_id`}}",
"client_secret": "{{user `azure_client_secret`}}",
"tenant_id": "{{user `azure_tenant_id`}}",
"subscription_id": "{{user `azure_subscription_id`}}",
"managed_image_resource_group_name": "packer",
"managed_image_name": "{{user `build_prefix`}}dstack-{{user `build_id`}}",
"os_type": "Linux",
"image_publisher": "Canonical",
"image_offer": "UbuntuServer",
"image_sku": "18.04-DAILY-LTS",
"azure_tags": {
"Name": "DSTACK"
},
"location": "{{user `azure_location`}}",
"vm_size": "{{user `azure_vm_size`}}"
}],
"provisioners": [
{
"type": "shell",
"inline": ["cloud-init status --long --wait"]
},
{
"type": "shell",
"scripts": [
"provisioners/kernel/apt-upgrade.sh",
"provisioners/kernel/apt-daily.sh",
"provisioners/kernel/apt-packages.sh",
"provisioners/kernel/kernel-tuning.sh"
]
},
{
"type": "shell",
"environment_vars": ["DSTACK_STAGE={{user `dstack_stage`}}"],
"script": "provisioners/get-dstack-runner.sh"
},
{
"type": "file",
"source": "provisioners/install-docker.sh",
"destination": "/tmp/install-docker.sh"
},
{
"type": "file",
"source": "provisioners/run-docker",
"destination": "/tmp/run-docker"
},
{
"type": "shell",
"inline_shebang": "/bin/sh -x",
"inline": [
"cd /tmp",
"chmod +x install-docker.sh",
"./install-docker.sh --version {{user `docker_version`}}"
]
},
{
"type": "shell",
"script": "provisioners/docker-image-without-cuda.sh"
},
{
"type": "shell",
"inline_shebang": "/bin/sh -x",
"inline": ["/usr/local/bin/dstack-runner --version"]
},
{
"type": "shell",
"inline_shebang": "/bin/sh -x",
"inline": ["/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"]
}
]
}

0 comments on commit e98b05c

Please sign in to comment.