Skip to content

Commit

Permalink
加入php安装
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Mar 10, 2020
1 parent 689d44b commit 96ae068
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 117 deletions.
1 change: 1 addition & 0 deletions backend/entity/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
19 changes: 19 additions & 0 deletions backend/scripts/install-dotnet.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions backend/scripts/install-php.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions backend/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 6 additions & 32 deletions backend/services/rpc/install_lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 本地安装语言
func InstallLangLocal(lang string) (o string, err error) {
l := utils.GetLangFromLangNamePlain(lang)
if l.Name == "" || l.InstallScript == "" {
return "", errors.New(fmt.Sprintf("%s is not implemented", lang))
}

// 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"))
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
}

// 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 {
return "", errors.New(fmt.Sprintf("%s is not implemented", lang))
}
return
}

Expand Down
16 changes: 16 additions & 0 deletions backend/utils/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion devops/develop/crawlab-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion devops/develop/crawlab-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
178 changes: 95 additions & 83 deletions frontend/src/components/Node/NodeInstallationMatrix.vue
Original file line number Diff line number Diff line change
@@ -1,87 +1,96 @@
<template>
<div class="node-installation-matrix">
<div class="lang-table">
<el-table
class="table"
:data="nodeList"
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white',height:'50px'}"
border
@row-click="onLangTableRowClick"
>
<el-table-column
:label="$t('Node')"
width="240px"
prop="name"
/>
<el-table-column
:label="$t('nodeList.type')"
width="120px"
>
<template slot-scope="scope">
<el-tag type="primary" v-if="scope.row.is_master">{{$t('Master')}}</el-tag>
<el-tag type="warning" v-else>{{$t('Worker')}}</el-tag>
</template>
</el-table-column>
<el-table-column
:label="$t('Status')"
width="120px"
>
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.status === 'offline'">{{$t('Offline')}}</el-tag>
<el-tag type="success" v-else-if="scope.row.status === 'online'">{{$t('Online')}}</el-tag>
<el-tag type="danger" v-else>{{$t('Unavailable')}}</el-tag>
</template>
</el-table-column>
<el-table-column
v-for="l in langs"
:key="l.name"
:label="l.label"
width="220px"
>
<template slot="header" slot-scope="scope">
<div class="header-with-action">
<span>{{scope.column.label}}</span>
<el-button type="primary" size="mini" @click="onInstallAll(scope.column.label)">
{{$t('Install')}}
</el-button>
</div>
</template>
<template slot-scope="scope">
<template v-if="getLangInstallStatus(scope.row._id, l.name) === 'installed'">
<el-tag type="success">
<i class="el-icon-check"></i>
{{$t('Installed')}}
</el-tag>
</template>
<template v-else-if="getLangInstallStatus(scope.row._id, l.name) === 'installing'">
<el-tag type="warning">
<i class="el-icon-loading"></i>
{{$t('Installing')}}
</el-tag>
</template>
<template
v-else-if="['installing-other', 'not-installed'].includes(getLangInstallStatus(scope.row._id, l.name))"
<el-tabs v-model="activeTabName">
<el-tab-pane :label="$t('Languages')" name="lang">
<div class="lang-table">
<el-table
class="table"
:data="nodeList"
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white',height:'50px'}"
border
@row-click="onLangTableRowClick"
>
<el-table-column
:label="$t('Node')"
width="240px"
prop="name"
fixed
/>
<el-table-column
:label="$t('nodeList.type')"
width="120px"
fixed
>
<div class="cell-with-action">
<el-tag type="danger">
<i class="el-icon-error"></i>
{{$t('Not Installed')}}
</el-tag>
<el-button type="primary" size="mini" @click="onInstall(scope.row._id, scope.column.label, $event)">
{{$t('Install')}}
</el-button>
</div>
</template>
<template v-else-if="getLangInstallStatus(scope.row._id, l.name) === 'na'">
<el-tag type="info">
<i class="el-icon-question"></i>
{{$t('N/A')}}
</el-tag>
</template>
</template>
</el-table-column>
</el-table>
</div>
<template slot-scope="scope">
<el-tag type="primary" v-if="scope.row.is_master">{{$t('Master')}}</el-tag>
<el-tag type="warning" v-else>{{$t('Worker')}}</el-tag>
</template>
</el-table-column>
<el-table-column
:label="$t('Status')"
width="120px"
fixed
>
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.status === 'offline'">{{$t('Offline')}}</el-tag>
<el-tag type="success" v-else-if="scope.row.status === 'online'">{{$t('Online')}}</el-tag>
<el-tag type="danger" v-else>{{$t('Unavailable')}}</el-tag>
</template>
</el-table-column>
<el-table-column
v-for="l in langs"
:key="l.name"
:label="l.label"
width="220px"
>
<template slot="header" slot-scope="scope">
<div class="header-with-action">
<span>{{scope.column.label}}</span>
<el-button type="primary" size="mini" @click="onInstallAll(scope.column.label)">
{{$t('Install')}}
</el-button>
</div>
</template>
<template slot-scope="scope">
<template v-if="getLangInstallStatus(scope.row._id, l.name) === 'installed'">
<el-tag type="success">
<i class="el-icon-check"></i>
{{$t('Installed')}}
</el-tag>
</template>
<template v-else-if="getLangInstallStatus(scope.row._id, l.name) === 'installing'">
<el-tag type="warning">
<i class="el-icon-loading"></i>
{{$t('Installing')}}
</el-tag>
</template>
<template
v-else-if="['installing-other', 'not-installed'].includes(getLangInstallStatus(scope.row._id, l.name))"
>
<div class="cell-with-action">
<el-tag type="danger">
<i class="el-icon-error"></i>
{{$t('Not Installed')}}
</el-tag>
<el-button type="primary" size="mini" @click="onInstall(scope.row._id, scope.column.label, $event)">
{{$t('Install')}}
</el-button>
</div>
</template>
<template v-else-if="getLangInstallStatus(scope.row._id, l.name) === 'na'">
<el-tag type="info">
<i class="el-icon-question"></i>
{{$t('N/A')}}
</el-tag>
</template>
</template>
</el-table-column>
</el-table>
</div>
</el-tab-pane>
<el-tab-pane :label="$t('Dependencies')" name="dep">
</el-tab-pane>
</el-tabs>
</div>
</template>

Expand All @@ -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: {
Expand Down

0 comments on commit 96ae068

Please sign in to comment.