-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ozone cdn invalidation #2087
Ozone cdn invalidation #2087
Changes from 7 commits
df5a179
a172695
3799e84
24cb438
8e53bac
7df8a5f
b798229
e8c7c42
519803f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Invalidation is a general interface for propagating an image blob | ||
// takedown through any caches where a representation of it may be stored. | ||
// @NOTE this does not remove the blob from storage: just invalidates it from caches. | ||
// @NOTE keep in sync with same interface in aws/src/cloudfront.ts | ||
export interface ImageInvalidator { | ||
invalidate(subject: string, paths: string[]): Promise<void> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ require('dd-trace') // Only works with commonjs | |
|
||
// Tracer code above must come before anything else | ||
const path = require('path') | ||
const { | ||
BunnyInvalidator, | ||
CloudfrontInvalidator, | ||
MultiImageInvalidator, | ||
} = require('@atproto/aws') | ||
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to adjust the service's package.json and dockerfile to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easiest thing to check/catch this is to make a build and run it, even if it's unconfigured. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup yup good point 👍 |
||
const { | ||
OzoneService, | ||
envToCfg, | ||
|
@@ -24,7 +29,38 @@ const main = async () => { | |
const env = readEnv() | ||
const cfg = envToCfg(env) | ||
const secrets = envToSecrets(env) | ||
const ozone = await OzoneService.create(cfg, secrets) | ||
|
||
// configure zero, one, or more image invalidators | ||
const imgUriEndpoint = process.env.OZONE_IMG_URI_ENDPOINT | ||
const bunnyAccessKey = process.env.OZONE_BUNNY_ACCESS_KEY | ||
const cfDistributionId = process.env.OZONE_CF_DISTRIBUTION_ID | ||
|
||
const imgInvalidators = [] | ||
|
||
if (bunnyAccessKey) { | ||
imgInvalidators.push( | ||
new BunnyInvalidator({ | ||
accessKey: bunnyAccessKey, | ||
urlPrefix: imgUriEndpoint, | ||
}), | ||
) | ||
} | ||
|
||
if (cfDistributionId) { | ||
imgInvalidators.push( | ||
new CloudfrontInvalidator({ | ||
distributionId: cfDistributionId, | ||
pathPrefix: imgUriEndpoint && new URL(imgUriEndpoint).pathname, | ||
}), | ||
) | ||
} | ||
|
||
const imgInvalidator = | ||
imgInvalidators.length > 1 | ||
? new MultiImageInvalidator(imgInvalidators) | ||
: imgInvalidators[0] | ||
|
||
const ozone = await OzoneService.create(cfg, secrets, { imgInvalidator }) | ||
|
||
await ozone.start() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issue here, but node's
util.format()
does this exact printf-style replacement! Would look something likeutil.format(path, subject.did, cid)
.