diff --git a/backend/entity/system.go b/backend/entity/system.go index ac3e9dec..4c15cc54 100644 --- a/backend/entity/system.go +++ b/backend/entity/system.go @@ -15,11 +15,11 @@ type Executable struct { } type Lang struct { - Name string `json:"name"` - ExecutableName string `json:"executable_name"` - ExecutablePath string `json:"executable_path"` - DepExecutablePath string `json:"dep_executable_path"` - Installed bool `json:"installed"` + Name string `json:"name"` + ExecutableName string `json:"executable_name"` + ExecutablePaths []string `json:"executable_paths"` + DepExecutablePath string `json:"dep_executable_path"` + Installed bool `json:"installed"` } type Dependency struct { diff --git a/backend/scripts/install-java.sh b/backend/scripts/install-java.sh new file mode 100644 index 00000000..e98de224 --- /dev/null +++ b/backend/scripts/install-java.sh @@ -0,0 +1,11 @@ +#!/bin/env bash + +# lock +touch /tmp/install-java.lock + +# install java +apt-get install -y default-jdk +ln -s /usr/bin/java /usr/local/bin/java + +# unlock +rm /tmp/install-java.lock diff --git a/backend/scripts/install-nodejs.sh b/backend/scripts/install-nodejs.sh index 376a2a3f..eada900a 100644 --- a/backend/scripts/install-nodejs.sh +++ b/backend/scripts/install-nodejs.sh @@ -1,5 +1,8 @@ #!/bin/env bash +# lock +touch /tmp/install-nodejs.lock + # install nvm BASE_DIR=`dirname $0` /bin/bash ${BASE_DIR}/install-nvm.sh @@ -33,3 +36,6 @@ apt-get update && apt-get install -y --no-install-recommends gconf-service libas PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors npm config set puppeteer_download_host=https://npm.taobao.org/mirrors npm install puppeteer-chromium-resolver crawlab-sdk -g --unsafe-perm=true --registry=https://registry.npm.taobao.org + +# unlock +rm /tmp/install-nodejs.lock diff --git a/backend/services/system.go b/backend/services/system.go index 6181afee..b2884378 100644 --- a/backend/services/system.go +++ b/backend/services/system.go @@ -65,9 +65,9 @@ func GetSystemInfo(nodeId string) (sysInfo entity.SystemInfo, err error) { // 获取语言列表 func GetLangList(nodeId string) []entity.Lang { list := []entity.Lang{ - {Name: "Python", ExecutableName: "python", ExecutablePath: "/usr/local/bin/python", DepExecutablePath: "/usr/local/bin/pip"}, - {Name: "Node.js", ExecutableName: "node", ExecutablePath: "/usr/local/bin/node", DepExecutablePath: "/usr/local/bin/npm"}, - //{Name: "Java", ExecutableName: "java", ExecutablePath: "/usr/local/bin/java"}, + {Name: "Python", ExecutableName: "python", ExecutablePaths: []string{"/usr/bin/python", "/usr/local/bin/python"}, DepExecutablePath: "/usr/local/bin/pip"}, + {Name: "Node.js", ExecutableName: "node", ExecutablePaths: []string{"/usr/bin/node", "/usr/local/bin/node"}, DepExecutablePath: "/usr/local/bin/npm"}, + {Name: "Java", ExecutableName: "java", ExecutablePaths: []string{"/usr/bin/java", "/usr/local/bin/java"}}, } for i, lang := range list { list[i].Installed = IsInstalledLang(nodeId, lang) @@ -93,8 +93,10 @@ func IsInstalledLang(nodeId string, lang entity.Lang) bool { return false } for _, exec := range sysInfo.Executables { - if exec.Path == lang.ExecutablePath { - return true + for _, path := range lang.ExecutablePaths { + if exec.Path == path { + return true + } } } return false diff --git a/docker-compose.yml b/docker-compose.yml index affdf7bb..26cbb989 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,7 @@ services: # CRAWLAB_SERVER_REGISTER_IP: "127.0.0.1" # node register ip 节点注册IP. 节点唯一识别号,只有当 CRAWLAB_SERVER_REGISTER_TYPE 为 "ip" 时才生效 # CRAWLAB_TASK_WORKERS: 4 # number of task executors 任务执行器个数(并行执行任务数) # CRAWLAB_SERVER_LANG_NODE: "Y" # whether to pre-install Node.js 预安装 Node.js 语言环境 + # CRAWLAB_SERVER_LANG_JAVA: "Y" # whether to pre-install Java 预安装 Java 语言环境 # CRAWLAB_SETTING_ALLOWREGISTER: "N" # whether to allow user registration 是否允许用户注册 # CRAWLAB_SETTING_ENABLETUTORIAL: "N" # whether to enable tutorial 是否启用教程 # CRAWLAB_NOTIFICATION_MAIL_SERVER: smtp.exmaple.com # STMP server address STMP 服务器地址 diff --git a/docker_init.sh b/docker_init.sh index 4baee046..9c51fa83 100755 --- a/docker_init.sh +++ b/docker_init.sh @@ -26,7 +26,14 @@ service nginx start if [ "${CRAWLAB_SERVER_LANG_NODE}" = "Y" ]; then echo "installing node.js" - /bin/sh /app/backend/scripts/install-nodejs.sh + /bin/sh /app/backend/scripts/install-nodejs.sh & +fi + +# install languages: Java +if [ "${CRAWLAB_SERVER_LANG_JAVA}" = "Y" ]; +then + echo "installing java" + /bin/sh /app/backend/scripts/install-java.sh & fi # generate ssh diff --git a/frontend/src/components/Node/NodeInstallation.vue b/frontend/src/components/Node/NodeInstallation.vue index 2d466ab7..68eb14c7 100644 --- a/frontend/src/components/Node/NodeInstallation.vue +++ b/frontend/src/components/Node/NodeInstallation.vue @@ -152,6 +152,7 @@ export default { methods: { async getDepList () { this.loading = true + this.depList = [] const res = await this.$request.get(`/nodes/${this.nodeForm._id}/deps`, { lang: this.activeLang.executable_name, dep_name: this.depName @@ -175,6 +176,7 @@ export default { }, async getInstalledDepList () { this.loading = true + this.installedDepList = [] const res = await this.$request.get(`/nodes/${this.nodeForm._id}/deps/installed`, { lang: this.activeLang.executable_name }) diff --git a/frontend/src/components/Node/NodeInstallationMatrix.vue b/frontend/src/components/Node/NodeInstallationMatrix.vue new file mode 100644 index 00000000..c08dcaeb --- /dev/null +++ b/frontend/src/components/Node/NodeInstallationMatrix.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/frontend/src/views/node/NodeList.vue b/frontend/src/views/node/NodeList.vue index 2b721950..a3320f8d 100644 --- a/frontend/src/views/node/NodeList.vue +++ b/frontend/src/views/node/NodeList.vue @@ -142,6 +142,9 @@ + + + @@ -153,10 +156,11 @@ import { } from 'vuex' import 'github-markdown-css/github-markdown.css' import NodeNetwork from '../../components/Node/NodeNetwork' +import NodeInstallationMatrix from '../../components/Node/NodeInstallationMatrix' export default { name: 'NodeList', - components: { NodeNetwork }, + components: { NodeInstallationMatrix, NodeNetwork }, data () { return { pagination: {