🌳
pt0/deployF/dockerF/getDockerBaseStrF.mts
3import * as _ from 'lodash-es'
7import { npmName } from './npmNameF.mts'
8import { initDockFile } from './dockFileF.mts'
17import type { absFileDirPath } from '../../ptDirF.mts'
18import type { DockFile } from './dockFileF.mts'
20export const getDockerBaseStr = async ({
21 afterYarnInstallDockPathsA, aptPkgNames = [], fromImgName,
22 extraDockerSetupLine, appPath, includeShaInTag,
23 bundle, entrypointAbsPath, bundleName, nativeInstallPackages = [],
24}: {
25 afterYarnInstallDockPathsA: string[], aptPkgNames?: string[], fromImgName?: string,
26 extraDockerSetupLine?: string, appPath: string, includeShaInTag?: boolean,
27 bundle?: boolean, entrypointAbsPath?: string, bundleName?: string, nativeInstallPackages?: string[],
28}): Promise<DockFile> => {
29 fromImgName ||= nodeJsDockerImage()
31 const dockFile = initDockFile(`FROM ${fromImgName} AS yarninstallstage`, {includeShaInTag})
32 const {pushLine, pushCpTar} = dockFile
34 pushLine(`WORKDIR ${dockerApproot}`)
36 let aptInstallStr = `RUN echo ${dockBumpNo} && apt-get update && apt-get install -y apt-transport-https`
38 aptInstallStr += ` && echo omg`
39 pushLine(aptInstallStr)
41 if (aptPkgNames.length > 0) {
42 pushLine(`RUN apt-get update && apt-get install -y ${[...aptPkgNames].sort().join(' ')}`)
43 }
45 if (extraDockerSetupLine) pushLine(extraDockerSetupLine)
46 if ((getAppCfg() as Record<string, unknown>)?.forceIpv4Dns) dockFile.pushEnv('NODE_OPTIONS', '--dns-result-order=ipv4first', {append: true})
48 if (bundle) {
49 pushCpTar(await genBundleTar({entrypointAbsPath: entrypointAbsPath!, bundleName: bundleName!, externalA: nativeInstallPackages}))
50 pushLine(`WORKDIR ${dockerApproot}`)
51 pushLine(`ENV PT_DIR=${dockerApproot}`)
52 if (nativeInstallPackages.length) pushLine(`RUN npm install ${nativeInstallPackages.join(' ')}`)
53 return dockFile
54 }
56 const packageJsonPath = `${ptDir}/${appPath}/package.json`
57 const pkgJsonA = await recPkgJsonsPathA({packageJsonPath}) as {packageJsonPath: string, pkgJson: {name: string}}[]
58 const pkgJsonPtPathA = pkgJsonA.map(p => absPathToPtPath(p.packageJsonPath as absFileDirPath))
60 pushCpTar(await dockerTarPaths({dockerPathsA: _.uniq([
61 ...pkgJsonPtPathA,
62 ...globalDependPaths,
63 ])}))
65 pushLine(`ENV CXXFLAGS="--std=c++14"`)
66 pushLine(`#^ https://github.com/nodejs/node/issues/38367`)
68 if ((npmName as string) == 'yarn') {
69 pushLine(`WORKDIR ${getFullAppPath({appPath})}`)
70 pushLine(`# workaround for openid-client@5.1.8: The engine "node" is incompatible with this module
71RUN yarn install --ignore-engines --production`)
72 } else if (npmName == 'pnpm') {
73 assertDefined(pkgJsonA[0])
74 const appPkgName = pkgJsonA[0].pkgJson.name
76 pushLine(`ENV PNPM_HOME="/pnpm"`)
77 pushLine(`ENV PATH="$PNPM_HOME:$PATH"`)
78 pushLine(corepackInstallLine)
79 const pnpmInstallCmd = `pnpm install --frozen-lockfile --filter ${appPkgName}...`
80 pushLine(isKanikojob()
81 ? `RUN ${pnpmInstallCmd}`
82 : `RUN --mount=type=cache,id=pnpm,target=/pnpm/store ${pnpmInstallCmd}`)
83 }
85 pushLine(`RUN echo ${afterYarnBumpNo}`)
86 pushLine(`WORKDIR ${dockerApproot}`)
88 pushCpTar(await dockerTarPaths({dockerPathsA: afterYarnInstallDockPathsA}))
90 return dockFile