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

Fix 'Other' platform generation (hotfix 0.3.1) #509

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.3.1 - 25 September 2018

### Fixed

* Error while generating Dockerfile for 'other' [#504](https://github.com/Microsoft/vscode-docker/issues/504)

## 0.3.0 - 21 September 2018

### Added
Expand Down
2 changes: 2 additions & 0 deletions configureWorkspace/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { configureAspDotNetCore, configureDotNetCoreConsole } from './configure_
import { configureGo } from './configure_go';
import { configureJava } from './configure_java';
import { configureNode } from './configure_node';
import { configureOther } from './configure_other';
import { configurePython } from './configure_python';
import { configureRuby } from './configure_ruby';

Expand Down Expand Up @@ -65,6 +66,7 @@ generatorsByPlatform.set('.NET Core Console', configureDotNetCoreConsole);
generatorsByPlatform.set('Node.js', configureNode);
generatorsByPlatform.set('Python', configurePython);
generatorsByPlatform.set('Ruby', configureRuby);
generatorsByPlatform.set('Other', configureOther);

function genDockerFile(serviceNameAndRelativePath: string, platform: Platform, os: OS | undefined, port: string | undefined, { cmd, author, version, artifactName }: Partial<PackageInfo>): string {
let generators = generatorsByPlatform.get(platform);
Expand Down
47 changes: 47 additions & 0 deletions configureWorkspace/configure_other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { PackageInfo } from './configure';

export let configureOther = {
genDockerFile,
genDockerCompose,
genDockerComposeDebug,
defaultPort: '3000'
};

function genDockerFile(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { cmd, author, version, artifactName }: Partial<PackageInfo>): string {
return `FROM docker/whalesay:latest
LABEL Name=${serviceNameAndRelativePath} Version=${version}
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
`;
}

function genDockerCompose(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string): string {
return `version: '2.1'

services:
${serviceNameAndRelativePath}:
image: ${serviceNameAndRelativePath}
build: .
ports:
- ${port}:${port}
`;
}

function genDockerComposeDebug(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { fullCommand: cmd }: Partial<PackageInfo>): string {
return `version: '2.1'

services:
${serviceNameAndRelativePath}:
image: ${serviceNameAndRelativePath}
build:
context: .
dockerfile: Dockerfile
ports:
- ${port}:${port}
`;
}
5 changes: 3 additions & 2 deletions configureWorkspace/configure_python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ services:
image: ${serviceNameAndRelativePath}
build: .
ports:
- ${port}:${port}`;
- ${port}:${port}
`;
}

function genDockerComposeDebug(serviceNameAndRelativePath: string, platform: string, os: string | undefined, port: string, { fullCommand: cmd }: Partial<PackageInfo>): string {
Expand All @@ -64,6 +65,6 @@ services:
context: .
dockerfile: Dockerfile
ports:
- ${port}:${port}
- ${port}:${port}
`;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vscode-docker",
"version": "0.3.0",
"version": "0.3.1",
"publisher": "PeterJausovec",
"displayName": "Docker",
"description": "Adds syntax highlighting, commands, hover tips, and linting for Dockerfile and docker-compose files.",
Expand Down
65 changes: 64 additions & 1 deletion test/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ as the easier to read:
sub-indented text
`;
*/

function removeIndentation(text: string): string {
while (text[0] === '\r' || text[0] === '\n') {
text = text.substr(1);
Expand Down Expand Up @@ -1090,6 +1089,70 @@ suite("Configure (Add Docker files to Workspace)", function (this: Suite): void
});
});

suite("'Other'", () => {
testInEmptyFolder("with package.json", async () => {
await writeFile('', 'package.json', JSON.stringify({
"name": "myexpressapp",
"version": "1.2.3",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"jade": "~1.11.0",
"morgan": "~1.9.0"
}
}))
await testConfigureDocker(
'Other',
{
configurePlatform: 'Other',
configureOs: undefined,
packageFileType: undefined,
packageFileSubfolderDepth: undefined
},
[undefined /*port*/],
['Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore', 'package.json']);

let dockerfileContents = await readFile('Dockerfile');
let composeContents = await readFile('docker-compose.yml');
let debugComposeContents = await readFile('docker-compose.debug.yml');

assert.strictEqual(dockerfileContents, removeIndentation(`
FROM docker/whalesay:latest
LABEL Name=testoutput Version=1.2.3
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
`));
assert.strictEqual(composeContents, removeIndentation(`
version: '2.1'

services:
testoutput:
image: testoutput
build: .
ports:
- 3000:3000
`));
assert.strictEqual(debugComposeContents, removeIndentation(`
version: '2.1'

services:
testoutput:
image: testoutput
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
`));
});
});

// API (vscode-docker.api.configure)

suite("API", () => {
Expand Down