Last active
August 12, 2024 18:48
-
-
Save damienpontifex/4a4874d55e17a395a96a51e6ac9ba6ea to your computer and use it in GitHub Desktop.
Bazel remote cache with Azure Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interactive read the storage account name | |
read -p "Storage account name: " STORAGE_ACCOUNT | |
# Or set variable directly here | |
# STORAGE_ACCOUNT=azurestorageaccountname | |
STORAGE_CONTAINER=bazel-cpp-tutorial | |
ACCESS_TOKEN=$(az account get-access-token \ | |
--resource="https://${STORAGE_ACCOUNT}.blob.core.windows.net/" \ | |
--query accessToken --output tsv) | |
bazel build //... \ | |
--remote_cache="https://${STORAGE_ACCOUNT}.blob.core.windows.net/${STORAGE_CONTAINER}" \ | |
--remote_header="Authorization=Bearer ${ACCESS_TOKEN}" \ | |
--remote_header='x-ms-version=2021-06-08' \ | |
--remote_header='x-ms-blob-type=BlockBlob' \ | |
--verbose_failures | |
# Can also use the below flag which might make sense for PR or local builds | |
# --remote_upload_local_results=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use if creating storage account and want to automatically delete old cache data after 30 days of no access | |
az storage account create \ | |
--name <storage-account> \ | |
--location <location> \ | |
--resource-group <resource-group> \ | |
--access-tier Hot \ | |
--https-only true \ | |
--kind StorageV2 \ | |
--sku Standard_LRS \ | |
--min-tls-version TLS1_2 \ | |
--public-network-access Disabled | |
az storage account blob-service-properties update \ | |
--resource-group <resource-group> \ | |
--account-name <storage-account> \ | |
--enable-last-access-tracking true | |
az storage account management-policy create \ | |
--account-name <storage-account> \ | |
--policy @policy.json \ | |
--resource-group <resource-group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": [ | |
{ | |
"name": "deleteAfterAgingAccess", | |
"enabled": true, | |
"type": "Lifecycle", | |
"definition": { | |
"filters": { | |
"blobTypes": [ | |
"blockBlob" | |
], | |
"prefixMatch": [ | |
"sample-container" | |
] | |
}, | |
"actions": { | |
"baseBlob": { | |
"delete": { | |
"daysAfterLastAccessTimeGreaterThan": 30 | |
} | |
} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment