Skip to content

Commit ef0a352

Browse files
committed
azblob cache: account_name attribute
By default account name is parsed from request uri host (account url) but when product style url is disabled, account name is not part of the host. This new attribute allows to specify the account name in such case. Also return error if account name is empty. Signed-off-by: CrazyMax <[email protected]>
1 parent 983554b commit ef0a352

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ There are 2 options supported for Azure Blob Storage authentication:
536536
* Any system using environment variables supported by the [Azure SDK for Go](https://docs.microsoft.com/en-us/azure/developer/go/azure-sdk-authentication). The configuration must be available for the buildkit daemon, not for the client.
537537
* Secret Access Key, using the `secret_access_key` attribute to specify the primary or secondary account key for your Azure Blob Storage account. [Azure Blob Storage account keys](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
538538

539+
> **Note**
540+
>
541+
> Account name can also be specified with `account_name` attribute (or `$BUILDKIT_AZURE_STORAGE_ACCOUNT_NAME`)
542+
> if it is not part of the account URL host.
543+
539544
`--export-cache` options:
540545
* `type=azblob`
541546
* `mode=<min|max>`: specify cache layers to export (default: `min`)

cache/remotecache/azblob/utils.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
const (
1717
attrSecretAccessKey = "secret_access_key"
18+
attrAccountName = "account_name"
1819
attrAccountURL = "account_url"
1920
attrPrefix = "prefix"
2021
attrManifestsPrefix = "manifests_prefix"
@@ -50,7 +51,16 @@ func getConfig(attrs map[string]string) (*Config, error) {
5051
return &Config{}, errors.Wrap(err, "azure storage account url provided is not a valid url")
5152
}
5253

53-
accountName := strings.Split(accountURL.Hostname(), ".")[0]
54+
accountName, ok := attrs[attrAccountName]
55+
if !ok {
56+
accountName, ok = os.LookupEnv("BUILDKIT_AZURE_STORAGE_ACCOUNT_NAME")
57+
if !ok {
58+
accountName = strings.Split(accountURL.Hostname(), ".")[0]
59+
}
60+
}
61+
if accountName == "" {
62+
return &Config{}, errors.New("unable to retrieve account name from account url or ${BUILDKIT_AZURE_STORAGE_ACCOUNT_NAME} or account_name attribute for azblob cache")
63+
}
5464

5565
container, ok := attrs[attrContainer]
5666
if !ok {

0 commit comments

Comments
 (0)