diff --git a/CHANGELOG.md b/CHANGELOG.md index a97d8faa6f..ac2408cf37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/configureWorkspace/configure.ts b/configureWorkspace/configure.ts index 4958a94f21..87c41d5d60 100644 --- a/configureWorkspace/configure.ts +++ b/configureWorkspace/configure.ts @@ -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'; @@ -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): string { let generators = generatorsByPlatform.get(platform); diff --git a/configureWorkspace/configure_other.ts b/configureWorkspace/configure_other.ts new file mode 100644 index 0000000000..460c9db7a2 --- /dev/null +++ b/configureWorkspace/configure_other.ts @@ -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): 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): string { + return `version: '2.1' + +services: + ${serviceNameAndRelativePath}: + image: ${serviceNameAndRelativePath} + build: + context: . + dockerfile: Dockerfile + ports: + - ${port}:${port} +`; +} diff --git a/configureWorkspace/configure_python.ts b/configureWorkspace/configure_python.ts index 6e4df2d5ed..7a06e75eb7 100644 --- a/configureWorkspace/configure_python.ts +++ b/configureWorkspace/configure_python.ts @@ -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): string { @@ -64,6 +65,6 @@ services: context: . dockerfile: Dockerfile ports: - - ${port}:${port} + - ${port}:${port} `; } diff --git a/package.json b/package.json index 16e36630af..849e4385b8 100644 --- a/package.json +++ b/package.json @@ -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.", diff --git a/test/configure.test.ts b/test/configure.test.ts index 7ba9d28033..01ac7bce59 100644 --- a/test/configure.test.ts +++ b/test/configure.test.ts @@ -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); @@ -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", () => {