-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a788b
commit 363eef7
Showing
11 changed files
with
341 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
"use babel"; | ||
// @flow | ||
|
||
import type { | ||
GeneratedPlanObject, | ||
PlanConfig, | ||
} from "../../PlanConfigurationFeature/Types/types"; | ||
import type { PackageTesterResult } from "../../../ProjectSystemEpic/PackageFeature/Types/types"; | ||
import type { Plugin } from "../../DevtoolLoadingFeature/Types/types"; | ||
import path from "path"; | ||
import yaml from "js-yaml"; | ||
import fs from "fs"; | ||
import moment from "moment"; | ||
|
||
const plugin: Plugin = { | ||
info: { | ||
name: "docker", | ||
dominantColor: "#339fee", | ||
iconUri: "atom://molecule/images/plugins/docker.svg", | ||
}, | ||
|
||
configSchema: { | ||
type: "object", | ||
schemas: { | ||
command: { | ||
type: "enum", | ||
label: "command", | ||
default: "start", | ||
enum: [ | ||
{ value: "build", description: "build" }, | ||
{ value: "up", description: "up" }, | ||
{ value: "push", description: "push" }, | ||
], | ||
}, | ||
serviceName: { | ||
type: "string", | ||
label: "service name", | ||
placeholder: "database,web... empty for all", | ||
default: "", | ||
}, | ||
bin: { | ||
type: "string", | ||
label: "binary path", | ||
placeholder: "docker-compose", | ||
default: "docker-compose", | ||
}, | ||
}, | ||
}, | ||
|
||
getStrategyForPlan(plan: PlanConfig) { | ||
if (plan.config.command === "up") { | ||
return { | ||
strategy: { | ||
type: "node", | ||
path: path.join(__dirname, "lsp"), | ||
cwd: path.dirname(plan.packageInfo.path), | ||
lsp: true, | ||
env: { | ||
COMPOSE_COMMAND: JSON.stringify({ | ||
bin: plan.config.bin, | ||
command: plan.config.command, | ||
service: plan.config.serviceName, | ||
configFile: plan.packageInfo.path, | ||
}), | ||
}, | ||
}, | ||
}; | ||
} else { | ||
const command = `${plan.config.bin} -f ${plan.packageInfo.path} ${ | ||
plan.config.command | ||
} ${plan.config.serviceName}`; | ||
return { | ||
strategy: { | ||
type: "terminal", | ||
cwd: path.dirname(plan.packageInfo.path), | ||
command: command, | ||
env: process.env, | ||
}, | ||
controller: { | ||
onData(data: string, taskAPI: TaskAPI, helperAPI: HelperAPI) {}, | ||
onError(err: any, taskAPI: TaskAPI, helperAPI: HelperAPI) { | ||
taskAPI.diagnostics.setForWorkspace({ | ||
uri: "docker-compose", | ||
diagnostics: [ | ||
{ | ||
range: { | ||
start: { line: -1, character: -1 }, | ||
end: { line: -1, character: -1 }, | ||
}, | ||
severity: helperAPI.severity.error, | ||
message: `Error: ${err.code | 1}`.toString(), | ||
date: moment().unix(), | ||
}, | ||
], | ||
}); | ||
}, | ||
}, | ||
}; | ||
} | ||
}, | ||
|
||
async isPackage(packagePath: string): PackageTesterResult { | ||
if (!packagePath.endsWith(".yaml")) { | ||
return false; | ||
} | ||
|
||
const rawData = await new Promise((resolve, reject) => { | ||
fs.readFile(packagePath, (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
const fileConfig = yaml.safeLoad(rawData); | ||
return "version" in fileConfig && "services" in fileConfig; | ||
}, | ||
|
||
async generatePlansForPackage( | ||
packagePath: string, | ||
): Promise<Array<GeneratedPlanObject>> { | ||
const rawData = await new Promise((resolve, reject) => { | ||
fs.readFile(packagePath, (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
const fileConfig = yaml.safeLoad(rawData); | ||
|
||
return Promise.resolve([ | ||
{ | ||
name: `up`, | ||
value: { | ||
command: "up", | ||
serviceName: "", | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
ownSource: true, | ||
}, | ||
{ | ||
name: `build`, | ||
value: { | ||
command: "build", | ||
serviceName: "", | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
}, | ||
{ | ||
name: `push`, | ||
value: { | ||
command: "push", | ||
serviceName: "", | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
}, | ||
...Object.keys(fileConfig.services || {}) | ||
.map(serviceName => [ | ||
{ | ||
name: `up ${serviceName}`, | ||
value: { | ||
command: "up", | ||
serviceName: serviceName, | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
ownSource: true, | ||
}, | ||
{ | ||
name: `${ | ||
fileConfig.services[serviceName].image ? "pull" : "build" | ||
} ${serviceName}`, | ||
value: { | ||
command: `${ | ||
fileConfig.services[serviceName].image ? "pull" : "build" | ||
}`, | ||
serviceName: serviceName, | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
}, | ||
{ | ||
name: `push ${serviceName}`, | ||
value: { | ||
command: "push", | ||
serviceName: serviceName, | ||
bin: "docker-compose", | ||
}, | ||
autorun: false, | ||
}, | ||
]) | ||
.reduce((red, arr) => [...red, ...arr], []), | ||
]); | ||
}, | ||
}; | ||
|
||
export default plugin; |
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,59 @@ | ||
/* eslint-disable */ | ||
const { | ||
createMessageConnection, | ||
StreamMessageReader, | ||
StreamMessageWriter, | ||
} = require("vscode-jsonrpc"); | ||
|
||
const { spawn, exec } = require("child_process"); | ||
const process = require("process"); | ||
const StreamSplitter = require("stream-splitter"); | ||
const stripAnsi = require("strip-ansi"); | ||
|
||
const connection = createMessageConnection( | ||
new StreamMessageReader(process.stdin), | ||
new StreamMessageWriter(process.stdout), | ||
); | ||
|
||
connection.onRequest("initialize", () => { | ||
return new Promise((resolve, reject) => { | ||
const { bin, command, service, configFile } = JSON.parse( | ||
process.env.COMPOSE_COMMAND, | ||
); | ||
|
||
const dockerProcess = spawn(bin, ["-f", configFile, command, service], { | ||
stderr: "pipe", | ||
stdout: "pipe", | ||
}); | ||
dockerProcess.on("error", err => | ||
connection.sendNotification("window/logMessage", { | ||
type: 3, | ||
message: `Error running Docker: ${err}`, | ||
}), | ||
); | ||
|
||
const lines = dockerProcess.stdout.pipe(StreamSplitter("\n")); | ||
lines.on("token", line => | ||
connection.sendNotification("window/logMessage", { | ||
type: 1, | ||
message: stripAnsi(line.toString()), | ||
}), | ||
); | ||
|
||
connection.onRequest("shutdown", () => { | ||
return new Promise(resolve => { | ||
dockerProcess.kill(); | ||
exec( | ||
`${bin} -f ${configFile} stop ${service}`, | ||
{}, | ||
(err, stdout, stderr) => { | ||
resolve(); | ||
}, | ||
); | ||
}); | ||
}); | ||
resolve(); | ||
}); | ||
}); | ||
|
||
connection.listen(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
version: "3" | ||
services: | ||
redis: | ||
image: redis:alpine | ||
ports: | ||
- "6379" | ||
networks: | ||
- frontend | ||
|
||
db: | ||
image: postgres:9.4 | ||
networks: | ||
- backend | ||
|
||
vote: | ||
image: dockersamples/examplevotingapp_vote:before | ||
ports: | ||
- "5000:80" | ||
networks: | ||
- frontend | ||
depends_on: | ||
- redis | ||
|
||
result: | ||
image: dockersamples/examplevotingapp_result:before | ||
ports: | ||
- "5001:80" | ||
networks: | ||
- backend | ||
depends_on: | ||
- db | ||
|
||
worker: | ||
image: dockersamples/examplevotingapp_worker | ||
networks: | ||
- frontend | ||
- backend | ||
|
||
visualizer: | ||
image: dockersamples/visualizer:stable | ||
ports: | ||
- "8080:8080" | ||
stop_grace_period: 1m30s | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock" | ||
|
||
networks: | ||
frontend: | ||
backend: |
Oops, something went wrong.