2022-02-10 15:47:44 +01:00
|
|
|
import { buildCacheImageWithNode, buildImage } from '$lib/docker';
|
|
|
|
import { promises as fs } from 'fs';
|
|
|
|
|
|
|
|
const createDockerfile = async (data, image): Promise<void> => {
|
|
|
|
const { applicationId, tag, workdir, publishDirectory } = data;
|
|
|
|
const Dockerfile: Array<string> = [];
|
|
|
|
|
|
|
|
Dockerfile.push(`FROM ${image}`);
|
|
|
|
Dockerfile.push('WORKDIR /usr/share/nginx/html');
|
2022-02-28 10:09:34 +01:00
|
|
|
Dockerfile.push(`LABEL coolify.image=true`);
|
2022-03-20 23:51:50 +01:00
|
|
|
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
|
2022-03-20 15:03:24 +01:00
|
|
|
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
|
2022-02-10 15:47:44 +01:00
|
|
|
Dockerfile.push(`EXPOSE 80`);
|
|
|
|
Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]');
|
|
|
|
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
|
|
|
};
|
|
|
|
|
|
|
|
export default async function (data) {
|
|
|
|
try {
|
|
|
|
const image = 'nginx:stable-alpine';
|
|
|
|
const imageForBuild = 'node:lts';
|
|
|
|
await buildCacheImageWithNode(data, imageForBuild);
|
2022-03-20 15:03:24 +01:00
|
|
|
// await fs.writeFile(`${data.workdir}/default.conf`, `server {
|
|
|
|
// listen 80;
|
|
|
|
// server_name localhost;
|
|
|
|
|
|
|
|
// location / {
|
|
|
|
// root /usr/share/nginx/html;
|
|
|
|
// try_files $uri $uri/ /index.html;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// error_page 500 502 503 504 /50x.html;
|
|
|
|
// location = /50x.html {
|
|
|
|
// root /usr/share/nginx/html;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// `);
|
2022-02-10 15:47:44 +01:00
|
|
|
await createDockerfile(data, image);
|
|
|
|
await buildImage(data);
|
|
|
|
} catch (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|