.travis, build: autodelete old unstable archives (#13867)
This commit adds a build step to travis to auto-delete unstable archives older than 14 days (our regular release schedule) from Azure via ci.go purge. The commit also pulls in the latest Azure storage code, also switching over from the old import path (github.com/Azure/azure-sdk-for-go) to the new split one (github.com/Azure/azure-storage-go).
This commit is contained in:
committed by
Felix Lange
parent
3d8de95f99
commit
c76ad94492
@ -20,7 +20,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/storage"
|
||||
storage "github.com/Azure/azure-storage-go"
|
||||
)
|
||||
|
||||
// AzureBlobstoreConfig is an authentication and configuration struct containing
|
||||
@ -42,7 +42,6 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
|
||||
fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create an authenticated client against the Azure cloud
|
||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
||||
if err != nil {
|
||||
@ -63,3 +62,50 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
|
||||
}
|
||||
return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil)
|
||||
}
|
||||
|
||||
// AzureBlobstoreList lists all the files contained within an azure blobstore.
|
||||
func AzureBlobstoreList(config AzureBlobstoreConfig) ([]storage.Blob, error) {
|
||||
// Create an authenticated client against the Azure cloud
|
||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := rawClient.GetBlobService()
|
||||
|
||||
// List all the blobs from the container and return them
|
||||
container := client.GetContainerReference(config.Container)
|
||||
|
||||
blobs, err := container.ListBlobs(storage.ListBlobsParameters{
|
||||
MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them
|
||||
Timeout: 3600, // Yes, wait for all of them
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return blobs.Blobs, nil
|
||||
}
|
||||
|
||||
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
|
||||
// from the blobstore.
|
||||
func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) error {
|
||||
if *DryRunFlag {
|
||||
for _, blob := range blobs {
|
||||
fmt.Printf("would delete %s (%s) from %s/%s\n", blob.Name, blob.Properties.LastModified, config.Account, config.Container)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Create an authenticated client against the Azure cloud
|
||||
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := rawClient.GetBlobService()
|
||||
|
||||
// Iterate over the blobs and delete them
|
||||
for _, blob := range blobs {
|
||||
if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user