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-4033]: Replicate shared.mk steps within Autobuilder code #917

Merged
merged 56 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9878242
[DOP-4033]: Add initial commands
branberry Sep 21, 2023
902a357
[DOP-4033]: Create helpers for cli commands
branberry Sep 21, 2023
534084b
[DOP-4033]: Add default args
branberry Sep 21, 2023
8995249
[DOP-4033]: Move directories
branberry Sep 21, 2023
1ccbad7
[DOP-4033]: Update spawn to work async and add code for getPatchId co…
branberry Sep 22, 2023
5281b13
[DOP-4033]: Refactor executeCliCommand
branberry Sep 22, 2023
dce8dd7
[DOP-4033]: Wrap up nextgenparse refactor
branberry Sep 22, 2023
7324870
[DOP-4033]: Move commands directory out of enhanced
branberry Sep 22, 2023
ab09876
[DOP-4033]: Add next gen html command
branberry Sep 22, 2023
18ff8d8
[DOP-4033]: Use correct arg for createEnvProdFile
branberry Sep 22, 2023
8e03ca2
[DOP-4033]: Add git hash
branberry Sep 25, 2023
3566e9a
[DOP-4033]: Move commands into shared directory
branberry Sep 26, 2023
7d4dca6
[DOP-4033]: Refactor
branberry Sep 26, 2023
43efb54
[DOP-4033]: Create base job for standard builds ie jobs with makefile…
branberry Sep 26, 2023
6a39606
[DOP-4033]: Add the ability to append to file using executeCliCommand
branberry Sep 26, 2023
e27bae3
[DOP-4033]: Add logic to write to .env.production file
branberry Sep 26, 2023
6b9df11
[DOP-4033]: Add more logic to write to files and start working creati…
branberry Sep 27, 2023
3ae00e3
[DOP-4033]: Add local testing app and make test build faster
branberry Sep 27, 2023
32f7dc6
[DOP-4033]: Add test code to confirm commands work, and remove base d…
branberry Sep 27, 2023
8b9519d
[DOP-4033]: Add next-gen-stage, and add support for arm64 dockerfile
branberry Sep 29, 2023
4518c13
[DOP-4033]: Remove extra args from dockerfile
branberry Sep 29, 2023
a9ae14a
[DOP-4033]: Add oas-page-build and persistence module
branberry Sep 29, 2023
c5037fd
[DOP-4033]: Add bundle path for oaspagebuild
branberry Sep 29, 2023
9f3cd88
[DOP-4033]: Work on logic for deploy and ability to pipe output from …
branberry Oct 2, 2023
4b5a432
[DOP-4033]: Work on logic for deploy and ability to pipe output from …
branberry Oct 2, 2023
1a635d1
[DOP-4033]: Work on logic for deploy and ability to pipe output from …
branberry Oct 3, 2023
82872a0
[DOP-4033]: Finish up pipe logic
branberry Oct 3, 2023
d6798e3
[DOP-4033]: Add next-gen-deploy
branberry Oct 3, 2023
66bd820
[DOP-4033]: Remove unused imports
branberry Oct 3, 2023
dcc7e62
[DOP-4033]: Remove standard job handler
branberry Oct 3, 2023
24b4c00
[DOP-4033]: Add execution helper
branberry Oct 3, 2023
c5d6680
[DOP-4033]: Refactor localApp
branberry Oct 3, 2023
17830fb
[DOP-4033]: Add stage job
branberry Oct 4, 2023
ff2aeb0
Merge branch 'master' into DOP-4033
branberry Oct 4, 2023
d2c6f13
[DOP-4033]: Update persistence module
branberry Oct 5, 2023
4827b01
[DOP-4033]: Add next-gen-deploy
branberry Oct 6, 2023
9b28c5d
Merge branch 'master' into DOP-4033
branberry Oct 6, 2023
5c44115
[DOP-4033]: Update next-gen-deploy to work
branberry Oct 6, 2023
42753cf
[DOP-4033]: Add comments
branberry Oct 11, 2023
6749b66
[DOP-4033]: Add more comments
branberry Oct 11, 2023
dc492ac
[DOP-4033]: Remove index.ts
branberry Oct 12, 2023
3adf633
[DOP-4033]: Refactor to use index file
branberry Oct 12, 2023
de8ae8c
Merge branch 'master' into DOP-4033
branberry Oct 12, 2023
b2bc784
[DOP-4033]: Use correct values for nextgenstage
branberry Oct 16, 2023
bdacf2d
[DOP-4033]: Respond to review comments
branberry Oct 16, 2023
1f0328b
[DOP-4033]: Use PATH_PREFIX
branberry Oct 16, 2023
f5497f9
[DOP-4033]: Remove param0
branberry Oct 16, 2023
fbb0256
[DOP-4033]: Respond to review feedback
branberry Oct 17, 2023
80f4e2f
[DOP-4033]: Respond to review feedback
branberry Oct 17, 2023
a06ebe1
[DOP-4033]: Remove extra log
branberry Oct 17, 2023
99ad2e1
[DOP-4033]: Add empty string to join to remove commas
branberry Oct 17, 2023
079fe47
[DOP-4033]: Use console.log
branberry Oct 17, 2023
0d63308
[DOP-4033]: Check array length
branberry Oct 19, 2023
234c843
[DOP-4033]: Add error handling for dependency helper
branberry Oct 19, 2023
759689a
Merge branch 'master' into DOP-4033
branberry Oct 20, 2023
e442448
Merge branch 'master' into DOP-4033
branberry Oct 26, 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
101 changes: 101 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
FROM arm64v8/ubuntu:20.04
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IGNORE: This is for local testing. This will probably change.

ARG NPM_BASE_64_AUTH
ARG NPM_EMAIL
ARG SNOOTY_PARSER_VERSION=0.14.9
ARG SNOOTY_FRONTEND_VERSION=0.14.18
ARG MUT_VERSION=0.10.7
ARG REDOC_CLI_VERSION=1.2.2
ARG NPM_BASE_64_AUTH
ARG NPM_EMAIL
ENV DEBIAN_FRONTEND=noninteractive

# helper libraries for docs builds
RUN apt-get update && apt-get install -y vim git unzip zip

# get node 18
# https://gist.github.com/RinatMullayanov/89687a102e696b1d4cab
RUN apt-get install --yes curl
RUN curl --location https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential
RUN apt-get install --yes python3-pip libxml2-dev libxslt-dev python-dev pkg-config

WORKDIR /app

RUN python3 -m pip install poetry

# install snooty parser
RUN git clone -b v${SNOOTY_PARSER_VERSION} --depth 1 https://github.com/mongodb/snooty-parser.git \
&& cd snooty-parser \
&& python3 -m poetry install \
&& make package \
&& mv dist/snooty /opt/

# install mut

RUN git clone -b v${MUT_VERSION} --depth 1 https://github.com/mongodb/mut.git \
&& cd mut \
&& python3 -m poetry install \
&& make package \
&& mv dist/mut /opt/

RUN curl -L -o redoc.zip https://github.com/mongodb-forks/redoc/archive/refs/tags/v${REDOC_CLI_VERSION}.zip \
&& unzip redoc.zip \
&& mv redoc-${REDOC_CLI_VERSION} redoc/

ENV PATH="${PATH}:/opt/snooty:/opt/mut:/app/.local/bin"

# setup user and root directory
RUN useradd -ms /bin/bash docsworker
RUN chmod 755 -R /app
RUN chown -Rv docsworker /app
USER docsworker

# install snooty frontend and docs-tools
RUN git clone -b v${SNOOTY_FRONTEND_VERSION} --depth 1 https://github.com/mongodb/snooty.git \
&& cd snooty \
&& npm ci --legacy-peer-deps --omit=dev

RUN mkdir -p modules/persistence && chmod 755 modules/persistence
COPY modules/persistence/package*.json ./modules/persistence/
RUN cd ./modules/persistence \
&& npm ci --legacy-peer-deps

RUN mkdir -p modules/oas-page-builder && chmod 755 modules/oas-page-builder
COPY modules/oas-page-builder/package*.json ./modules/oas-page-builder/
RUN cd ./modules/oas-page-builder \
&& npm ci --legacy-peer-deps

# Root project build
COPY package*.json ./
RUN npm ci --legacy-peer-deps
# Build persistence module

COPY --chown=docsworker modules/persistence/tsconfig*.json ./modules/persistence
COPY --chown=docsworker modules/persistence/src ./modules/persistence/src/
COPY --chown=docsworker modules/persistence/index.ts ./modules/persistence

RUN cd ./modules/persistence \
&& npm run build

# Build modules
# OAS Page Builder
COPY --chown=docsworker modules/oas-page-builder/tsconfig*.json ./modules/oas-page-builder
COPY --chown=docsworker modules/oas-page-builder/src ./modules/oas-page-builder/src/
COPY --chown=docsworker modules/oas-page-builder/index.ts ./modules/oas-page-builder

RUN cd ./modules/oas-page-builder \
&& npm run build

COPY tsconfig*.json ./
COPY config config/
COPY api api/
COPY src src/

RUN npm run build:esbuild

RUN mkdir repos && chmod 755 repos

EXPOSE 3000

CMD ["node", "--enable-source-maps", "dist/entrypoints/localApp.js"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "node index.js",
"clean": "node maintain.js",
"build": "tsc",
"build:esbuild": "esbuild src/entrypoints/localApp.ts --bundle --platform=node --outdir=./dist/entrypoints --allow-overwrite --sourcemap",
Copy link
Contributor Author

@branberry branberry Oct 11, 2023

Choose a reason for hiding this comment

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

Added this to improve the build time of the app for quicker testing. Added sourcemaps for more accurate stack traces. Basically, it will tell the exact line in the TS code where an error occurs.

"format": "npm run prettier -- --check",
"format:fix": "npm run prettier -- --write",
"lint": "eslint --ext .ts .",
Expand Down
17 changes: 17 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { prepareBuildAndGetDependencies } from './src/helpers/dependency-helpers';
import { nextGenDeploy } from './src/shared/next-gen-deploy';
import { nextGenHtml } from './src/shared/next-gen-html';
import { nextGenParse } from './src/shared/next-gen-parse';
import { nextGenStage } from './src/shared/next-gen-stage';
import { oasPageBuild } from './src/shared/oas-page-build';
import { persistenceModule } from './src/shared/persistence-module';

export {
nextGenParse,
nextGenHtml,
nextGenStage,
persistenceModule,
oasPageBuild,
nextGenDeploy,
prepareBuildAndGetDependencies,
};
60 changes: 60 additions & 0 deletions src/commands/src/helpers/dependency-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import path from 'path';
import fs from 'fs';
import { executeCliCommand, getCommitBranch, getCommitHash, getPatchId, getRepoDir } from '.';
import { promisify } from 'util';

const existsAsync = promisify(fs.exists);
const writeFileAsync = promisify(fs.writeFile);

async function cloneRepo(repoName: string) {
await executeCliCommand({
command: 'git',
args: ['clone', `https://github.com/mongodb/${repoName}`],
options: { cwd: `${process.cwd()}/repos` },
});
}
async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: string, prefix = '') {
const prodFileName = `${process.cwd()}/snooty/.env.production`;

try {
await writeFileAsync(
prodFileName,
`GATSBY_SITE=${projectName}
GATSBY_MANIFEST_PATH=${repoDir}/bundle.zip
GATSBY_PARSER_USER=${process.env.USER}
GATSBY_BASE_URL=${baseUrl}
PATH_PREFIX=${prefix}`,
'utf8'
);
} catch (e) {
console.error(`ERROR! Could not write to .env.production`);
throw e;
}
}

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

const repoDir = getRepoDir(repoName);

// doing these in parallel
const commandPromises = [
getCommitHash(repoDir),
getCommitBranch(repoDir),
getPatchId(repoDir),
existsAsync(path.join(process.cwd(), 'config/redirects')),
createEnvProdFile(repoDir, projectName, baseUrl),
];

const dependencies = await Promise.all(commandPromises);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@branberry would we want to provide a way of catching or handling the error message if one of these promises are rejected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question, that is something I have been thinking about. I was thinking that maybe the error handling could occur in the place where this function gets called to simplify this code, but I am not set in stone on that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@branberry this was a pretty good read, on how and where to raise an error to be handled.


return {
commitHash: dependencies[0] as string,
commitBranch: dependencies[1] as string,
patchId: dependencies[2] as string | undefined,
hasRedirects: dependencies[3] as boolean,
bundlePath: `${repoDir}/bundle.zip`,
repoDir,
};
}
Loading
Loading