coolify/apps/api/src/lib/buildPacks/nuxtjs.ts

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-02-10 14:47:44 +00:00
import { promises as fs } from 'fs';
2022-12-21 09:11:03 +00:00
import { generateSecrets } from '../common';
import { buildCacheImageWithNode, buildImage, checkPnpm } from './common';
2022-02-10 14:47:44 +00:00
const createDockerfile = async (data, image): Promise<void> => {
const {
applicationId,
buildId,
tag,
workdir,
publishDirectory,
port,
installCommand,
buildCommand,
startCommand,
baseDirectory,
secrets,
2022-05-02 12:15:50 +00:00
pullmergeRequestId,
deploymentType,
baseImage
} = data;
2022-02-10 14:47:44 +00:00
const Dockerfile: Array<string> = [];
const isPnpm = checkPnpm(installCommand, buildCommand, startCommand);
2022-02-10 14:47:44 +00:00
Dockerfile.push(`FROM ${image}`);
2022-03-20 22:51:50 +00:00
Dockerfile.push('WORKDIR /app');
2022-05-02 12:15:50 +00:00
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
2022-02-10 14:47:44 +00:00
if (secrets.length > 0) {
2022-12-21 09:11:03 +00:00
generateSecrets(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
2022-02-10 14:47:44 +00:00
});
}
if (isPnpm) {
2022-06-02 19:59:51 +00:00
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7');
}
if (deploymentType === 'node') {
Dockerfile.push(`COPY .${baseDirectory || ''} ./`);
Dockerfile.push(`RUN ${installCommand}`);
2022-02-10 14:47:44 +00:00
Dockerfile.push(`RUN ${buildCommand}`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ${startCommand}`);
} else if (deploymentType === 'static') {
if (baseImage?.includes('nginx')) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
Dockerfile.push(`EXPOSE 80`);
2022-02-10 14:47:44 +00:00
}
2022-02-10 14:47:44 +00:00
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
};
export default async function (data) {
try {
const { baseImage, baseBuildImage, deploymentType, buildCommand } = data;
if (deploymentType === 'node') {
await createDockerfile(data, baseImage);
await buildImage(data);
} else if (deploymentType === 'static') {
if (buildCommand) await buildCacheImageWithNode(data, baseBuildImage);
await createDockerfile(data, baseImage);
await buildImage(data);
}
2022-02-10 14:47:44 +00:00
} catch (error) {
throw error;
}
}