2018-09-13 19:28:23 +03:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2018-09-22 03:48:28 +03:00
|
|
|
import { getExposeStatements, IPlatformGeneratorInfo, PackageInfo } from './configure';
|
2018-09-13 19:28:23 +03:00
|
|
|
|
2018-09-22 03:48:28 +03:00
|
|
|
export let configureNode: IPlatformGeneratorInfo = {
|
2018-09-13 19:28:23 +03:00
|
|
|
genDockerFile,
|
|
|
|
genDockerCompose,
|
2018-09-22 03:48:28 +03:00
|
|
|
genDockerComposeDebug,
|
|
|
|
defaultPort: '3000'
|
2018-09-13 19:28:23 +03:00
|
|
|
};
|
|
|
|
|
2018-09-18 21:32:34 +03:00
|
|
|
function genDockerFile(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { cmd, author, version, artifactName }: Partial<PackageInfo>): string {
|
2018-09-22 03:48:28 +03:00
|
|
|
let exposeStatements = getExposeStatements(port);
|
|
|
|
|
2018-11-15 05:27:56 +03:00
|
|
|
return `FROM node:10.13-alpine
|
2018-09-13 19:28:23 +03:00
|
|
|
ENV NODE_ENV production
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
|
|
|
|
RUN npm install --production --silent && mv node_modules ../
|
|
|
|
COPY . .
|
2018-09-22 03:48:28 +03:00
|
|
|
${exposeStatements}
|
2018-09-13 19:28:23 +03:00
|
|
|
CMD ${cmd}`;
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:32:34 +03:00
|
|
|
function genDockerCompose(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string): string {
|
2018-09-13 19:28:23 +03:00
|
|
|
return `version: '2.1'
|
|
|
|
|
|
|
|
services:
|
2018-09-18 21:32:34 +03:00
|
|
|
${serviceNameAndRelativePath}:
|
|
|
|
image: ${serviceNameAndRelativePath}
|
2018-09-13 19:28:23 +03:00
|
|
|
build: .
|
|
|
|
environment:
|
|
|
|
NODE_ENV: production
|
|
|
|
ports:
|
|
|
|
- ${port}:${port}`;
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:32:34 +03:00
|
|
|
function genDockerComposeDebug(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { fullCommand: cmd }: Partial<PackageInfo>): string {
|
2018-09-13 19:28:23 +03:00
|
|
|
|
|
|
|
const cmdArray: string[] = cmd.split(' ');
|
|
|
|
if (cmdArray[0].toLowerCase() === 'node') {
|
|
|
|
cmdArray.splice(1, 0, '--inspect=0.0.0.0:9229');
|
|
|
|
cmd = `command: ${cmdArray.join(' ')}`;
|
|
|
|
} else {
|
|
|
|
cmd = '## set your startup file here\n command: node --inspect index.js';
|
|
|
|
}
|
|
|
|
|
|
|
|
return `version: '2.1'
|
|
|
|
|
|
|
|
services:
|
2018-09-20 01:52:19 +03:00
|
|
|
${serviceNameAndRelativePath}:
|
|
|
|
image: ${serviceNameAndRelativePath}
|
|
|
|
build: .
|
|
|
|
environment:
|
|
|
|
NODE_ENV: development
|
|
|
|
ports:
|
|
|
|
- ${port}:${port}
|
|
|
|
- 9229:9229
|
|
|
|
${cmd}`;
|
2018-09-13 19:28:23 +03:00
|
|
|
}
|