feat: Ability to change deployment type for nuxtjs
This commit is contained in:
@@ -17,7 +17,7 @@ const nodeBased = [
|
|||||||
'nextjs'
|
'nextjs'
|
||||||
];
|
];
|
||||||
|
|
||||||
export function setDefaultBaseImage(buildPack: string | null, deploymentType: string | null) {
|
export function setDefaultBaseImage(buildPack: string | null, deploymentType: string | null = null) {
|
||||||
const nodeVersions = [
|
const nodeVersions = [
|
||||||
{
|
{
|
||||||
value: 'node:lts',
|
value: 'node:lts',
|
||||||
|
@@ -69,7 +69,6 @@ export default async function (data) {
|
|||||||
await createDockerfile(data, baseImage);
|
await createDockerfile(data, baseImage);
|
||||||
await buildImage(data);
|
await buildImage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { buildImage, checkPnpm } from './common';
|
import { buildCacheImageWithNode, buildImage, checkPnpm } from './common';
|
||||||
|
|
||||||
const createDockerfile = async (data, image): Promise<void> => {
|
const createDockerfile = async (data, image): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
|
applicationId,
|
||||||
|
buildId,
|
||||||
|
tag,
|
||||||
workdir,
|
workdir,
|
||||||
|
publishDirectory,
|
||||||
port,
|
port,
|
||||||
installCommand,
|
installCommand,
|
||||||
buildCommand,
|
buildCommand,
|
||||||
@@ -11,7 +15,8 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
baseDirectory,
|
baseDirectory,
|
||||||
secrets,
|
secrets,
|
||||||
pullmergeRequestId,
|
pullmergeRequestId,
|
||||||
buildId
|
deploymentType,
|
||||||
|
baseImage
|
||||||
} = data;
|
} = data;
|
||||||
const Dockerfile: Array<string> = [];
|
const Dockerfile: Array<string> = [];
|
||||||
const isPnpm = checkPnpm(installCommand, buildCommand, startCommand);
|
const isPnpm = checkPnpm(installCommand, buildCommand, startCommand);
|
||||||
@@ -36,21 +41,34 @@ const createDockerfile = async (data, image): Promise<void> => {
|
|||||||
if (isPnpm) {
|
if (isPnpm) {
|
||||||
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7');
|
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7');
|
||||||
}
|
}
|
||||||
Dockerfile.push(`COPY .${baseDirectory || ''} ./`);
|
if (deploymentType === 'node') {
|
||||||
Dockerfile.push(`RUN ${installCommand}`);
|
Dockerfile.push(`COPY .${baseDirectory || ''} ./`);
|
||||||
if (buildCommand) {
|
Dockerfile.push(`RUN ${installCommand}`);
|
||||||
Dockerfile.push(`RUN ${buildCommand}`);
|
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`);
|
||||||
}
|
}
|
||||||
Dockerfile.push(`EXPOSE ${port}`);
|
|
||||||
Dockerfile.push(`CMD ${startCommand}`);
|
|
||||||
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function (data) {
|
export default async function (data) {
|
||||||
try {
|
try {
|
||||||
const { baseImage, baseBuildImage } = data;
|
const { baseImage, baseBuildImage, deploymentType, buildCommand } = data;
|
||||||
await createDockerfile(data, baseImage);
|
if (deploymentType === 'node') {
|
||||||
await buildImage(data);
|
await createDockerfile(data, baseImage);
|
||||||
|
await buildImage(data);
|
||||||
|
} else if (deploymentType === 'static') {
|
||||||
|
if (buildCommand) await buildCacheImageWithNode(data, baseBuildImage);
|
||||||
|
await createDockerfile(data, baseImage);
|
||||||
|
await buildImage(data);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,15 @@ export async function getImages(request: FastifyRequest) {
|
|||||||
port = '3000'
|
port = '3000'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (buildPack === 'nuxtjs') {
|
||||||
|
if (deploymentType === 'static') {
|
||||||
|
publishDirectory = 'dist'
|
||||||
|
port = '80'
|
||||||
|
} else {
|
||||||
|
publishDirectory = ''
|
||||||
|
port = '3000'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return { baseImage, baseBuildImage, baseBuildImages, baseImages, publishDirectory, port }
|
return { baseImage, baseBuildImage, baseBuildImages, baseImages, publishDirectory, port }
|
||||||
|
@@ -95,7 +95,8 @@ export function findBuildPack(pack: string, packageManager = 'npm') {
|
|||||||
...metaData,
|
...metaData,
|
||||||
...defaultBuildAndDeploy(packageManager),
|
...defaultBuildAndDeploy(packageManager),
|
||||||
publishDirectory: null,
|
publishDirectory: null,
|
||||||
port: 3000
|
port: 3000,
|
||||||
|
deploymentType: 'node'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (pack === 'preact') {
|
if (pack === 'preact') {
|
||||||
|
@@ -466,7 +466,7 @@
|
|||||||
<Explainer text={$t('application.base_image_explainer')} />
|
<Explainer text={$t('application.base_image_explainer')} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if application.buildPack !== 'docker' && application.buildPack === 'nextjs'}
|
{#if application.buildPack !== 'docker' && (application.buildPack === 'nextjs' || application.buildPack === 'nuxtjs')}
|
||||||
<div class="grid grid-cols-2 items-center pb-8">
|
<div class="grid grid-cols-2 items-center pb-8">
|
||||||
<label for="deploymentType" class="text-base font-bold text-stone-100"
|
<label for="deploymentType" class="text-base font-bold text-stone-100"
|
||||||
>Deployment Type</label
|
>Deployment Type</label
|
||||||
@@ -484,7 +484,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Explainer
|
<Explainer
|
||||||
text="How to build your application. Static is for static websites, node is for server-side applications."
|
text="Defines how to deploy your application. <br><br><span class='text-green-500 font-bold'>Static</span> is for static websites, <span class='text-green-500 font-bold'>node</span> is for server-side applications."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
Reference in New Issue
Block a user