feat: Install pnpm into docker image if pnpm lock file is used
This commit is contained in:
@@ -4,13 +4,19 @@ import { promises as fs } from 'fs';
|
|||||||
const createDockerfile = async (data, image): Promise<void> => {
|
const createDockerfile = async (data, image): Promise<void> => {
|
||||||
const { applicationId, tag, port, startCommand, workdir, baseDirectory } = data;
|
const { applicationId, tag, port, startCommand, workdir, baseDirectory } = data;
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
|
const isPnpm = startCommand.includes('pnpm');
|
||||||
|
|
||||||
Dockerfile.push(`FROM ${image}`);
|
Dockerfile.push(`FROM ${image}`);
|
||||||
Dockerfile.push('WORKDIR /usr/src/app');
|
Dockerfile.push('WORKDIR /usr/src/app');
|
||||||
Dockerfile.push(`LABEL coolify.image=true`);
|
Dockerfile.push(`LABEL coolify.image=true`);
|
||||||
|
if (isPnpm) {
|
||||||
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
|
||||||
|
Dockerfile.push('RUN pnpm add -g pnpm');
|
||||||
|
}
|
||||||
Dockerfile.push(
|
Dockerfile.push(
|
||||||
`COPY --from=${applicationId}:${tag}-cache /usr/src/app/${baseDirectory || ''} ./`
|
`COPY --from=${applicationId}:${tag}-cache /usr/src/app/${baseDirectory || ''} ./`
|
||||||
);
|
);
|
||||||
|
|
||||||
Dockerfile.push(`EXPOSE ${port}`);
|
Dockerfile.push(`EXPOSE ${port}`);
|
||||||
Dockerfile.push(`CMD ${startCommand}`);
|
Dockerfile.push(`CMD ${startCommand}`);
|
||||||
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
||||||
|
@@ -13,7 +13,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
pullmergeRequestId
|
pullmergeRequestId
|
||||||
} = data;
|
} = data;
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
|
const isPnpm =
|
||||||
|
installCommand.includes('pnpm') ||
|
||||||
|
buildCommand.includes('pnpm') ||
|
||||||
|
startCommand.includes('pnpm');
|
||||||
Dockerfile.push(`FROM ${image}`);
|
Dockerfile.push(`FROM ${image}`);
|
||||||
Dockerfile.push('WORKDIR /usr/src/app');
|
Dockerfile.push('WORKDIR /usr/src/app');
|
||||||
Dockerfile.push(`LABEL coolify.image=true`);
|
Dockerfile.push(`LABEL coolify.image=true`);
|
||||||
@@ -32,6 +35,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (isPnpm) {
|
||||||
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
|
||||||
|
Dockerfile.push('RUN pnpm add -g pnpm');
|
||||||
|
}
|
||||||
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
||||||
try {
|
try {
|
||||||
await fs.stat(`${workdir}/yarn.lock`);
|
await fs.stat(`${workdir}/yarn.lock`);
|
||||||
|
@@ -13,7 +13,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
pullmergeRequestId
|
pullmergeRequestId
|
||||||
} = data;
|
} = data;
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
|
const isPnpm =
|
||||||
|
installCommand.includes('pnpm') ||
|
||||||
|
buildCommand.includes('pnpm') ||
|
||||||
|
startCommand.includes('pnpm');
|
||||||
Dockerfile.push(`FROM ${image}`);
|
Dockerfile.push(`FROM ${image}`);
|
||||||
Dockerfile.push('WORKDIR /usr/src/app');
|
Dockerfile.push('WORKDIR /usr/src/app');
|
||||||
Dockerfile.push(`LABEL coolify.image=true`);
|
Dockerfile.push(`LABEL coolify.image=true`);
|
||||||
@@ -32,6 +35,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (isPnpm) {
|
||||||
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
|
||||||
|
Dockerfile.push('RUN pnpm add -g pnpm');
|
||||||
|
}
|
||||||
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
||||||
try {
|
try {
|
||||||
await fs.stat(`${workdir}/yarn.lock`);
|
await fs.stat(`${workdir}/yarn.lock`);
|
||||||
|
@@ -13,7 +13,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
pullmergeRequestId
|
pullmergeRequestId
|
||||||
} = data;
|
} = data;
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
|
const isPnpm =
|
||||||
|
installCommand.includes('pnpm') ||
|
||||||
|
buildCommand.includes('pnpm') ||
|
||||||
|
startCommand.includes('pnpm');
|
||||||
Dockerfile.push(`FROM ${image}`);
|
Dockerfile.push(`FROM ${image}`);
|
||||||
Dockerfile.push('WORKDIR /usr/src/app');
|
Dockerfile.push('WORKDIR /usr/src/app');
|
||||||
Dockerfile.push(`LABEL coolify.image=true`);
|
Dockerfile.push(`LABEL coolify.image=true`);
|
||||||
@@ -32,6 +35,10 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (isPnpm) {
|
||||||
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
|
||||||
|
Dockerfile.push('RUN pnpm add -g pnpm');
|
||||||
|
}
|
||||||
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
||||||
try {
|
try {
|
||||||
await fs.stat(`${workdir}/yarn.lock`);
|
await fs.stat(`${workdir}/yarn.lock`);
|
||||||
|
@@ -13,7 +13,7 @@ export function findBuildPack(pack, packageManager = 'npm') {
|
|||||||
if (pack === 'node') {
|
if (pack === 'node') {
|
||||||
return {
|
return {
|
||||||
...metaData,
|
...metaData,
|
||||||
installCommand: null,
|
...defaultBuildAndDeploy(packageManager),
|
||||||
buildCommand: null,
|
buildCommand: null,
|
||||||
startCommand: null,
|
startCommand: null,
|
||||||
publishDirectory: null,
|
publishDirectory: null,
|
||||||
|
@@ -16,6 +16,7 @@ export async function buildCacheImageWithNode(data, imageForBuild) {
|
|||||||
secrets,
|
secrets,
|
||||||
pullmergeRequestId
|
pullmergeRequestId
|
||||||
} = data;
|
} = data;
|
||||||
|
const isPnpm = installCommand.includes('pnpm') || buildCommand.includes('pnpm');
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
Dockerfile.push(`FROM ${imageForBuild}`);
|
Dockerfile.push(`FROM ${imageForBuild}`);
|
||||||
Dockerfile.push('WORKDIR /usr/src/app');
|
Dockerfile.push('WORKDIR /usr/src/app');
|
||||||
@@ -35,7 +36,10 @@ export async function buildCacheImageWithNode(data, imageForBuild) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// TODO: If build command defined, install command should be the default yarn install
|
if (isPnpm) {
|
||||||
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
|
||||||
|
Dockerfile.push('RUN pnpm add -g pnpm');
|
||||||
|
}
|
||||||
if (installCommand) {
|
if (installCommand) {
|
||||||
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
Dockerfile.push(`COPY ./${baseDirectory || ''}package*.json ./`);
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user