diff --git a/configureWorkspace/config-utils.ts b/configureWorkspace/config-utils.ts index 8252492cb8..1526835c6e 100644 --- a/configureWorkspace/config-utils.ts +++ b/configureWorkspace/config-utils.ts @@ -49,6 +49,7 @@ export async function quickPickPlatform(): Promise { 'Node.js', 'Python', 'Ruby', + 'C++', 'Other' ]; diff --git a/configureWorkspace/configure.ts b/configureWorkspace/configure.ts index 4b1c6cf9a7..619020a169 100644 --- a/configureWorkspace/configure.ts +++ b/configureWorkspace/configure.ts @@ -16,6 +16,7 @@ import { globAsync } from '../helpers/async'; import { extractRegExGroups } from '../helpers/extractRegExGroups'; import { Platform, PlatformOS } from '../utils/platform'; import { promptForPort, quickPickOS, quickPickPlatform } from './config-utils'; +import { configureCpp } from './configure_cpp'; import { configureAspDotNetCore, configureDotNetCoreConsole } from './configure_dotnetcore'; import { configureGo } from './configure_go'; import { configureJava } from './configure_java'; @@ -67,6 +68,7 @@ export function getExposeStatements(port: string): string { const generatorsByPlatform = new Map(); generatorsByPlatform.set('ASP.NET Core', configureAspDotNetCore); +generatorsByPlatform.set('C++', configureCpp); generatorsByPlatform.set('Go', configureGo); generatorsByPlatform.set('Java', configureJava); generatorsByPlatform.set('.NET Core Console', configureDotNetCoreConsole); diff --git a/configureWorkspace/configure_cpp.ts b/configureWorkspace/configure_cpp.ts new file mode 100644 index 0000000000..179f8ff899 --- /dev/null +++ b/configureWorkspace/configure_cpp.ts @@ -0,0 +1,38 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See LICENSE.md in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { getExposeStatements, IPlatformGeneratorInfo, PackageInfo } from './configure'; + +export let configureCpp: IPlatformGeneratorInfo = { + genDockerFile, + genDockerCompose: undefined, // We don't generate compose files for Cpp + genDockerComposeDebug: undefined, // We don't generate compose files for Cpp + defaultPort: undefined // We don't open a port for Cpp +}; + +function genDockerFile(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { cmd, author, version, artifactName }: Partial): string { + let exposeStatements = getExposeStatements(port); + + return `# GCC support can be specified at major, minor, or micro version +# (e.g. 8, 8.2 or 8.2.0). +# See https://hub.docker.com/r/library/gcc/ for all supported GCC +# tags from Docker Hub. +# See https://docs.docker.com/samples/library/gcc/ for more on how to use this image +FROM gcc:latest + +# These commands copy your files into the specified directory in the image +# and set that as the working location +COPY . /usr/src/myapp +WORKDIR /usr/src/myapp + +# This command compiles your app using GCC, adjust for your source code +RUN g++ -o myapp main.cpp + +# This command runs your application, comment out this line to compile only +CMD ["./myapp"] + +LABEL Name=${serviceNameAndRelativePath} Version=${version} +`; +} diff --git a/test/configure.test.ts b/test/configure.test.ts index 190535784e..087d7a23a5 100644 --- a/test/configure.test.ts +++ b/test/configure.test.ts @@ -1154,6 +1154,27 @@ suite("Configure (Add Docker files to Workspace)", function (this: Suite): void }); }); + // C++ + + suite("C++", () => { + testInEmptyFolder("C++", async () => { + await testConfigureDocker( + 'C++', + { + configurePlatform: 'C++', + configureOs: undefined, + packageFileType: undefined, + packageFileSubfolderDepth: undefined + }); + + assertFileContains('Dockerfile', 'FROM gcc:latest'); + assertFileContains('Dockerfile', 'COPY . /usr/src/myapp'); + assertFileContains('Dockerfile', 'WORKDIR /usr/src/myapp'); + assertFileContains('Dockerfile', 'RUN g++ -o myapp main.cpp'); + assertFileContains('Dockerfile', 'CMD ["./myapp"]'); + }); + }); + suite("'Other'", () => { testInEmptyFolder("with package.json", async () => { await writeFile('', 'package.json', JSON.stringify({ diff --git a/utils/platform.ts b/utils/platform.ts index 9f874db3cb..5315ed8e27 100644 --- a/utils/platform.ts +++ b/utils/platform.ts @@ -12,4 +12,5 @@ export type Platform = 'Node.js' | 'Python' | 'Ruby' | + 'C++' | 'Other';