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-4209 #958

Merged
merged 195 commits into from
Jan 22, 2024
Merged

DOP-4209 #958

merged 195 commits into from
Jan 22, 2024

Conversation

mayaraman19
Copy link
Contributor

@mayaraman19 mayaraman19 commented Jan 3, 2024

DOP-4209

docs-monorepo/docs-mongodb-internal was not building without makefiles for multiple reasons:

  • retrieving the build dependencies from repos_branches did not take into consideration monorepo naming/directory structure, causing builds to just be pulling from docs-monorepo/cloud-docs since that was the first monorepo entry to show up in repos_branches.
  • migrating from makefiles did not take into account which error codes should/shouldn't cause the build to fail.

These have since been fixed, however, and docs-monorepo projects should be able to build now! (shoutout to @branberry for the help!)

@mayaraman19 mayaraman19 marked this pull request as ready for review January 12, 2024 17:42
Copy link
Contributor

@mmeigs mmeigs left a comment

Choose a reason for hiding this comment

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

Okay, some of these comments are a little long, so please reach out if you have any questions!

Comment on lines 98 to 101
repoName: string,
projectName: string,
baseUrl: string,
buildDependencies: BuildDependencies,
directory?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're not getting dependencies in this function anymore, can we rename this function? prepareBuild could be fine by itself!

Comment on lines 215 to 232
@throwIfJobInterupted()
private async getBuildDependencies() {
const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(this.currJob.payload.repoName);
const repoName = this.currJob.payload.repoName;
const directory = this.currJob.payload.repoName === MONOREPO_NAME ? this.currJob.payload.directory : undefined;
const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(repoName, directory);
if (!buildDependencies) return [];
await this._logger.save(this._currJob._id, 'Identified Build dependencies');
return buildDependencies;
}

@throwIfJobInterupted()
private async getAndBuildDependencies() {
private async getAndDownloadBuildDependencies() {
const repoName = this.currJob.payload.repoName;
const directory = this.currJob.payload.repoName === MONOREPO_NAME ? this.currJob.payload.directory : undefined;
const buildDependencies = await this.getBuildDependencies();
const commands = await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName);
this._logger.save(this._currJob._id, commands.join('\n'));
const commands = await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName, directory);
await this._logger.save(this._currJob._id, `${commands.join('\n')}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can combine these again. The reason to separate is gone now, and also it would combine the redundancy of accessing the repoName and directory twice in quick succession.

README.md Outdated
Comment on lines 54 to 59

<<<<<<< HEAD
`npm run debug -- -o 10gen -n 'cloud-docs'`
=======
`npm run debug -- -o 10gen -n cloud-docs`

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Make sure the merge finishes and gets rid of these characters

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the diff: The quotes are not necessary, but they are also not an issue. Either way is fine, but I would lean toward all the examples showing the same way for each input

Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting here that this entire file has multiple unfinished merge flags to take care of!

@@ -19,7 +19,7 @@ export class WebhookEnvConstruct extends Construct {
const ssmPrefix = getSsmPathPrefix();
const env = getEnv();

const featureFlagMonorepoPath = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/monorepo_path`);
const featureFlagMonorepoPath = StringParameter.valueFromLookup(this, `${ssmPrefix}/DOP-4127/flag/monorepo_path`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that this needs to be changed back before merge

@@ -50,7 +50,7 @@ export class WorkerEnvConstruct extends Construct {
// doing this for the time being, but I think we don't need to necessarily retrieve this from ssm for feature branches, nor would we want to in that case
const previewBuildEnabled = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/preview_build/enabled`);
const featureFlagUpdatePages = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/update_pages`);
const featureFlagMonorepoPath = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/monorepo_path`);
const featureFlagMonorepoPath = StringParameter.valueFromLookup(this, `${ssmPrefix}/DOP-4127/flag/monorepo_path`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to change back before merge

const commands: string[] = [];
await Promise.all(
buildDependencies.map(async (dependencyInfo) => {
const repoDir = getRepoDir(repoName);
const repoDir = directory ? getRepoDir(repoName, directory) : getRepoDir(repoName);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to do this conditional! The directory argument can be undefined. You can simple state:

const repoDir = getRepoDir(repoName, directory);

Comment on lines 74 to 90
await Promise.all(
dependencyInfo.dependencies.map((dep) => {
dependencyInfo.dependencies.map(async (dep) => {
try {
executeCliCommand({
command: 'curl',
args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`],
args: ['--max-time', '10', '-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`],
options: options,
});
} catch (error) {
console.error(
`ERROR! Could not curl ${dep.url} into ${targetDir}/${dep.filename}. Dependency information: `,
dependencyInfo
);
return commands;
}
commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, interesting thing here. I could be wrong, but I believe that because we're returning a static value (even though it's a Promise because of the async keyword) it can return before the executeCliCommand function finishes.

I think this can be slightly changed to do what you're trying to do and cleaner too. If you take away the async keyword and add return keyword to the executeCliCommand invocation that will ensure that the Promise.all waits for each Promise to finish. Then move the commands.push line up into the try block before the return. Then you can completely delete the unused line return commands. Doing this will ensure that the Node thread will not continue on until all of these commands have either finished or errored.

I have an example below.

Like this:

await Promise.all(
     dependencyInfo.dependencies.map((dep) => {
          try {
            commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`);
            return executeCliCommand({
              command: 'curl',
               args: ['--max-time', '10', '-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`],
              options: options,
            });
          } catch (error) {
            console.error(
              `ERROR! Could not curl ${dep.url} into ${targetDir}/${dep.filename}. Dependency information: `,
              dependencyInfo
            );
          }
       })
)

Copy link
Contributor

Choose a reason for hiding this comment

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

These are all great points, @mmeigs. The one small nit with the example though is that we won't hit this catch block, I think. This is because we return the promise, but we don't await it, not giving the promise the opportunity to settle before the catch block can be entered.

I think we can add the async back and do return await executeCliCommand... so that it will wait for the promise to settle before returning.

This also has me thinking as well, do we want to do an allSettled here maybe as well? That way, we can know all of the dependencies that are failing for whatever reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing this out with some incorrect curl links but this approach still doesn't seem to catch the error 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I wonder if doing return await executeCliCommand(...) we try:

 const cliResult = await executeCliCommand(...);

return cliResult;

in the try/catch? I wonder if return is sort of overwriting the await in a sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this didn't work either 💔 i dropped a new ticket for this issue though!

@branberry
Copy link
Contributor

We can ignore the failing Update Feature Branch Infrastructure jobs. This stems from an edge case with the new updated feature branch deploys that depend on being run as a part of the first job.

@@ -63,36 +72,29 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen
}
commands.push(`mkdir -p ${targetDir}`);
await Promise.all(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I did not use allSettled here because it seemed to not exist with this version of Javascript?

Copy link
Contributor

Choose a reason for hiding this comment

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

What version of node are you using?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v18.17.1!

@mayaraman19
Copy link
Contributor Author

I think I'm going to bump error logging in downloadBuildDependencies to another ticket because I can't figure it out 😭

@mayaraman19 mayaraman19 requested a review from mmeigs January 16, 2024 20:31
Copy link
Contributor

@mmeigs mmeigs left a comment

Choose a reason for hiding this comment

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

Thanks for getting this working!

Copy link
Contributor

@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.

LGTM!

@mayaraman19 mayaraman19 merged commit 834e691 into master Jan 22, 2024
8 of 10 checks passed
@mayaraman19 mayaraman19 deleted the DOP-4209 branch January 22, 2024 20:14
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