Skip to content

Commit fa01117

Browse files
authored
build/ci: handle split up listing (#21293)
1 parent 490b380 commit fa01117

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

build/ci.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@ func doPurge(cmdline []string) {
10981098
if err != nil {
10991099
log.Fatal(err)
11001100
}
1101+
fmt.Printf("Found %d blobs\n", len(blobs))
1102+
11011103
// Iterate over the blobs, collect and sort all unstable builds
11021104
for i := 0; i < len(blobs); i++ {
11031105
if !strings.Contains(blobs[i].Name, "unstable") {
@@ -1119,6 +1121,7 @@ func doPurge(cmdline []string) {
11191121
break
11201122
}
11211123
}
1124+
fmt.Printf("Deleting %d blobs\n", len(blobs))
11221125
// Delete all marked as such and return
11231126
if err := build.AzureBlobstoreDelete(auth, blobs); err != nil {
11241127
log.Fatal(err)

internal/build/azure.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,35 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
7171

7272
// AzureBlobstoreList lists all the files contained within an azure blobstore.
7373
func AzureBlobstoreList(config AzureBlobstoreConfig) ([]azblob.BlobItem, error) {
74-
credential, err := azblob.NewSharedKeyCredential(config.Account, config.Token)
75-
if err != nil {
76-
return nil, err
74+
credential := azblob.NewAnonymousCredential()
75+
if len(config.Token) > 0 {
76+
c, err := azblob.NewSharedKeyCredential(config.Account, config.Token)
77+
if err != nil {
78+
return nil, err
79+
}
80+
credential = c
7781
}
78-
7982
pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{})
8083

8184
u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", config.Account))
8285
service := azblob.NewServiceURL(*u, pipeline)
8386

87+
var allBlobs []azblob.BlobItem
8488
// List all the blobs from the container and return them
8589
container := service.NewContainerURL(config.Container)
90+
nextMarker := azblob.Marker{}
91+
for nextMarker.NotDone() {
92+
res, err := container.ListBlobsFlatSegment(context.Background(), nextMarker, azblob.ListBlobsSegmentOptions{
93+
MaxResults: 5000, // The server only gives max 5K items
94+
})
95+
if err != nil {
96+
return nil, err
97+
}
98+
allBlobs = append(allBlobs, res.Segment.BlobItems...)
99+
nextMarker = res.NextMarker
86100

87-
res, err := container.ListBlobsFlatSegment(context.Background(), azblob.Marker{}, azblob.ListBlobsSegmentOptions{
88-
MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them
89-
})
90-
if err != nil {
91-
return nil, err
92101
}
93-
return res.Segment.BlobItems, nil
102+
return allBlobs, nil
94103
}
95104

96105
// AzureBlobstoreDelete iterates over a list of files to delete and removes them
@@ -121,6 +130,7 @@ func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []azblob.BlobItem)
121130
if _, err := blockblob.Delete(context.Background(), azblob.DeleteSnapshotsOptionInclude, azblob.BlobAccessConditions{}); err != nil {
122131
return err
123132
}
133+
fmt.Printf("deleted %s (%s)\n", blob.Name, blob.Properties.LastModified)
124134
}
125135
return nil
126136
}

0 commit comments

Comments
 (0)