versionsapi: fix cache invalidation

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2022-12-22 15:17:41 +01:00
parent b9a1a9ae5e
commit 8b39d3d368
2 changed files with 9 additions and 4 deletions

View File

@ -102,7 +102,7 @@ func main() {
log.Infof("Successfully added version %q", *flags.version)
log.Infof("Waiting for cache invalidation.")
if err := versionManager.invalidateCaches(ctx, ver); err != nil {
if err := versionManager.invalidateCaches(ctx, ver, *flags.latest); err != nil {
log.With(zap.Error(err)).Fatalf("Failed to invalidate caches")
}
@ -413,7 +413,7 @@ func (m *versionManager) addLatest(ctx context.Context, ver version) error {
return err
}
func (m *versionManager) invalidateCaches(ctx context.Context, ver version) error {
func (m *versionManager) invalidateCaches(ctx context.Context, ver version, latest bool) error {
invalidIn := &cloudfront.CreateInvalidationInput{
DistributionId: aws.String(m.distributionID),
InvalidationBatch: &cftypes.InvalidationBatch{
@ -427,6 +427,11 @@ func (m *versionManager) invalidateCaches(ctx context.Context, ver version) erro
},
},
}
if latest {
invalidIn.InvalidationBatch.Paths.Quantity = aws.Int32(3)
path := path.Join("ref", ver.Ref(), "stream", ver.Stream(), "versions/latest/image.json")
invalidIn.InvalidationBatch.Paths.Items = append(invalidIn.InvalidationBatch.Paths.Items, "/"+path)
}
invalidation, err := m.cloudfrontc.CreateInvalidation(ctx, invalidIn)
if err != nil {
return err

View File

@ -163,12 +163,12 @@ func New() *Fetcher {
// MinorVersionsOf fetches the list of minor versions for a given stream, major version and kind.
func (f *Fetcher) MinorVersionsOf(ctx context.Context, ref, stream, major, kind string) (*List, error) {
return f.list(ctx, stream, "major", major, ref, kind)
return f.list(ctx, ref, stream, "major", major, kind)
}
// PatchVersionsOf fetches the list of patch versions for a given stream, minor version and kind.
func (f *Fetcher) PatchVersionsOf(ctx context.Context, ref, stream, minor, kind string) (*List, error) {
return f.list(ctx, stream, "minor", minor, ref, kind)
return f.list(ctx, ref, stream, "minor", minor, kind)
}
// list fetches the list of versions for a given stream, granularity, base and kind.