-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changes from 47 commits
9878242
902a357
534084b
8995249
1ccbad7
5281b13
dce8dd7
7324870
ab09876
18ff8d8
8e03ca2
3566e9a
7d4dca6
43efb54
6a39606
e27bae3
6b9df11
3ae00e3
32f7dc6
8b9519d
4518c13
a9ae14a
c5037fd
9f3cd88
4b5a432
1a635d1
82872a0
d6798e3
66bd820
dcc7e62
24b4c00
c5d6680
17830fb
ff2aeb0
d2c6f13
4827b01
9b28c5d
5c44115
42753cf
6749b66
dc492ac
3adf633
de8ae8c
b2bc784
bdacf2d
1f0328b
f5497f9
fbb0256
80f4e2f
a06ebe1
99ad2e1
079fe47
0d63308
234c843
759689a
e442448
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
FROM arm64v8/ubuntu:20.04 | ||
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"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 .", | ||
|
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, | ||
}; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}; | ||
} |
There was a problem hiding this comment.
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.