29 lines
977 B
TypeScript
Raw Normal View History

2022-02-10 15:47:44 +01:00
import { promises as fs } from 'fs';
2022-07-06 11:02:36 +02:00
import { buildCacheImageWithNode, buildImage } from './common';
2022-02-10 15:47:44 +01:00
const createDockerfile = async (data, image): Promise<void> => {
2022-05-04 15:45:44 +02:00
const { applicationId, tag, workdir, publishDirectory, baseImage, buildId, port } = data;
2022-02-10 15:47:44 +01:00
const Dockerfile: Array<string> = [];
Dockerfile.push(`FROM ${image}`);
2022-05-02 14:15:50 +02:00
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
2022-03-21 21:25:01 +01:00
Dockerfile.push('WORKDIR /app');
2022-03-20 23:51:50 +01:00
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
if (baseImage?.includes('nginx')) {
2022-04-26 14:51:08 +02:00
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
2022-05-04 15:45:44 +02:00
Dockerfile.push(`EXPOSE ${port}`);
2022-02-10 15:47:44 +01:00
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
};
export default async function (data) {
try {
2022-04-26 14:51:08 +02:00
const { baseImage, baseBuildImage } = data;
await buildCacheImageWithNode(data, baseBuildImage);
await createDockerfile(data, baseImage);
2022-02-10 15:47:44 +01:00
await buildImage(data);
} catch (error) {
throw error;
}
}