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

Docker run options. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"default": "rchain/rnode",
"description": "Docker image (version) used by Rholang Language Server."
},
"rholang.dockerRunOptions": {
"type": "string",
"default": "",
"description": "Docker run options."
},
"rholang.showAllOutput": {
"type": "boolean",
"default": false,
Expand Down
31 changes: 23 additions & 8 deletions src/rholang-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Settings = {
rnode : string
enableDocker : boolean
rnodeDockerImage : string
dockerRunOptions : string
showAllOutput : boolean
}

Expand All @@ -110,7 +111,11 @@ export class RholangServer {
let rhovm : ChildProcess

const stopRNodeProcess = useDocker => {
log(`Stopping RChain Node.`)

if (rhovm) {
this.log(`Process PID: ${rhovm.pid}`)

try {
if (useDocker) spawn('docker', ['stop', rhoTmpName], { detached: true, stdio: 'ignore' })
else process.kill(rhovm.pid)
Expand Down Expand Up @@ -169,12 +174,16 @@ export class RholangServer {
const diffs = (newS: Settings, oldS: Settings) => [
[true , newS.enableLanguageServer, oldS.enableLanguageServer],
[true , newS.enableDocker , oldS.enableDocker],
[true , newS.dockerRunOptions , oldS.dockerRunOptions],
arthurgreef marked this conversation as resolved.
Show resolved Hide resolved
[!newS.enableDocker, newS.rnode , oldS.rnode] ,
[newS.enableDocker , newS.rnodeDockerImage , oldS.rnodeDockerImage],
]
if(!oldSettings || diffs(this._settings, oldSettings).find(([s, x, y]) => s && x !== y)) {
// If settings change
oldSettings && stopRNodeProcess(oldSettings.enableDocker)
oldSettings &&
(oldSettings.enableDocker || oldSettings.dockerRunOptions) &&
stopRNodeProcess(oldSettings.enableDocker)

const startNode = () => {
if (this._settings.enableLanguageServer) {
log('Rholang Language Server (enabled)')
Expand Down Expand Up @@ -225,18 +234,24 @@ export class RholangServer {
'-p', `${port0}`, '--http-port', `${port3}`, '--kademlia-port', `${port4}`,
]

// Start RNode (standalone) process used by the server
let vm: ChildProcess
if (this.useDocker()) {
const dockerCmd = runOptions => {
const volume = `${workingFolder}:/vscode`
vm = spawn('docker', [
let cmd = [
arthurgreef marked this conversation as resolved.
Show resolved Hide resolved
// Docker run
'run', '-i', '--rm', '--name', rhoTmpName, '-v', volume,
'-p', `${port0}:${port0}`, '-p', `${port1}:${port1}`, '-p', `${port2}:${port2}`,
'-p', `${port3}:${port3}`, '-p', `${port4}:${port4}`,
// RNode run
this._settings.rnodeDockerImage, ...runCmd('/vscode/.rnode'),
])
]
runOptions && runOptions.length != 0 && cmd.push(`${runOptions}`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky part. spawn accepts arguments separated in a list and not in one string. But just to split by space can also be problematic if space is part of the value.

I wrote helper function to parse arguments by - to an object.
https://github.com/tgrospic/rnode-grpc-js/blob/a6ae689/src/cli/args.js#L30

This is how it's used. For now object can be transformed to a list and just appended. Later we can add merging of objects.
https://github.com/tgrospic/rnode-grpc-js/blob/a6ae6894/src/cli/index.js#L60

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can use your function. I have an option like --network=host but your function strips the dashes. I need an array like ['--network', 'host'] not ['network','host']. Am I understanding that you want a modified version of your version to return lists of string arrays with the dashes intact?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. With equal sign will not work. And also multiple parameters like -p 123 -p 456 are generated as a list for this key { p: [123, 456] }.
Maybe there already exists some nice lib for what we need here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elsewhere in vs-code config, JSON is used to represent structured args.

cmd.push(this._settings.rnodeDockerImage)
cmd.push(...runCmd('/vscode/.rnode'))
return cmd
}

// Start RNode (standalone) process used by the server
let vm: ChildProcess
if (this.useDocker()) {
vm = spawn('docker', dockerCmd(this._settings.dockerRunOptions))
} else {
// RNode run
vm = spawn(this._settings.rnode, runCmd(dataDir))
Expand Down