fix of run docker commandline

master
xieguigang 4 years ago
parent 8a8149a55e
commit c77fbeee31

@ -136,14 +136,24 @@ Public Module Commands
' Run 'docker COMMAND --help' for more information on a command.
ReadOnly powershell As New PowerShell
Friend ReadOnly shell As Func(Of String, String, String)
Friend ReadOnly logs As New List(Of String)
Public Iterator Function CommandHistory() As IEnumerable(Of String)
For Each line As String In powershell.logs
For Each line As String In logs
Yield line
Next
End Function
Sub New()
shell = Function(app, args) As String
Dim lines As New List(Of String)
Call logs.Add($"{app} {args}")
Call CommandLine.ExecSub(app, args, onReadLine:=AddressOf lines.Add)
Return lines.JoinBy(vbLf)
End Function
End Sub
''' <summary>
''' Search the Docker Hub for images
''' </summary>
@ -152,7 +162,7 @@ Public Module Commands
'''
<ExportAPI("search")>
Public Function Search(term As String) As IEnumerable(Of Search)
Return powershell($"docker search {term}") _
Return shell("docker", $"search {term}") _
.ParseTable(Function(tokens)
Return New Search With {
.NAME = Image.ParseEntry(tokens(0)),
@ -171,7 +181,7 @@ Public Module Commands
'''
<ExportAPI("ps")>
Public Function PS() As IEnumerable(Of Container)
Return powershell("docker ps") _
Return shell("docker", "ps") _
.ParseTable(Function(tokens)
Return New Container With {
.CONTAINER_ID = tokens(0).Trim,
@ -193,7 +203,7 @@ Public Module Commands
<ExportAPI("stop")>
Public Sub [Stop](ParamArray containers As String())
For Each id As String In containers
Call powershell.RunScript($"docker stop {id}")
Call shell("docker", $"stop {id}")
Next
End Sub
@ -217,11 +227,7 @@ Public Module Commands
.Mount(mounts) _
.CreateDockerCommand(command, workdir, portForward)
#If UNIX = 0 Then
Return CommandLine.Call("docker", cli.GetTagValue.Value)
#Else
Return powershell(cli)
#End If
Return shell("docker", cli)
End Function
''' <summary>
@ -237,7 +243,7 @@ Public Module Commands
Do While (stdout = CommandLine.Call("docker", $"rmi {imageId}")).Contains("image is being used by stopped container")
containerId = Strings.Split(Strings.Trim(stdout)).Last
Call CommandLine.Call("docker", $"rm {containerId}")
Call shell("docker", $"rm {containerId}")
Call Console.WriteLine($"remove container {containerId}")
Loop

@ -107,16 +107,13 @@
<Compile Remove="test\**" />
<EmbeddedResource Remove="test\**" />
<None Remove="test\**" />
<Compile Remove="PowerShell.vb" />
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="6.2.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\R-sharp\R#\Rsharp-netcore5.vbproj" />
<ProjectReference Include="..\..\..\sciBASIC#\Microsoft.VisualBasic.Core\src\Core.vbproj" />

@ -1,55 +1,56 @@
#Region "Microsoft.VisualBasic::2bc4c7a574db43f6df5da77e267ee513, CloudKit\Docker\Environment.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' /********************************************************************************/
' Summaries:
' Summaries:
' Class Environment
'
' Properties: [Shared], container
'
' Constructor: (+1 Overloads) Sub New
' Function: CreateDockerCommand, (+2 Overloads) Mount
'
' Class DockerAppDriver
'
' Constructor: (+1 Overloads) Sub New
' Function: Shell
'
' /********************************************************************************/
' Class Environment
'
' Properties: [Shared], container
'
' Constructor: (+1 Overloads) Sub New
' Function: CreateDockerCommand, (+2 Overloads) Mount
'
' Class DockerAppDriver
'
' Constructor: (+1 Overloads) Sub New
' Function: Shell
'
' /********************************************************************************/
#End Region
Imports System.Runtime.CompilerServices
Imports System.Text
Imports Darwinism.Docker.Arguments
Imports Microsoft.VisualBasic.CommandLine
Imports Microsoft.VisualBasic.Linq
''' <summary>
@ -249,7 +250,7 @@ Public Class Environment
Call options.AppendLine($"-p {portForward}")
End If
Return $"docker run {options} {container} {command}"
Return $"run {options} {container} {command}"
End Function
End Class
@ -259,7 +260,6 @@ End Class
Public Class DockerAppDriver
ReadOnly docker As Environment
ReadOnly powershell As New PowerShell
ReadOnly appHome$
ReadOnly appName$
@ -278,6 +278,6 @@ Public Class DockerAppDriver
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Function Shell(args$, Optional workdir$ = Nothing) As String
Return powershell(docker.CreateDockerCommand($"{appHome}/{appName} {args}", workdir:=workdir))
Return Commands.shell("docker", docker.CreateDockerCommand($"{appHome}/{appName} {args}", workdir:=workdir))
End Function
End Class

@ -113,10 +113,6 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="6.2.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\R-sharp\R#\Rsharp-netcore5.vbproj" />
<ProjectReference Include="..\..\..\sciBASIC#\Data_science\Graph\graph-netcore5.vbproj" />

Loading…
Cancel
Save