Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding C++ template #644

Merged
merged 12 commits into from
Dec 5, 2018
13 changes: 13 additions & 0 deletions configureWorkspace/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import { IAzureQuickPickItem, IAzureUserInput } from 'vscode-azureextensionui';
import { ext } from "../extensionVariables";
import { Platform, PlatformOS } from '../utils/platform';

export type OS = 'Windows' | 'Linux';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these and instead use the ones from platform.ts (where they were moved to)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done. The PlatformOS type from platform.ts was already being used so that shouldn't have still been there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to the extra Platform enum as well... Thx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh! Fixed.

export type Platform =
'Go' |
'Java' |
'.NET Core Console' |
'ASP.NET Core' |
'Node.js' |
'Python' |
'Ruby' |
'C++' |
'Other';

/**
* Prompts for a port number
* @throws `UserCancelledError` if the user cancels.
Expand Down Expand Up @@ -49,6 +61,7 @@ export async function quickPickPlatform(): Promise<Platform> {
'Node.js',
'Python',
'Ruby',
'C++',
'Other'
];

Expand Down
2 changes: 2 additions & 0 deletions configureWorkspace/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { extractRegExGroups } from '../helpers/extractRegExGroups';
import { Platform, PlatformOS } from '../utils/platform';
import { promptForPort, quickPickOS, quickPickPlatform } from './config-utils';
import { configureAspDotNetCore, configureDotNetCoreConsole } from './configure_dotnetcore';
import { configureCpp } from './configure_cpp';
import { configureGo } from './configure_go';
import { configureJava } from './configure_java';
import { configureNode } from './configure_node';
Expand Down Expand Up @@ -67,6 +68,7 @@ export function getExposeStatements(port: string): string {

const generatorsByPlatform = new Map<Platform, IPlatformGeneratorInfo>();
generatorsByPlatform.set('ASP.NET Core', configureAspDotNetCore);
generatorsByPlatform.set('C++', configureCpp);
generatorsByPlatform.set('Go', configureGo);
generatorsByPlatform.set('Java', configureJava);
generatorsByPlatform.set('.NET Core Console', configureDotNetCoreConsole);
Expand Down
38 changes: 38 additions & 0 deletions configureWorkspace/configure_cpp.ts
Original file line number Diff line number Diff line change
@@ -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<PackageInfo>): 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}
`;
}
21 changes: 21 additions & 0 deletions test/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,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({
Expand Down
1 change: 1 addition & 0 deletions utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export type Platform =
'Node.js' |
'Python' |
'Ruby' |
'C++' |
'Other';