🌳
pt0/nextF/deployF/buildNextDfF.mts
1import * as _ from 'lodash-es'
9import type { absFileDirPath } from '../../ptDirF.mts'
11type BuildResult = (DockFile | BakedDf)[] & {imageReused?: boolean}
13export const buildNextDf = async ({action, dockerEnv, git_sha, buildSha, afterYarnInstallDockPathsA}: {action?: string, dockerEnv: Record<string, string>, git_sha: string, buildSha?: string, afterYarnInstallDockPathsA: absFileDirPath[]}) => {
14 if (isWithNix()) {
16 return await nixBuildNextImg({action: action!, dockerEnv, git_sha, afterYarnInstallDockPathsA})
17 }
18 const ctx = getReqNextDeployCtx() as Record<string, any>
19 const {appPath, aptPkgNames, name, git_repo_name, dockreg_host, dockLanHost, cluster_name, kanikoClusterName: _kanikoClusterName} = ctx
20 let kanikoClusterName = _kanikoClusterName as string | undefined
22 kanikoClusterName ||= cluster_name
24 const {cfProxied} = ctx
25 const nextbuildDockerEnv = {..._.omit(dockerEnv, runtimeOnlyDockerEnvKeys), NEXT_PUBLIC_GIT_SHA: buildSha || git_sha, ...(cfProxied && {NEXT_PUBLIC_CF_PROXIED: '1'})}
27 const rebuildDf: DockFile & {imageReused?: boolean} = await dockerFileNextBuild({
28 aptPkgNames, dockerEnv: nextbuildDockerEnv, afterYarnInstallDockPathsA,
29 })
31 const dfNextBuildRaw = await dockerBuildAndRet({
32 dfToBuild: rebuildDf,
33 name, git_sha, git_repo_name, dockreg_host, dockLanHost, kanikoClusterName,
34 appPath, dfLabel: 'nextbuild',
35 reqDockPush: true,
36 })
37 const nextbuildImageReused = rebuildDf.imageReused
39 const dfNextBuild = await dfNextBuildRaw.getRnt()
40 const runtimeDockerEnv = _.omit(dockerEnv, runtimeOnlyDockerEnvKeys)
41 const dockFile = await dockerFileNextServ({
42 appPath, dockerEnv: runtimeDockerEnv,
43 lastNextBuildDf: dfNextBuild,
44 })
46 const dfNextStart = await dockerBuildAndRet({
47 dfToBuild: dockFile,
48 name, action, git_sha, git_repo_name, dockreg_host, dockLanHost, kanikoClusterName,
49 appPath, dfLabel: 'runtime',
50 })
52 const result: BuildResult = flatDfBuild ? [dfNextStart] : [dfNextBuild, dfNextStart]
53 if (nextbuildImageReused) result.imageReused = true
54 return result