Skip to content

Commit

Permalink
Adding C++ template (#644)
Browse files Browse the repository at this point in the history
* Initial GCC container for Cpp, need to surpress request for port

* Adding test

* Initial GCC container for Cpp, need to surpress request for port

* Adding test

* Missed updated platform.ts

* Changing port to undefined so it doesn't prompt

* Changed name to C++, fixed tests

* removing unused type

Unneeded type, already using PlatformOS from platform.ts

* Removing another duplication...

* Fixing lint error
  • Loading branch information
robotdad authored and StephenWeatherford committed Dec 5, 2018
1 parent bf20b5a commit df5dcc5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions configureWorkspace/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 @@ -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';
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 @@ -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({
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';

0 comments on commit df5dcc5

Please sign in to comment.