This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from Microsoft/feature/composefileCreation
Creating a simple docker-compose.yml file as part of the experience.
- Loading branch information
Showing
12 changed files
with
330 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
'use strict' | ||
|
||
/** | ||
* Helper for creating docker-compose file contents. | ||
* @constructor | ||
*/ | ||
var DockerComposeHelper = function() { | ||
this._commandMap = []; | ||
} | ||
|
||
DockerComposeHelper.prototype.addAppName = function(name) { | ||
this._addCommand('', name); | ||
} | ||
|
||
DockerComposeHelper.prototype.addDockerfile = function(fileName) { | ||
this._addCommand('dockerfile', fileName); | ||
} | ||
|
||
DockerComposeHelper.prototype.addBuildContext = function(context) { | ||
this._addCommand('build', context); | ||
} | ||
|
||
DockerComposeHelper.prototype.addPort = function(ports) { | ||
this._addCommand('ports', ports); | ||
} | ||
|
||
DockerComposeHelper.prototype.addVolume = function(volume) { | ||
this._addCommand('volumes', volume); | ||
} | ||
|
||
/** | ||
* Iterates through the array of commands and creates the contents. | ||
*/ | ||
DockerComposeHelper.prototype.createContents = function() { | ||
var contents = ''; | ||
|
||
for (var i = 0; i < this._commandMap.length; i ++) { | ||
var item = this._commandMap[i]; | ||
|
||
switch (item.commandName) { | ||
case '': { | ||
// [VALUE]: | ||
contents += item.value + ':\n'; | ||
break; | ||
} | ||
|
||
case 'ports': { | ||
if (contents.indexOf(item.commandName) === -1) { | ||
// Add 'ports:' first. | ||
contents += ' ' + item.commandName + ':\n'; | ||
} | ||
|
||
contents += ' - "' + item.value + '"\n'; | ||
break; | ||
} | ||
case 'volumes': { | ||
if (contents.indexOf(item.commandName) === -1) { | ||
// Add 'volumes:' first. | ||
contents += ' ' + item.commandName + ':\n'; | ||
} | ||
|
||
contents += ' - ' + item.value + '\n'; | ||
break; | ||
} | ||
|
||
default: { | ||
// [COMMANDNAME]: [VALUE] | ||
contents += ' ' + item.commandName + ': ' + item.value + '\n'; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return contents; | ||
} | ||
|
||
/** | ||
* Adds the command name and value to the list of commands. | ||
*/ | ||
DockerComposeHelper.prototype._addCommand = function(commandName, value) { | ||
this._commandMap.push({ commandName: commandName, value: value }); | ||
} | ||
|
||
module.exports = DockerComposeHelper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.