Skip to content
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

DOP-5128 and DOP-5167 #34

Merged
merged 41 commits into from
Nov 18, 2024
Merged

DOP-5128 and DOP-5167 #34

merged 41 commits into from
Nov 18, 2024

Conversation

seungpark
Copy link
Collaborator

@seungpark seungpark commented Nov 11, 2024

This PR adds logic for the offline snooty extension.
In the entry index.ts file, this extension calls to do the following onSuccess of the build's deploy:

  • Create a copy of snooty to build offline docs
  • Build the snooty output with the OFFLINE_DOCS set as an env variable in netlify UI (open to suggestions to stick this in the netlify.toml to be always tied to the extension repo)
  • Modify the output public directory to remove non-HTML non-image files
  • Update the links' href and images' src properties in each HTML file to have a relative path to the correct html / image file
  • Create a zip file .tgz to upload to S3
  • Upload the resulting zip file to S3 bucket at path <bucket>/docs/offline

Follow up tickets will address updating an entry in Atlas collection repos_branches to signify a successful offline build upload

Netlify extension is created here

Netlify site for the extension is created here

Build log of test site using this extension

Resulting S3 upload bucket

NOTE: test is failing at an unrelated change due to biome (also failing on main)

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for redoc-ext-test failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/redoc-ext-test/deploys/67377e942dcd740008ebd018

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for git-changed-file-extension canceled.

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/git-changed-file-extension/deploys/67377e94b1ff1c0008a0fcb5

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for persistence-module-ext canceled.

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/persistence-module-ext/deploys/67377e94158b020008893795

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for populate-data-extension canceled.

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/populate-data-extension/deploys/67377e94e7d4420008767607

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for test-monorepo-redoc failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/test-monorepo-redoc/deploys/67377e94bc78700008726485

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for site-links-display failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/site-links-display/deploys/67377e946aa5200008f06ec7

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for search-manifest-integration failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/search-manifest-integration/deploys/67377e94ce011c0008529210

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for snooty-cache-extension canceled.

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/snooty-cache-extension/deploys/67377e941449380008cacdae

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for offline-snooty ready!

Name Link
🔨 Latest commit 642d6ea
🔍 Latest deploy log https://app.netlify.com/sites/offline-snooty/deploys/673383ec526f2200074664a0
😎 Deploy Preview https://deploy-preview-34--offline-snooty.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for search-manifest-extension failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/search-manifest-extension/deploys/67377e94bef0c600089e8fba

@anabellabuckvar
Copy link
Collaborator

anabellabuckvar commented Nov 13, 2024

Q: Should this be run for all builds, always, regardless of the environment the build is triggered in? Also, as is, I believe this extension will error in createSnootyCopy when run on a site where the source code is the Snooty repo, such as the mongodb-snooty Netlify site, because there's no Snooty folder within Snooty.

The rest of the comments I've left are just nits, but could you also add comments to the places where work will be done in future tickets? Thanks you!

@seungpark seungpark changed the title DOP-5128 DOP-5128 and DOP-5167 Nov 15, 2024
@seungpark
Copy link
Collaborator Author

Q: Should this be run for all builds, always, regardless of the environment the build is triggered in? Also, as is, I believe this extension will error in createSnootyCopy when run on a site where the source code is the Snooty repo, such as the mongodb-snooty Netlify site, because there's no Snooty folder within Snooty.

The rest of the comments I've left are just nits, but could you also add comments to the places where work will be done in future tickets? Thanks you!

This is designed to run in dotcomstg (for testing) and dotcomprd for prod. I think we should clean up stg (aka mongodb-snooty) so that the folder structure on each job is the same, so we don't have to account for different directory structure for that specific env each time. Until then, we can disable this extension via env var in that context

Copy link
Collaborator

@branberry branberry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Seung! Looks good, just a few more small comments


export const convertGatsbyToHtml = async (path: string): Promise<Gzip> => {
return createGzip();
type fileUpdateLog = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Can you capitalize the first letter of this type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment on lines 25 to 36
const { bucketName, fileName } = readEnvConfigs({
env: netlifyConfig.build.environment.ENV ?? '',
docsetEntry:
(netlifyConfig.build.environment
.DOCSET_ENTRY as unknown as DocsetsDocument) ?? {},
repoEntry:
(netlifyConfig.build.environment
.REPO_ENTRY as unknown as ReposBranchesDocument) ?? {},
branchEntry:
(netlifyConfig.build.environment
.BRANCH_ENTRY as unknown as BranchEntry) ?? {},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Instead of casting as unknown as ..., we can provide a type for the environment property so that we can cast as the type we want directly.

Suggested change
const { bucketName, fileName } = readEnvConfigs({
env: netlifyConfig.build.environment.ENV ?? '',
docsetEntry:
(netlifyConfig.build.environment
.DOCSET_ENTRY as unknown as DocsetsDocument) ?? {},
repoEntry:
(netlifyConfig.build.environment
.REPO_ENTRY as unknown as ReposBranchesDocument) ?? {},
branchEntry:
(netlifyConfig.build.environment
.BRANCH_ENTRY as unknown as BranchEntry) ?? {},
});
const environment = netlifyConfig.build.environment as Record<
string,
string | DocsetsDocument | ReposBranchesDocument | BranchEntry
>;
const { bucketName, fileName } = readEnvConfigs({
env: (environment.ENV as string) ?? '',
docsetEntry: (environment.DOCSET_ENTRY as DocsetsDocument) ?? {},
repoEntry: (environment.REPO_ENTRY as ReposBranchesDocument) ?? {},
branchEntry: (environment.BRANCH_ENTRY as BranchEntry) ?? {},
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good typing! i like it. done

// remove empty directories
for (const [path, filenames] of Object.entries(log.filePathsPerDir)) {
if (!filenames.length && path !== PUBLIC_OUTPUT_PATH) {
await fsPromises.rm(path, { recursive: true, force: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to do these concurrently? ie

await Promise.all(Object.entries(log.filePathsPerDir).map(async ([path, filenames]) => { 
  if (!filenames.length && path !== PUBLIC_OUTPUT_PATH) {
    await fsPromises.rm(path, { recursive: true, force: true });
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. minor note that this doesnt take long

5:27:55 PM: >>>>>>>>>> converted gatsby results <<<<<<<<<<<<<

then this removing directories has no log, and then
5:28:00 PM: ... uploaded to AWS S3

link to log:
https://app.netlify.com/sites/iridescent-babka-0105eb/deploys/673676f557170d869a2ac07b#L5882

Copy link

netlify bot commented Nov 15, 2024

Deploy Preview for redirects-and-publish-extension failed. Why did it fail? →

Name Link
🔨 Latest commit ead9c80
🔍 Latest deploy log https://app.netlify.com/sites/redirects-and-publish-extension/deploys/67377e94670e950008e9a8f7

@seungpark seungpark merged commit d09b19b into main Nov 18, 2024
20 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants