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-4306: Remove legacy build code from autobuilder #985

Merged
merged 13 commits into from
Feb 12, 2024
Merged
1 change: 0 additions & 1 deletion .github/workflows/deploy-prd-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
npm ci
sls deploy --stage prd
sls deploy --stage dotcomprd
sls deploy --stage legacydotcomprd
- uses: mr-smithers-excellent/docker-build-push@v5
name: build and push to ECR
with:
Expand Down
17 changes: 1 addition & 16 deletions .github/workflows/deploy-stg-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
branches:
- "main"
- "integration"
- "DOP-4306"
concurrency:
group: environment-stg-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -34,7 +35,6 @@ jobs:
npm ci
sls deploy --stage stg
sls deploy --stage dotcomstg
sls deploy --stage legacydotcomstg
- uses: mr-smithers-excellent/docker-build-push@v5
name: build and push to ECR
with:
Expand All @@ -59,30 +59,15 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NPM_BASE_64_AUTH: ${{ secrets.NPM_BASE64_AUTH }}
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
- uses: mr-smithers-excellent/docker-build-push@v5
name: build and push to ECR Legacy DOTCOM
with:
image: docs-worker-pool-legacydotcomstg
tags: latest
registry: ${{ steps.login-ecr.outputs.registry }}
dockerfile: Dockerfile.legacy
buildArgs: NPM_EMAIL=${{ secrets.NPM_EMAIL }},NPM_BASE_64_AUTH=${{ secrets.NPM_BASE64_AUTH }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NPM_BASE_64_AUTH: ${{ secrets.NPM_BASE64_AUTH }}
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
- name: Deploy ECS
run: |
cd infrastructure/ecs-main
npm ci
sls deploy --stage stg
sls deploy --stage dotcomstg
sls deploy --stage legacydotcomstg
- name: Deploy Lambdas
run: |
npm ci
sls deploy --stage stg
sls deploy --stage dotcomstg
sls deploy --stage legacydotcomstg
sls prune -n 5
2 changes: 1 addition & 1 deletion Dockerfile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM node:14-bullseye-slim

ARG MUT_VERSION=0.10.6

ENV PATH="${PATH}:/opt/mut"

RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
6 changes: 2 additions & 4 deletions cdk-infra/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Construct } from 'constructs';
import { getCurrentBranch } from './git';

const snootyEnvs = ['staging', 'production', 'dotcomstg', 'dotcomprd', 'legacydotcomprd', 'legacydotcomstg'] as const;
const autoBuilderEnvs = ['stg', 'prd', 'dev', 'dotcomstg', 'dotcomprd', 'legacydotcomstg', 'legacydotcomprd'] as const;
const snootyEnvs = ['staging', 'production', 'dotcomstg', 'dotcomprd'] as const;
const autoBuilderEnvs = ['stg', 'prd', 'dev', 'dotcomstg', 'dotcomprd'] as const;
const autoBuilderContextVariables = [
'enhanced',
'isFeatureBranch',
Expand All @@ -24,8 +24,6 @@ const autoBuilderToSnootyEnvMap: Record<AutoBuilderEnv, SnootyEnv> = {
prd: 'production',
dotcomprd: 'dotcomprd',
dotcomstg: 'dotcomstg',
legacydotcomstg: 'legacydotcomstg',
legacydotcomprd: 'legacydotcomprd',
};

export function envShortToFullName(env: string): SnootyEnv {
Expand Down
2 changes: 0 additions & 2 deletions cdk-infra/utils/search-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ export function getSearchIndexFolder(env: AutoBuilderEnv): string {
return '';
case 'stg':
case 'dotcomstg':
case 'legacydotcomstg':
return 'preprd';
case 'dotcomprd':
case 'legacydotcomprd':
case 'prd':
return 'prd';
}
Expand Down
2 changes: 0 additions & 2 deletions cdk-infra/utils/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const dashboardUrls: Record<AutoBuilderEnv, string> = {
prd: `https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=`,
dotcomstg: `https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=`,
dotcomprd: `https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=`,
legacydotcomstg: `https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=`,
legacydotcomprd: `https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=`,
dev: `https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=`,
};

Expand Down
4 changes: 0 additions & 4 deletions cdk-infra/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ const hostUrlMap: Record<AutoBuilderEnv, string> = {
dev: 'docs-dev.mongodb.com',
stg: 'mongodbcom-cdn.website.staging.corp.mongodb.com',
dotcomstg: 'mongodbcom-cdn.website.staging.corp.mongodb.com',
legacydotcomstg: 'mongodbcom-cdn.website.staging.corp.mongodb.com',
prd: 'www.mongodb.com',
dotcomprd: 'www.mongodb.com',
legacydotcomprd: 'www.mongodb.com',
};

const urlPrefixMap: Record<AutoBuilderEnv, string> = {
dev: 'docs',
stg: 'docs-qa',
dotcomstg: 'docs-qa',
legacydotcomstg: 'docs-qa',
prd: 'docs',
dotcomprd: 'docs',
legacydotcomprd: 'docs',
};

export const getHostUrl = (env: AutoBuilderEnv): string => hostUrlMap[env];
Expand Down
22 changes: 0 additions & 22 deletions infrastructure/ecs-main/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,18 @@ custom:
prd: '4'
dotcomstg: '4'
dotcomprd: '4'
legacydotcomstg: '4'
legacydotcomprd: '4'
minimumHealthyPercent:
dev: 100
stg: 100
prd: 100
dotcomstg: 100
dotcomprd: 100
legacydotcomstg: 100
legacydotcomprd: 100
maximumPercent:
dev: 200
stg: 200
prd: 200
dotcomstg: 200
dotcomprd: 200
legacydotcomstg: 200
legacydotcomprd: 200
deregistrationDelaySecs: '10'
targetGroupName: docs-worker-pool
accountId:
Expand All @@ -91,8 +85,6 @@ custom:
prd: 216656347858
dotcomstg: 216656347858
dotcomprd: 216656347858
legacydotcomstg: 216656347858
legacydotcomprd: 216656347858

dbUsername: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/username}
dbPassword: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/password}
Expand Down Expand Up @@ -152,25 +144,19 @@ custom:
prd: https://cdnvalidator.devops.prod.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
dotcomstg: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
dotcomprd: https://cdnvalidator.devops.prod.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
legacydotcomstg: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
legacydotcomprd: https://cdnvalidator.devops.prod.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
dev: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
distributionName:
stg: mongodbcom-staging-docs
dotcomstg: mongodbcom-staging-docs
legacydotcomstg: mongodbcom-staging-docs
dev: mongodbcom-staging-docs
dotcomprd: mongodbcom-prod-docs
legacydotcomprd: mongodbcom-prod-docs
prd: mongodbcom-prod-docs
env:
stg: "staging"
prd: "production"
dev: "staging"
dotcomstg: "dotcomstg"
dotcomprd: "dotcomprd"
legacydotcomstg: "dotcomstg"
legacydotcomprd: "dotcomprd"
# TODO: When satisfied with manifest generation, remove '-test'
searchIndexBucket: docs-search-indexes-test
# TODO: In future, use duplicate mapping of dotcomstg -> preprd to have
Expand All @@ -181,30 +167,22 @@ custom:
prd: "prd"
dotcomstg: "preprd"
dotcomprd: "prd"
legacydotcomstg: "preprd"
legacydotcomprd: "prd"
site:
host:
dev: "docs-dev.mongodb.com"
stg: "mongodbcom-cdn.website.staging.corp.mongodb.com"
dotcomstg: "mongodbcom-cdn.website.staging.corp.mongodb.com"
legacydotcomstg: "mongodbcom-cdn.website.staging.corp.mongodb.com"
prd: "www.mongodb.com"
dotcomprd: "www.mongodb.com"
legacydotcomprd: "www.mongodb.com"
prefix:
dev: "docs"
stg: "docs-qa"
dotcomstg: "docs-qa"
legacydotcomstg: "docs-qa"
prd: "docs"
dotcomprd: "docs"
legacydotcomprd: "docs"
errorDoc:
dotcomstg: "docs-qa/404/index.html"
dotcomprd: "docs/404/index.html"
legacydotcomstg: "docs-qa/404/index.html"
legacydotcomprd: "docs/404/index.html"

resources:
- ${file(./buckets.yml)}
Expand Down
8 changes: 0 additions & 8 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ custom:
prd: worker-pool-deployment
dotcomstg: worker-pool-deployment
dotcomprd: worker-pool-deployment
legacydotcomstg: worker-pool-deployment
legacydotcomprd: worker-pool-deployment
searchIndexBucket:
dev: "" # I'm just here so I don't get fined
# TODO: When satisfied with manifest generation, remove the '-test'
dotcomstg: docs-search-indexes-test/preprd
dotcomprd: docs-search-indexes-test/prd
legacydotcomstg: docs-search-indexes-test/preprd
legacydotcomprd: docs-search-indexes-test/prd
fastlyDochubToken: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/dochub/token}
fastlyDochubServiceId: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/dochub/service_id}
fastlyDochubMap: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/dochub_map}
Expand All @@ -51,8 +47,6 @@ custom:
dev: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dotcomstg: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dotcomprd: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
legacydotcomstg: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
legacydotcomprd: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dochubEventBus: arn:aws:events:${aws:region}:${aws:accountId}:event-bus/${self:custom.docuhubEventSource.${self:provider.stage}}
dbUsername: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/username}
dbPassword: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/password}
Expand All @@ -79,8 +73,6 @@ custom:
prd: https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dotcomstg: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dotcomprd: https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
legacydotcomstg: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
legacydotcomprd: https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dev: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
env:
stg: "staging"
Expand Down
2 changes: 0 additions & 2 deletions src/entities/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export type Payload = {
primaryAlias: string | null | undefined;
repoBranches: any;
stable: boolean | null | undefined;
isNextGen: boolean | null | undefined;
regression: boolean | null | undefined;
urlSlug: string | null | undefined;
prefix: string;
Expand Down Expand Up @@ -78,7 +77,6 @@ export type EnhancedPayload = {
aliased?: boolean | null;
primaryAlias?: string | null;
stable?: boolean | null;
isNextGen?: boolean | null;
repoBranches?: any;
regression?: boolean | null;
urlSlug?: string | null;
Expand Down
47 changes: 15 additions & 32 deletions src/job/jobHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import axios, { AxiosResponse } from 'axios';
import axios from 'axios';
import { Payload, Job, JobStatus } from '../entities/job';
import { JobRepository } from '../repositories/jobRepository';
import { RepoBranchesRepository } from '../repositories/repoBranchesRepository';
Expand Down Expand Up @@ -115,7 +114,6 @@ export abstract class JobHandler {
const { _id: jobId, user } = this.currJob;
const gatsbyCloudSiteId = await this._repoEntitlementsRepo.getGatsbySiteIdByGithubUsername(user);
if (
this.currJob.payload.isNextGen &&
gatsbyCloudSiteId &&
this.currJob.payload.jobType === 'githubPush' &&
process.env.IS_FEATURE_BRANCH !== 'true'
Expand Down Expand Up @@ -256,25 +254,20 @@ export abstract class JobHandler {

@throwIfJobInterupted()
private async prepNextGenBuild(): Promise<void> {
if (this.isbuildNextGen()) {
await this._validator.throwIfBranchNotConfigured(this.currJob);
await this.constructPrefix();
// TODO: Look into moving the generation of manifestPrefix into the manifestJobHandler,
// as well as reducing difficult-to-debug state changes
// if this payload is NOT aliased or if it's the primary alias, we need the index path
if (!this.currJob.payload.aliased || (this.currJob.payload.aliased && this.currJob.payload.primaryAlias)) {
this.currJob.payload.manifestPrefix = this.constructManifestPrefix();
this._logger.info(this.currJob._id, `Created payload manifestPrefix: ${this.currJob.payload.manifestPrefix}`);
}
await this._validator.throwIfBranchNotConfigured(this.currJob);
await this.constructPrefix();
// TODO: Look into moving the generation of manifestPrefix into the manifestJobHandler,
// as well as reducing difficult-to-debug state changes
// if this payload is NOT aliased or if it's the primary alias, we need the index path
if (!this.currJob.payload.aliased || (this.currJob.payload.aliased && this.currJob.payload.primaryAlias)) {
this.currJob.payload.manifestPrefix = this.constructManifestPrefix();
this._logger.info(this.currJob._id, `Created payload manifestPrefix: ${this.currJob.payload.manifestPrefix}`);
}

this.prepStageSpecificNextGenCommands();
this.constructEnvVars();
this.currJob.payload.isNextGen = true;
if (this._currJob.payload.jobType === 'productionDeploy') {
this._validator.throwIfNotPublishable(this._currJob);
}
} else {
this.currJob.payload.isNextGen = false;
this.prepStageSpecificNextGenCommands();
this.constructEnvVars();
Copy link
Contributor

@branberry branberry Feb 7, 2024

Choose a reason for hiding this comment

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

We should update the prepStageSpecificNextGenCommands();. That method contains stuff that we can clean up/simplify. More specifically, that function depends on mutations made to the this.currJob.buildCommands property in the this.prepBuildCommands method.

Anywhere we see . /venv/bin/activate or make (parse/html/stage/deploy) we should remove that as those are meant for legacy builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should make (parse/html/stage/deploy) be replaced with something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, should make publish be removed as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. They should be replaced with the next-gen equivalent e.g. make parse should be replaced with next-gen-parse. make publish should be removed as well, good catch!

if (this._currJob.payload.jobType === 'productionDeploy') {
this._validator.throwIfNotPublishable(this._currJob);
}
}

Expand Down Expand Up @@ -376,22 +369,12 @@ export abstract class JobHandler {
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}Finished Build`);
}

private async exeBuild(): Promise<void> {
const resp = await this._commandExecutor.execute(this.currJob.buildCommands);
this.logBuildDetails(resp);
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}Finished Build`);
}

@throwIfJobInterupted()
private async executeBuild(): Promise<boolean> {
if (this.currJob.buildCommands && this.currJob.buildCommands.length > 0) {
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}Running Build`);
await this._logger.save(this.currJob._id, `${'(BUILD)'.padEnd(15)}running worker.sh`);
if (this.currJob.payload.isNextGen) {
await this.exeBuildModified();
} else {
await this.exeBuild();
}
await this.exeBuildModified();
} else {
const error = new AutoBuilderError('No commands to execute', 'BuildError');
await this.logError(error);
Expand Down
19 changes: 9 additions & 10 deletions src/job/productionJobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ export class ProductionJobHandler extends JobHandler {
];

// TODO: Reduce confusion between job.manifestPrefix and job.payload.manifestPrefix
if (this.currJob.payload.isNextGen) {
this.currJob.manifestPrefix = this.currJob.manifestPrefix ?? this.constructManifestPrefix();
this.currJob.manifestPrefix = this.currJob.manifestPrefix ?? this.constructManifestPrefix();
this.currJob.deployCommands[
this.currJob.deployCommands.length - 1
] = `make next-gen-deploy MUT_PREFIX=${this.currJob.payload.mutPrefix}`;
// TODO: Remove when satisfied with new manifestJobHandler infrastructure
if (this.currJob.manifestPrefix) {
const searchFlag = this.currJob.payload.stable ? '-g' : '';
this.currJob.deployCommands[
this.currJob.deployCommands.length - 1
] = `make next-gen-deploy MUT_PREFIX=${this.currJob.payload.mutPrefix}`;
// TODO: Remove when satisfied with new manifestJobHandler infrastructure
if (this.currJob.manifestPrefix) {
const searchFlag = this.currJob.payload.stable ? '-g' : '';
this.currJob.deployCommands[
this.currJob.deployCommands.length - 1
] += ` MANIFEST_PREFIX=${this.currJob.manifestPrefix} GLOBAL_SEARCH_FLAG=${searchFlag}`;
}
] += ` MANIFEST_PREFIX=${this.currJob.manifestPrefix} GLOBAL_SEARCH_FLAG=${searchFlag}`;
}

// have to combine search deploy commands
// manifestJobHandler.prepDeployCommands

Expand Down
14 changes: 6 additions & 8 deletions src/job/stagingJobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ export class StagingJobHandler extends JobHandler {
prepDeployCommands(): void {
// TODO: Can we make this more readable?
this.currJob.deployCommands = ['. /venv/bin/activate', `cd repos/${getDirectory(this.currJob)}`, 'make stage'];
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove '. /ven/bin/activate' as that will cause errors when removing the legacy dependencies from the Dockerfile. We can also remove 'make stage' as this now will never be used. In fact, this could be simplified even more by simply doing something like:

this.currJob.deployCommands = [`cd repos/${getDirectory(this.currJob)}`, `make next-gen-stage ${this.currJob.payload.pathPrefix ? `MUT_PREFIX=${this.currJob.payload.mutPrefix}` : '' }`];

if (this.currJob.payload.isNextGen) {
if (this.currJob.payload.pathPrefix) {
this.currJob.deployCommands[
this.currJob.deployCommands.length - 1
] = `make next-gen-stage MUT_PREFIX=${this.currJob.payload.mutPrefix}`;
} else {
this.currJob.deployCommands[this.currJob.deployCommands.length - 1] = 'make next-gen-stage';
}
if (this.currJob.payload.pathPrefix) {
this.currJob.deployCommands[
this.currJob.deployCommands.length - 1
] = `make next-gen-stage MUT_PREFIX=${this.currJob.payload.mutPrefix}`;
} else {
this.currJob.deployCommands[this.currJob.deployCommands.length - 1] = 'make next-gen-stage';
}
}

Expand Down
Loading
Loading