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-4073: Adding support for curling dependencies stored in repos_branches #946

Merged
merged 30 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cc745e8
working locally with hardcoded values
mayaraman19 Nov 30, 2023
ee70cf9
ading to github push
mayaraman19 Dec 1, 2023
e60c4f8
adding to build function
mayaraman19 Dec 4, 2023
2880e32
trying again
mayaraman19 Dec 4, 2023
af03f92
updating structure
mayaraman19 Dec 4, 2023
02a3f0a
editing errors
mayaraman19 Dec 4, 2023
2f7e349
fianlly curling
mayaraman19 Dec 4, 2023
0a3e5bc
curl errors
mayaraman19 Dec 4, 2023
4759edb
cleaning up
mayaraman19 Dec 4, 2023
5273873
changing structurea gain
mayaraman19 Dec 4, 2023
707e090
adding curl options
mayaraman19 Dec 4, 2023
60de805
testing removing from github.ts
mayaraman19 Dec 5, 2023
e3731d7
moving logic
mayaraman19 Dec 5, 2023
c4dbc63
cleaning up
mayaraman19 Dec 5, 2023
48ea293
fixing localapp error
mayaraman19 Dec 5, 2023
6b1c427
addressing comments and renaming buildDir to targetDir
mayaraman19 Dec 5, 2023
dff22d4
addressing comments part 2
mayaraman19 Dec 5, 2023
088b80b
Merge branch 'master' into DOP-4073
mayaraman19 Dec 5, 2023
8e0c8c9
debugging empty array
mayaraman19 Dec 5, 2023
20016ab
Merge branch 'DOP-4073' of https://github.com/mongodb/docs-worker-poo…
mayaraman19 Dec 5, 2023
1345027
debugging
mayaraman19 Dec 5, 2023
4e7eb13
debugging still
mayaraman19 Dec 5, 2023
5736908
adding try catch
mayaraman19 Dec 5, 2023
fe73f52
adding promise.all
mayaraman19 Dec 5, 2023
0f1b376
adding async
mayaraman19 Dec 6, 2023
5e87b6a
adding await
mayaraman19 Dec 6, 2023
5382aac
testing await
mayaraman19 Dec 6, 2023
50cd8f5
refining try-catch, adding await promise.all
mayaraman19 Dec 7, 2023
83f5e77
dependency info logging
mayaraman19 Dec 7, 2023
6afab31
Merge branch 'master' into DOP-4073
mayaraman19 Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/commands/src/helpers/dependency-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import fs from 'fs';
import { executeCliCommand, getCommitBranch, getCommitHash, getPatchId, getRepoDir } from '.';
import { promisify } from 'util';
import { BuildDependencies } from '../../../entities/job';

const existsAsync = promisify(fs.exists);
const writeFileAsync = promisify(fs.writeFile);
Expand Down Expand Up @@ -33,12 +34,59 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl:
}
}

export async function prepareBuildAndGetDependencies(repoName: string, projectName: string, baseUrl: string) {
export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) {
const commands: string[] = [];
await Promise.all(
buildDependencies.map(async (dependencyInfo) => {
const repoDir = getRepoDir(repoName);
const targetDir = dependencyInfo.targetDir ?? repoDir;
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think we should narrow this try/catch to cover where in the code an exception might be thrown i.e. we can wrap just the executeCliCommand calls with a try catch. This allows us to be more fine-grained in our errors. For example:

try {
    await executeCliCommand({
       command: 'mkdir',
       args: ['-p', targetDir],
    });
} catch (e) {
  console.error(`Error! Could not create dependency directory: ${targetDir}. Dependency Information: `, dependencyInfo);
  throw e;

}

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

export async function prepareBuildAndGetDependencies(
repoName: string,
projectName: string,
baseUrl: string,
buildDependencies: BuildDependencies
) {
// before we get build dependencies, we need to clone the repo
await cloneRepo(repoName);

const repoDir = getRepoDir(repoName);

await downloadBuildDependencies(buildDependencies, repoName);

// doing these in parallel
const commandPromises = [
getCommitHash(repoDir),
Expand Down
12 changes: 12 additions & 0 deletions src/entities/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export enum JobStatus {
// regression = 'regression',
// }

export type BuildDependencies = DependencyInfo[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding these types!


type Dependency = {
url: string;
filename: string;
};

type DependencyInfo = {
targetDir?: string;
dependencies: Dependency[];
};

export type Payload = {
jobType: string;
source: string;
Expand Down
26 changes: 25 additions & 1 deletion src/entrypoints/localApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@ async function localApp() {
const baseUrl = 'https://www.mongodb.com';
const bucket = 'docs-java-dotcomstg';
const mutPrefix = 'docs/drivers/java/sync';
const buildDependencies = [
{
dependencies: [
{
url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-mongodb-internal.yaml',
filename: 'published-branches.yaml',
},
],
},
{
buildDir: 'source/driver-examples',
dependencies: [
{
url: 'https://raw.githubusercontent.com/mongodb/mongo-python-driver/master/test/test_examples.py',
filename: 'test_examples.py',
},
{
url: 'https://raw.githubusercontent.com/mongodb/motor/master/test/asyncio_tests/test_examples.py',
filename: 'test_examples_motor.py',
},
],
},
];

const { commitHash, patchId, bundlePath, commitBranch, hasRedirects, repoDir } = await prepareBuildAndGetDependencies(
repoName,
projectName,
baseUrl
baseUrl,
buildDependencies
);

console.log('Begin snooty build...');
Expand Down
11 changes: 11 additions & 0 deletions src/job/jobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IJobValidator } from './jobValidator';
import { RepoEntitlementsRepository } from '../repositories/repoEntitlementsRepository';
import { DocsetsRepository } from '../repositories/docsetsRepository';
import { MONOREPO_NAME } from '../monorepo/utils/monorepo-constants';
import { downloadBuildDependencies } from '../commands/src/helpers/dependency-helpers';
require('fs');

export abstract class JobHandler {
Expand Down Expand Up @@ -202,6 +203,14 @@ export abstract class JobHandler {
}
}

@throwIfJobInterupted()
private async getAndBuildDependencies() {
const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(this.currJob.payload.repoName);
if (!buildDependencies) return;
const commands = await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName);
this._logger.save(this._currJob._id, commands.join('\n'));
}

@throwIfJobInterupted()
private async downloadMakeFile(): Promise<void> {
try {
Expand Down Expand Up @@ -480,6 +489,8 @@ export abstract class JobHandler {
this._logger.save(this._currJob._id, 'Checked Commit');
await this.pullRepo();
this._logger.save(this._currJob._id, 'Pulled Repo');
await this.getAndBuildDependencies();
this._logger.save(this._currJob._id, 'Downloaded Build dependencies');
this.prepBuildCommands();
this._logger.save(this._currJob._id, 'Prepared Build commands');
await this.prepNextGenBuild();
Expand Down
10 changes: 10 additions & 0 deletions src/repositories/repoBranchesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ import { Db } from 'mongodb';
import { BaseRepository } from './baseRepository';
import { ILogger } from '../services/logger';
import { IConfig } from 'config';
import { BuildDependencies } from '../entities/job';

export class RepoBranchesRepository extends BaseRepository {
constructor(db: Db, config: IConfig, logger: ILogger) {
super(config, logger, 'RepoBranchesRepository', db.collection(config.get('repoBranchesCollection')));
}

async getBuildDependencies(repoName: string): Promise<BuildDependencies> {
const query = { repoName: repoName };
const repo = await this.findOne(
query,
`Mongo Timeout Error: Timedout while retrieving build dependencies for ${repoName}`
);
return repo?.optionalBuildSteps?.buildDependencies;
}

async getRepoBranches(repoName: string, directoryPath?: string): Promise<any> {
const query = { repoName: repoName };
if (directoryPath) query['directories.snooty_toml'] = `/${directoryPath}`;
Expand Down
Loading