diff --git a/Dockerfile.local b/Dockerfile.local index 9c8b6b15b..944e81b29 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -69,11 +69,6 @@ RUN cd ./modules/oas-page-builder \ # Root project build COPY package*.json ./ RUN npm ci --legacy-peer-deps -COPY tsconfig*.json ./ -COPY config config/ -COPY api api/ -COPY src src/ - # Build persistence module COPY --chown=docsworker modules/persistence/tsconfig*.json ./modules/persistence @@ -85,7 +80,6 @@ RUN cd ./modules/persistence \ # 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 @@ -93,10 +87,15 @@ COPY --chown=docsworker modules/oas-page-builder/index.ts ./modules/oas-page-bui 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", "dist/entrypoints/localApp.js"] \ No newline at end of file +CMD ["node", "--enable-source-maps", "dist/entrypoints/localApp.js"] \ No newline at end of file diff --git a/src/commands/src/helpers/execution-helper.ts b/src/commands/src/helpers/execution-helper.ts index 4f78fe317..5341d2879 100644 --- a/src/commands/src/helpers/execution-helper.ts +++ b/src/commands/src/helpers/execution-helper.ts @@ -4,15 +4,36 @@ import { checkIfPatched, getCommitBranch, getCommitHash, getPatchId, getRepoDir import { promisify } from 'util'; const existsAsync = promisify(fs.exists); +const writeFileAsync = promisify(fs.writeFile); -export async function getCliBuildDependencies(repoName: string) { - const repoDir = getRepoDir(repoName); +async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: string, prefix = '') { + const prodFileName = `${process.cwd()}/snooty/.env.production`; + + try { + await writeFileAsync( + prodFileName, + `GATSBY_BASE_URL=docs.mongodb.com + GATSBY_SITE=${projectName} + GATSBY_MANIFEST_PATH=${repoDir}/bundle.zip + GATSBY_PARSER_USER=${process.env.USER} + GATSBY_BASE_URL=${baseUrl} + GATSBY_PATH_PREFIX=${prefix}`, + 'utf8' + ); + } catch (e) { + console.error(`ERROR! Could not write to .env.production`); + throw e; + } +} + +export async function getCliBuildDependencies(repoDir: string, projectName: string, baseUrl: string) { const commandPromises = [ checkIfPatched(repoDir), getCommitHash(repoDir), getCommitBranch(repoDir), getPatchId(repoDir), existsAsync(path.join(process.cwd(), 'config/redirects')), + createEnvProdFile(repoDir, projectName, baseUrl), ]; const deps = await Promise.all(commandPromises); @@ -23,6 +44,5 @@ export async function getCliBuildDependencies(repoName: string) { patchId: deps[3] as string | undefined, hasRedirects: deps[4] as boolean, bundlePath: `${repoDir}/bundle.zip`, - repoDir, }; } diff --git a/src/commands/src/helpers/index.ts b/src/commands/src/helpers/index.ts index 349631509..bbd936f08 100644 --- a/src/commands/src/helpers/index.ts +++ b/src/commands/src/helpers/index.ts @@ -195,19 +195,6 @@ export async function getPatchId(repoDir: string): Promise { } } -export async function addProjectToEnv(project: string) { - return new Promise((resolve, reject) => { - const stream = fs.createWriteStream(path.join(process.cwd(), 'snooty/.env.production'), { flags: 'a+' }); - - stream.write(project); - stream.close(); - stream.on('error', (error) => { - console.log('Error when writing to file!', error); - reject(error); - }); - stream.on('close', resolve); - }); -} export async function getCommitBranch(repoDir: string): Promise { // equivalent to git rev-parse --short HEAD const response = await executeCliCommand({ diff --git a/src/commands/src/shared/next-gen-html.ts b/src/commands/src/shared/next-gen-html.ts index 7ddd91456..226a14a97 100644 --- a/src/commands/src/shared/next-gen-html.ts +++ b/src/commands/src/shared/next-gen-html.ts @@ -1,27 +1,6 @@ -import fs from 'fs'; -import { promisify } from 'util'; import { executeCliCommand } from '../helpers'; -const writeFileAsync = promisify(fs.writeFile); - -async function createEnvProdFile(repoDir: string, projectName: string) { - try { - await writeFileAsync( - `${process.cwd()}/snooty/.env.production`, - `GATSBY_BASE_URL=docs.mongodb.com - GATSBY_SITE=${projectName} - GATSBY_MANIFEST_PATH=${repoDir}/bundle.zip`, - 'utf8' - ); - } catch (e) { - console.error(`ERROR! Could not write to .env.production`); - throw e; - } -} -export async function nextGenHtml(repoDir: string) { - // might move this since technically next-gen-html doesn't create the file - await createEnvProdFile(repoDir, 'java'); - +export async function nextGenHtml() { const result = await executeCliCommand({ command: 'npm', args: ['run', 'build'], diff --git a/src/commands/src/shared/next-gen-stage.ts b/src/commands/src/shared/next-gen-stage.ts index 84bee695b..ac583454a 100644 --- a/src/commands/src/shared/next-gen-stage.ts +++ b/src/commands/src/shared/next-gen-stage.ts @@ -1,4 +1,11 @@ -import { checkIfPatched, executeCliCommand, getCommitBranch, getCommitHash, getPatchId, getRepoDir } from '../helpers'; +import { + checkIfPatched, + executeAndWriteToFile, + executeCliCommand, + getCommitBranch, + getCommitHash, + getPatchId, +} from '../helpers'; interface StageParams { repoDir: string; @@ -11,17 +18,26 @@ interface StageParams { export async function nextGenStage({ repoDir, mutPrefix, projectName, bucketName, url }: StageParams) { const [hasPatch, commitBranch] = await Promise.all([checkIfPatched(repoDir), getCommitBranch(repoDir)]); - let hostedAtUrl = `${url}/${mutPrefix}/${process.env.USER}/${commitBranch}/`; + let hostedAtUrl = `${url}/${mutPrefix}/docsworker/${commitBranch}/`; + let prefix = mutPrefix; const commandArgs = ['public', bucketName, '--stage']; - if (hasPatch && projectName !== mutPrefix) { + if (hasPatch && projectName === mutPrefix) { const [commitHash, patchId] = await Promise.all([getCommitHash(repoDir), getPatchId(repoDir)]); - commandArgs.push(`--prefix="${commitHash}/${patchId}/${mutPrefix}"`); - hostedAtUrl = `${url}/${commitHash}/${patchId}/${mutPrefix}/${process.env.USER}/${commitBranch}/`; + prefix = `${commitHash}/${patchId}/${mutPrefix}`; + hostedAtUrl = `${url}/${commitHash}/${patchId}/${mutPrefix}/docsworker/${commitBranch}/`; } - const { outputText } = await executeCliCommand({ command: 'mut-publish', args: commandArgs }); + commandArgs.push(`--prefix="${prefix}"`); + + const { outputText } = await executeCliCommand({ + command: 'mut-publish', + args: commandArgs, + options: { + cwd: `${process.cwd()}/snooty`, + }, + }); const resultMessage = `${outputText}\n Hosted at ${hostedAtUrl}`; return resultMessage; } diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index c0941e476..319b5e27a 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -1,19 +1,25 @@ -import { executeCliCommand } from '../commands/src/helpers'; +import { executeCliCommand, getRepoDir } from '../commands/src/helpers'; import { nextGenParse } from '../commands/src/shared/next-gen-parse'; import { nextGenHtml } from '../commands/src/shared/next-gen-html'; import { getCliBuildDependencies } from '../commands/src/helpers/execution-helper'; +import { nextGenStage } from '../commands/src/shared/next-gen-stage'; +import { oasPageBuild } from '../commands/src/shared/oas-page-build'; async function localApp() { - const repoName = 'docs-landing'; - const { repoDir, commitHash, patchId } = await getCliBuildDependencies(repoName); + const repoName = 'docs-java'; + const projectName = 'java'; + const baseUrl = 'https://www.mongodb.com'; + const repoDir = getRepoDir(repoName); + // mocking out the clone aspect of a job await executeCliCommand({ command: 'git', args: ['clone', `https://github.com/mongodb/${repoName}`], - options: { cwd: repoDir }, + options: { cwd: `${process.cwd()}/repos` }, }); - console.log('Hello'); + const { commitHash, patchId, bundlePath } = await getCliBuildDependencies(repoDir, projectName, baseUrl); + console.log('Begin snooty build...'); const snootyBuildRes = await nextGenParse({ repoDir, commitHash, patchId }); @@ -23,13 +29,27 @@ async function localApp() { console.log('Begin next-gen-html...'); - const nextGenHtmlRes = await nextGenHtml(repoName); + const nextGenHtmlRes = await nextGenHtml(); + console.log('Begin oas-page-build...'); + const mutPrefix = 'docs'; + const siteUrl = mutPrefix ? `${baseUrl}/${mutPrefix}` : `${baseUrl}`; + const oasPageBuildRes = await oasPageBuild({ repoDir, bundlePath, siteUrl }); console.log(nextGenHtmlRes.outputText); console.log('next-gen-html complete'); console.log('Begin next-gen-stage...'); + + const resultMessage = await nextGenStage({ + repoDir, + projectName, + bucketName: 'docs-mongodb-org-stg', + url: baseUrl, + mutPrefix, + }); + console.log(resultMessage); + console.log('Begin next-gen-stage complete'); } localApp();