vuls: init at 0.27.0
[NixPkgs.git] / nixos / maintainers / scripts / azure-new / upload-image.sh
blob143afbd7f962ea9885ffd8dbb45e30b0adfa7174
1 #!/usr/bin/env bash
2 set -euo pipefail
3 set -x
5 image_nix="${1:-"./examples/basic/image.nix"}"
7 nix-build "${image_nix}" --out-link "azure"
9 group="nixos-images"
10 location="westus2"
11 img_name="nixos-image"
12 img_file="$(readlink -f ./azure/disk.vhd)"
14 if ! az group show -n "${group}" &>/dev/null; then
15 az group create --name "${group}" --location "${location}"
18 # note: the disk access token song/dance is tedious
19 # but allows us to upload direct to a disk image
20 # thereby avoid storage accounts (and naming them) entirely!
21 if ! az disk show -g "${group}" -n "${img_name}" &>/dev/null; then
22 bytes="$(stat -c %s ${img_file})"
23 size="30"
24 az disk create \
25 --resource-group "${group}" \
26 --name "${img_name}" \
27 --for-upload true --upload-size-bytes "${bytes}"
29 timeout=$(( 60 * 60 )) # disk access token timeout
30 sasurl="$(\
31 az disk grant-access \
32 --access-level Write \
33 --resource-group "${group}" \
34 --name "${img_name}" \
35 --duration-in-seconds ${timeout} \
36 | jq -r '.accessSas'
39 azcopy copy "${img_file}" "${sasurl}" \
40 --blob-type PageBlob
42 az disk revoke-access \
43 --resource-group "${group}" \
44 --name "${img_name}"
47 if ! az image show -g "${group}" -n "${img_name}" &>/dev/null; then
48 diskid="$(az disk show -g "${group}" -n "${img_name}" -o json | jq -r .id)"
50 az image create \
51 --resource-group "${group}" \
52 --name "${img_name}" \
53 --source "${diskid}" \
54 --os-type "linux" >/dev/null
57 imageid="$(az image show -g "${group}" -n "${img_name}" -o json | jq -r .id)"
58 echo "${imageid}"