From 96ae068528f2e03ac49b45dd603fb3bc2e5c21d3 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Tue, 10 Mar 2020 16:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5php=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/entity/system.go | 1 + backend/scripts/install-dotnet.sh | 19 ++ backend/scripts/install-php.sh | 13 ++ backend/scripts/install.sh | 8 + backend/services/rpc/install_lang.go | 44 +---- backend/utils/system.go | 16 ++ devops/develop/crawlab-master.yaml | 4 +- devops/develop/crawlab-worker.yaml | 4 +- .../Node/NodeInstallationMatrix.vue | 178 ++++++++++-------- 9 files changed, 167 insertions(+), 120 deletions(-) create mode 100755 backend/scripts/install-dotnet.sh create mode 100755 backend/scripts/install-php.sh diff --git a/backend/entity/system.go b/backend/entity/system.go index 8e174b0e..2738b55a 100644 --- a/backend/entity/system.go +++ b/backend/entity/system.go @@ -20,6 +20,7 @@ type Lang struct { ExecutablePaths []string `json:"executable_paths"` DepExecutablePath string `json:"dep_executable_path"` LockPath string `json:"lock_path"` + InstallScript string `json:"install_script"` InstallStatus string `json:"install_status"` } diff --git a/backend/scripts/install-dotnet.sh b/backend/scripts/install-dotnet.sh new file mode 100755 index 00000000..ad2b124e --- /dev/null +++ b/backend/scripts/install-dotnet.sh @@ -0,0 +1,19 @@ +# lock global +touch /tmp/install.lock + +# lock +touch /tmp/install-dotnet.lock + +apt-get install curl +curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg +mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg +sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-artful-prod artful main" > /etc/apt/sources.list.d/dotnetdev.list' +apt-get install apt-transport-https +apt-get update +apt-get install dotnet-sdk-2.1 + +# unlock global +rm /tmp/install.lock + +# unlock +rm /tmp/install-dotnet.lock diff --git a/backend/scripts/install-php.sh b/backend/scripts/install-php.sh new file mode 100755 index 00000000..04a01a66 --- /dev/null +++ b/backend/scripts/install-php.sh @@ -0,0 +1,13 @@ +# lock global +touch /tmp/install.lock + +# lock +touch /tmp/install-php.lock + +apt-get install php + +# unlock global +rm /tmp/install.lock + +# unlock +rm /tmp/install-php.lock diff --git a/backend/scripts/install.sh b/backend/scripts/install.sh index cf6bf243..fe89d1b2 100644 --- a/backend/scripts/install.sh +++ b/backend/scripts/install.sh @@ -15,3 +15,11 @@ then /bin/sh /app/backend/scripts/install-java.sh echo "installed java" fi + +# install dotnet +if [ "${CRAWLAB_SERVER_LANG_DOTNET}" = "Y" ]; +then + echo "installing dotnet" + /bin/sh /app/backend/scripts/install-dotnet.sh + echo "installed dotnet" +fi diff --git a/backend/services/rpc/install_lang.go b/backend/services/rpc/install_lang.go index 5408cef1..39f5a6d8 100644 --- a/backend/services/rpc/install_lang.go +++ b/backend/services/rpc/install_lang.go @@ -39,45 +39,19 @@ func (s *InstallLangService) ClientHandle() (o interface{}, err error) { return } -// 本地安装Node.js -func InstallNodejsLocalLang() (string, error) { - cmd := exec.Command("/bin/sh", path.Join("scripts", "install-nodejs.sh")) - output, err := cmd.Output() - if err != nil { - log.Error(err.Error()) - debug.PrintStack() - return string(output), err - } - - // TODO: check if Node.js is installed successfully - - return string(output), nil -} - -// 本地安装Java -func InstallJavaLocalLang() (string, error) { - cmd := exec.Command("/bin/sh", path.Join("scripts", "install-java.sh")) - output, err := cmd.Output() - if err != nil { - log.Error(err.Error()) - debug.PrintStack() - return string(output), err - } - - // TODO: check if Java is installed successfully - - return string(output), nil -} - // 本地安装语言 func InstallLangLocal(lang string) (o string, err error) { - if lang == constants.Nodejs { - o, err = InstallNodejsLocalLang() - } else if lang == constants.Java { - o, err = InstallNodejsLocalLang() - } else { + l := utils.GetLangFromLangNamePlain(lang) + if l.Name == "" || l.InstallScript == "" { return "", errors.New(fmt.Sprintf("%s is not implemented", lang)) } + cmd := exec.Command("/bin/sh", path.Join("scripts", l.InstallScript)) + output, err := cmd.Output() + if err != nil { + log.Error(err.Error()) + debug.PrintStack() + return string(output), err + } return } diff --git a/backend/utils/system.go b/backend/utils/system.go index 8ff5eb64..f8f917be 100644 --- a/backend/utils/system.go +++ b/backend/utils/system.go @@ -17,12 +17,28 @@ func GetLangList() []entity.Lang { ExecutablePaths: []string{"/usr/bin/node", "/usr/local/bin/node"}, DepExecutablePath: "/usr/local/bin/npm", LockPath: "/tmp/install-nodejs.lock", + InstallScript: "install-nodejs.sh", }, { Name: "Java", ExecutableName: "java", ExecutablePaths: []string{"/usr/bin/java", "/usr/local/bin/java"}, LockPath: "/tmp/install-java.lock", + InstallScript: "install-java.sh", + }, + { + Name: ".Net Core", + ExecutableName: "dotnet", + ExecutablePaths: []string{"/usr/bin/dotnet", "/usr/local/bin/dotnet"}, + LockPath: "/tmp/install-dotnet.lock", + InstallScript: "install-dotnet.sh", + }, + { + Name: "PHP", + ExecutableName: "php", + ExecutablePaths: []string{"/usr/bin/php", "/usr/local/bin/php"}, + LockPath: "/tmp/install-php.lock", + InstallScript: "install-php.sh", }, } return list diff --git a/devops/develop/crawlab-master.yaml b/devops/develop/crawlab-master.yaml index 4d55118f..b2ea07b2 100644 --- a/devops/develop/crawlab-master.yaml +++ b/devops/develop/crawlab-master.yaml @@ -43,7 +43,9 @@ spec: - name: CRAWLAB_SERVER_LANG_NODE value: "N" - name: CRAWLAB_SERVER_LANG_JAVA - value: "Y" + value: "N" + - name: CRAWLAB_SERVER_LANG_DOTNET + value: "N" - name: CRAWLAB_SERVER_REGISTER_TYPE value: "hostname" ports: diff --git a/devops/develop/crawlab-worker.yaml b/devops/develop/crawlab-worker.yaml index 524e0efe..037aa8fc 100644 --- a/devops/develop/crawlab-worker.yaml +++ b/devops/develop/crawlab-worker.yaml @@ -28,6 +28,8 @@ spec: - name: CRAWLAB_SERVER_LANG_NODE value: "N" - name: CRAWLAB_SERVER_LANG_JAVA - value: "Y" + value: "N" + - name: CRAWLAB_SERVER_LANG_DOTNET + value: "N" - name: CRAWLAB_SERVER_REGISTER_TYPE value: "hostname" diff --git a/frontend/src/components/Node/NodeInstallationMatrix.vue b/frontend/src/components/Node/NodeInstallationMatrix.vue index 2aef8339..75c61779 100644 --- a/frontend/src/components/Node/NodeInstallationMatrix.vue +++ b/frontend/src/components/Node/NodeInstallationMatrix.vue @@ -1,87 +1,96 @@ @@ -101,10 +110,13 @@ export default { langs: [ { label: 'Python', name: 'python' }, { label: 'Node.js', name: 'node' }, - { label: 'Java', name: 'java' } + { label: 'Java', name: 'java' }, + { label: '.Net Core', name: 'dotnet' }, + { label: 'PHP', name: 'php' } ], dataDict: {}, - handle: undefined + handle: undefined, + activeTabName: 'lang' } }, computed: {