diff --git a/backend/constants/system.go b/backend/constants/system.go index 03491222..14c45698 100644 --- a/backend/constants/system.go +++ b/backend/constants/system.go @@ -18,3 +18,8 @@ const ( InstallStatusInstallingOther = "installing-other" InstallStatusInstalled = "installed" ) + +const ( + LangTypeLang = "lang" + LangTypeWebDriver = "webdriver" +) diff --git a/backend/entity/system.go b/backend/entity/system.go index bb95216d..f1a24f4b 100644 --- a/backend/entity/system.go +++ b/backend/entity/system.go @@ -24,6 +24,7 @@ type Lang struct { InstallStatus string `json:"install_status"` DepFileName string `json:"dep_file_name"` InstallDepArgs string `json:"install_dep_cmd"` + Type string `json:"type"` } type Dependency struct { diff --git a/backend/scripts/install-chromedriver.sh b/backend/scripts/install-chromedriver.sh new file mode 100644 index 00000000..8394797b --- /dev/null +++ b/backend/scripts/install-chromedriver.sh @@ -0,0 +1,18 @@ +export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install \ + unzip \ + && \ + DL=https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ + && curl -sL "$DL" > /tmp/chrome.deb \ + && apt install --no-install-recommends --no-install-suggests -y \ + /tmp/chrome.deb \ + && CHROMIUM_FLAGS='--no-sandbox --disable-dev-shm-usage' \ + # Patch Chrome launch script and append CHROMIUM_FLAGS to the last line: + && sed -i '${s/$/'" $CHROMIUM_FLAGS"'/}' /opt/google/chrome/google-chrome \ + && BASE_URL=https://chromedriver.storage.googleapis.com \ + && VERSION=$(curl -sL "$BASE_URL/LATEST_RELEASE") \ + && curl -sL "$BASE_URL/$VERSION/chromedriver_linux64.zip" -o /tmp/driver.zip \ + && unzip /tmp/driver.zip \ + && chmod 755 chromedriver \ + && mv chromedriver /usr/local/bin \ No newline at end of file diff --git a/backend/services/system.go b/backend/services/system.go index 49a47219..597bf96b 100644 --- a/backend/services/system.go +++ b/backend/services/system.go @@ -71,6 +71,7 @@ func GetLangList(nodeId string) []entity.Lang { return list } +// 获取语言安装状态 func GetLangInstallStatus(nodeId string, lang entity.Lang) (string, error) { if IsMasterNode(nodeId) { lang := rpc.GetLangLocal(lang) diff --git a/backend/utils/system.go b/backend/utils/system.go index 0fbc3776..dd41d195 100644 --- a/backend/utils/system.go +++ b/backend/utils/system.go @@ -1,6 +1,7 @@ package utils import ( + "crawlab/constants" "crawlab/entity" "encoding/json" "github.com/apex/log" @@ -10,6 +11,7 @@ import ( func GetLangList() []entity.Lang { list := []entity.Lang{ + // 语言 { Name: "Python", ExecutableName: "python", @@ -18,6 +20,7 @@ func GetLangList() []entity.Lang { LockPath: "/tmp/install-python.lock", DepFileName: "requirements.txt", InstallDepArgs: "install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt", + Type: constants.LangTypeLang, }, { Name: "Node.js", @@ -28,6 +31,7 @@ func GetLangList() []entity.Lang { InstallScript: "install-nodejs.sh", DepFileName: "package.json", InstallDepArgs: "install -g --registry=https://registry.npm.taobao.org", + Type: constants.LangTypeLang, }, { Name: "Java", @@ -35,6 +39,7 @@ func GetLangList() []entity.Lang { ExecutablePaths: []string{"/usr/bin/java", "/usr/local/bin/java"}, LockPath: "/tmp/install-java.lock", InstallScript: "install-java.sh", + Type: constants.LangTypeLang, }, { Name: ".Net Core", @@ -42,6 +47,7 @@ func GetLangList() []entity.Lang { ExecutablePaths: []string{"/usr/bin/dotnet", "/usr/local/bin/dotnet"}, LockPath: "/tmp/install-dotnet.lock", InstallScript: "install-dotnet.sh", + Type: constants.LangTypeLang, }, { Name: "PHP", @@ -49,6 +55,7 @@ func GetLangList() []entity.Lang { ExecutablePaths: []string{"/usr/bin/php", "/usr/local/bin/php"}, LockPath: "/tmp/install-php.lock", InstallScript: "install-php.sh", + Type: constants.LangTypeLang, }, { Name: "Golang", @@ -56,6 +63,16 @@ func GetLangList() []entity.Lang { ExecutablePaths: []string{"/usr/bin/go", "/usr/local/bin/go"}, LockPath: "/tmp/install-go.lock", InstallScript: "install-go.sh", + Type: constants.LangTypeLang, + }, + // WebDriver + { + Name: "Chrome Driver", + ExecutableName: "chromedriver", + ExecutablePaths: []string{"/usr/bin/chromedriver", "/usr/local/bin/chromedriver"}, + LockPath: "/tmp/install-chromedriver.lock", + InstallScript: "install-chromedriver.sh", + Type: constants.LangTypeWebDriver, }, } return list diff --git a/frontend/src/components/Node/NodeInstallationMatrix.vue b/frontend/src/components/Node/NodeInstallationMatrix.vue index 973a7874..411f7dff 100644 --- a/frontend/src/components/Node/NodeInstallationMatrix.vue +++ b/frontend/src/components/Node/NodeInstallationMatrix.vue @@ -72,7 +72,11 @@ {{ $t('Not Installed') }} - + {{ $t('Install') }} @@ -203,6 +207,97 @@ + +
+ + + + + + + + + + + + + +
+
@@ -220,13 +315,16 @@ }, data() { return { - langs: [ - { label: 'Python', name: 'python', hasDeps: true }, - { label: 'Node.js', name: 'node', hasDeps: true }, - { label: 'Java', name: 'java', hasDeps: false }, - { label: '.Net Core', name: 'dotnet', hasDeps: false }, - { label: 'PHP', name: 'php', hasDeps: false }, - { label: 'Golang', name: 'go', hasDeps: false } + allLangs: [ + // 语言 + { label: 'Python', name: 'python', hasDeps: true, type: 'lang' }, + { label: 'Node.js', name: 'node', hasDeps: true, type: 'lang' }, + { label: 'Java', name: 'java', hasDeps: false, type: 'lang' }, + { label: '.Net Core', name: 'dotnet', hasDeps: false, type: 'lang' }, + { label: 'PHP', name: 'php', hasDeps: false, type: 'lang' }, + { label: 'Golang', name: 'go', hasDeps: false, type: 'lang' }, + // web driver + { label: 'Chrome Driver', name: 'chromedriver', type: 'webdriver' } ], langsDataDict: {}, handle: undefined, @@ -244,6 +342,12 @@ ...mapState('node', [ 'nodeList' ]), + langs() { + return this.allLangs.filter(d => d.type === 'lang') + }, + webdrivers() { + return this.allLangs.filter(d => d.type === 'webdriver') + }, activeNodes() { return this.nodeList.filter(d => d.status === 'online') }, @@ -255,7 +359,7 @@ }) }, langsWithDeps() { - return this.langs.filter(l => l.hasDeps) + return this.allLangs.filter(l => l.hasDeps) } }, watch: { @@ -316,8 +420,8 @@ return lang.install_status }, getLangFromLabel(label) { - for (let i = 0; i < this.langs.length; i++) { - const lang = this.langs[i] + for (let i = 0; i < this.allLangs.length; i++) { + const lang = this.allLangs[i] if (lang.label === label) { return lang }