Skip to content

Commit

Permalink
Merge branch 'main' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
seungpark committed Oct 1, 2024
2 parents b764bad + 7c31782 commit f6ece7f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 200 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ RUN cd ./modules/oas-page-builder \
# where repo work will happen
FROM ubuntu:20.04
ARG WORK_DIRECTORY=/home/docsworker-xlarge
ARG SNOOTY_PARSER_VERSION=0.17.1
ARG SNOOTY_FRONTEND_VERSION=0.17.4
ARG SNOOTY_PARSER_VERSION=0.18.1
ARG SNOOTY_FRONTEND_VERSION=0.18.3
ARG MUT_VERSION=0.11.4
ARG REDOC_CLI_VERSION=1.3.0
ARG NPM_BASE_64_AUTH
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM arm64v8/ubuntu:20.04 as initial
ARG NPM_BASE_64_AUTH
ARG NPM_EMAIL
ARG SNOOTY_PARSER_VERSION=0.17.1
ARG SNOOTY_FRONTEND_VERSION=0.17.4
ARG SNOOTY_PARSER_VERSION=0.18.1
ARG SNOOTY_FRONTEND_VERSION=0.18.3
ARG MUT_VERSION=0.11.4
ARG REDOC_CLI_VERSION=1.2.3
ARG REDOC_CLI_VERSION=1.3.0
ARG NPM_BASE_64_AUTH
ARG NPM_EMAIL
ARG WORK_DIRECTORY=/home/docsworker-xlarge
Expand Down
71 changes: 4 additions & 67 deletions api/controllers/v1/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handle
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
import { PushEvent } from '@octokit/webhooks-types';
import { APIGatewayProxyResult } from 'aws-lambda';

async function prepGithubPushPayload(
githubEvent: any,
Expand Down Expand Up @@ -61,75 +62,11 @@ async function prepGithubPushPayload(
};
}

export const TriggerBuild = async (event: any = {}, context: any = {}): Promise<any> => {
const client = new mongodb.MongoClient(c.get('dbUrl'));
await client.connect();
const db = client.db(c.get('dbName'));
const consoleLogger = new ConsoleLogger();
const jobRepository = new JobRepository(db, c, consoleLogger);
const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger);
const docsetsRepository = new DocsetsRepository(db, c, consoleLogger);

if (!validateJsonWebhook(event, c.get<string>('githubSecret'))) {
const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match";
return {
statusCode: 401,
headers: { 'Content-Type': 'text/plain' },
body: errMsg,
};
}
if (!event.body) {
const err = 'Trigger build does not have a body in event payload';
consoleLogger.error('TriggerBuildError', err);
return {
statusCode: 400,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}

let body: PushEvent;
try {
body = JSON.parse(event.body) as PushEvent;
} catch (e) {
consoleLogger.error('[TriggerBuild]', `ERROR! Could not parse event.body ${e}`);
console.log(`event: ${event} and event body: ${event.body}`);
return {
statusCode: 502,
headers: { 'Content-Type': 'text/plain' },
body: ' ERROR! Could not parse event.body',
};
}

if (body.deleted) {
return {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: 'Job Ignored (Deletion)',
};
}

const env = c.get<string>('env');
const repoInfo = await docsetsRepository.getRepo(body.repository.name);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
// TODO: Make job be of type Job
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo);
try {
consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
consoleLogger.info(job.title, `Created Job ${jobId}`);
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
export const TriggerBuild = async (): Promise<APIGatewayProxyResult> => {
return {
statusCode: 202,
statusCode: 404,
headers: { 'Content-Type': 'text/plain' },
body: 'Job Queued',
body: 'The Autobuilder is currently disabled for staging. Please use Netlify instead.',
};
};

export const MarkBuildArtifactsForDeletion = markBuildArtifactsForDeletion;
127 changes: 3 additions & 124 deletions api/controllers/v2/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { ProjectsRepository } from '../../../src/repositories/projectsRepository
import { EnhancedJob, EnhancedPayload, JobStatus } from '../../../src/entities/job';
import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github';
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
import { getMonorepoPaths } from '../../../src/monorepo';
import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils';
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants';

const SMOKETEST_SITES = [
'docs-landing',
Expand Down Expand Up @@ -241,129 +238,11 @@ export const triggerSmokeTestAutomatedBuild = async (event: APIGatewayEvent): Pr
}
};

export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
const client = new mongodb.MongoClient(c.get('dbUrl'));
await client.connect();
const db = client.db(c.get('dbName'));
const consoleLogger = new ConsoleLogger();
const jobRepository = new JobRepository(db, c, consoleLogger);
const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger);
const docsetsRepository = new DocsetsRepository(db, c, consoleLogger);

if (!event.body) {
const err = 'Trigger build does not have a body in event payload';
return {
statusCode: 400,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}

if (!validateJsonWebhook(event, c.get<string>('githubSecret'))) {
const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match";
return {
statusCode: 401,
headers: { 'Content-Type': 'text/plain' },
body: errMsg,
};
}
let body: PushEvent;
try {
body = JSON.parse(event.body) as PushEvent;
} catch (e) {
console.log('[TriggerBuild]: ERROR! Could not parse event.body', e);
return {
statusCode: 502,
headers: { 'Content-Type': 'text/plain' },
body: ' ERROR! Could not parse event.body',
};
}

if (body.deleted) {
return {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: 'Job Ignored (Deletion)',
};
}

const env = c.get<string>('env');

async function createAndInsertJob(path?: string) {
const repo = body.repository;
const repoInfo = await docsetsRepository.getRepo(repo.name, path);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
const jobTitle = repo.full_name;
const payload = await createPayload({
repoName: repo.name,
prefix: jobPrefix,
repoBranchesRepository,
repoInfo,
githubEvent: body,
});

const job = await prepGithubPushPayload(body, payload, jobTitle);

consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
jobRepository.notify(jobId, c.get('jobUpdatesQueueUrl'), JobStatus.inQueue, 0);
consoleLogger.info(job.title, `Created Job ${jobId}`);
}

if (process.env.FEATURE_FLAG_MONOREPO_PATH === 'true' && body.repository.name === MONOREPO_NAME) {
let monorepoPaths: string[] = [];
try {
if (body.head_commit && body.repository.owner.name) {
monorepoPaths = await getMonorepoPaths({
commitSha: body.head_commit.id,
repoName: body.repository.name,
ownerName: body.repository.owner.name,
updatedFilePaths: getUpdatedFilePaths(body.head_commit),
});
consoleLogger.info(body.repository.full_name, `Monorepo Paths with new changes: ${monorepoPaths}`);
}
} catch (error) {
consoleLogger.warn('Warning, attempting to get monorepo paths caused an error', error);
}

/* Create and insert Job for each monorepo project that has changes */
for (const path of monorepoPaths) {
consoleLogger.info(body.repository.full_name, `Create Job for Monorepo directory: /${path}`);
// TODO: Deal with nested monorepo projects
/* For now, we will ignore nested monorepo projects until necessary */
if (path.split('/').length > 1) continue;

try {
await createAndInsertJob(path);
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
}

return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: 'Jobs Queued',
};
}

try {
await createAndInsertJob();
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
export const TriggerBuild = async (): Promise<APIGatewayProxyResult> => {
return {
statusCode: 202,
statusCode: 404,
headers: { 'Content-Type': 'text/plain' },
body: 'Job Queued',
body: 'The Autobuilder is currently disabled for staging. Please use Netlify instead.',
};
};

Expand Down
4 changes: 1 addition & 3 deletions cdk-infra/lib/constructs/worker/worker-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ export class WorkerConstruct extends Construct {
}),
});

const env = getEnv();

new FargateService(this, 'fargateService', {
cluster,
taskDefinition,
desiredCount: env === 'prd' ? 10 : 1,
desiredCount: 0,
minHealthyPercent: 100,
maxHealthyPercent: 200,
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workerpool",
"version": "1.5.29",
"version": "1.5.33",
"description": "Worker Pool Basic Implementation",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit f6ece7f

Please sign in to comment.