@@ -127,38 +127,58 @@ func (s *S3Cache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (m
127
127
return fmt .Errorf ("failed to get version: %w" , err )
128
128
}
129
129
130
- // Check for .tar.gz first
130
+ // Try .tar.gz first
131
131
gzKey := fmt .Sprintf ("%s.tar.gz" , version )
132
132
exists , err := s .storage .HasObject (ctx , gzKey )
133
133
if err != nil {
134
- return fmt .Errorf ("failed to check object %s: %w" , gzKey , err )
135
- }
136
-
137
- if exists {
134
+ log .WithFields (log.Fields {
135
+ "package" : p .FullName (),
136
+ "key" : gzKey ,
137
+ "error" : err ,
138
+ }).Debug ("failed to check .tar.gz in remote cache, will try .tar" )
139
+ } else if exists {
140
+ log .WithFields (log.Fields {
141
+ "package" : p .FullName (),
142
+ "key" : gzKey ,
143
+ }).Debug ("found package in remote cache (.tar.gz)" )
138
144
mu .Lock ()
139
145
result [p ] = struct {}{}
140
146
mu .Unlock ()
141
147
return nil
142
148
}
143
149
144
- // Fall back to .tar
150
+ // Fall back to .tar if .tar.gz doesn't exist or had error
145
151
tarKey := fmt .Sprintf ("%s.tar" , version )
146
152
exists , err = s .storage .HasObject (ctx , tarKey )
147
153
if err != nil {
148
- return fmt .Errorf ("failed to check object %s: %w" , tarKey , err )
154
+ log .WithFields (log.Fields {
155
+ "package" : p .FullName (),
156
+ "key" : tarKey ,
157
+ "error" : err ,
158
+ }).Debug ("failed to check .tar in remote cache" )
159
+ return nil // Continue with next package, will trigger local build
149
160
}
150
161
151
162
if exists {
163
+ log .WithFields (log.Fields {
164
+ "package" : p .FullName (),
165
+ "key" : tarKey ,
166
+ }).Debug ("found package in remote cache (.tar)" )
152
167
mu .Lock ()
153
168
result [p ] = struct {}{}
154
169
mu .Unlock ()
170
+ } else {
171
+ log .WithFields (log.Fields {
172
+ "package" : p .FullName (),
173
+ "version" : version ,
174
+ }).Debug ("package not found in remote cache, will build locally" )
155
175
}
156
176
157
177
return nil
158
178
})
159
179
160
180
if err != nil {
161
- log .WithError (err ).Error ("failed to check existing packages" )
181
+ log .WithError (err ).Error ("failed to check existing packages in remote cache " )
162
182
// Return partial results even if some checks failed
163
183
return result , err
164
184
}
@@ -183,16 +203,34 @@ func (s *S3Cache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cac
183
203
gzKey := fmt .Sprintf ("%s.tar.gz" , version )
184
204
_ , err = s .storage .GetObject (ctx , gzKey , localPath )
185
205
if err == nil {
206
+ log .WithFields (log.Fields {
207
+ "package" : p .FullName (),
208
+ "key" : gzKey ,
209
+ }).Debug ("successfully downloaded package from remote cache (.tar.gz)" )
186
210
return nil
187
211
}
212
+ log .WithFields (log.Fields {
213
+ "package" : p .FullName (),
214
+ "key" : gzKey ,
215
+ "error" : err ,
216
+ }).Debug ("failed to download .tar.gz from remote cache, trying .tar" )
188
217
189
218
// Try .tar if .tar.gz fails
190
219
tarKey := fmt .Sprintf ("%s.tar" , version )
191
220
_ , err = s .storage .GetObject (ctx , tarKey , localPath )
192
221
if err != nil {
222
+ log .WithFields (log.Fields {
223
+ "package" : p .FullName (),
224
+ "key" : tarKey ,
225
+ "error" : err ,
226
+ }).Debug ("failed to download package from remote cache, will build locally" )
193
227
return fmt .Errorf ("failed to download package %s: %w" , p .FullName (), err )
194
228
}
195
229
230
+ log .WithFields (log.Fields {
231
+ "package" : p .FullName (),
232
+ "key" : tarKey ,
233
+ }).Debug ("successfully downloaded package from remote cache (.tar)" )
196
234
return nil
197
235
})
198
236
}
@@ -214,9 +252,21 @@ func (s *S3Cache) Upload(ctx context.Context, src cache.LocalCache, pkgs []cache
214
252
})
215
253
}
216
254
255
+ // s3ClientAPI is a subset of the S3 client interface we need
256
+ type s3ClientAPI interface {
257
+ HeadObject (ctx context.Context , params * s3.HeadObjectInput , optFns ... func (* s3.Options )) (* s3.HeadObjectOutput , error )
258
+ GetObject (ctx context.Context , params * s3.GetObjectInput , optFns ... func (* s3.Options )) (* s3.GetObjectOutput , error )
259
+ PutObject (ctx context.Context , params * s3.PutObjectInput , optFns ... func (* s3.Options )) (* s3.PutObjectOutput , error )
260
+ AbortMultipartUpload (ctx context.Context , params * s3.AbortMultipartUploadInput , optFns ... func (* s3.Options )) (* s3.AbortMultipartUploadOutput , error )
261
+ CompleteMultipartUpload (ctx context.Context , params * s3.CompleteMultipartUploadInput , optFns ... func (* s3.Options )) (* s3.CompleteMultipartUploadOutput , error )
262
+ CreateMultipartUpload (ctx context.Context , params * s3.CreateMultipartUploadInput , optFns ... func (* s3.Options )) (* s3.CreateMultipartUploadOutput , error )
263
+ UploadPart (ctx context.Context , params * s3.UploadPartInput , optFns ... func (* s3.Options )) (* s3.UploadPartOutput , error )
264
+ ListObjectsV2 (ctx context.Context , params * s3.ListObjectsV2Input , optFns ... func (* s3.Options )) (* s3.ListObjectsV2Output , error )
265
+ }
266
+
217
267
// S3Storage implements ObjectStorage using AWS S3
218
268
type S3Storage struct {
219
- client * s3. Client
269
+ client s3ClientAPI
220
270
bucketName string
221
271
}
222
272
0 commit comments