refactor: host

master
xiaojunnuo 2021-02-08 15:46:03 +08:00
parent 2232f21b48
commit 399c23623d
6 changed files with 22 additions and 15 deletions

View File

@ -1,6 +1,6 @@
import _ from 'lodash-es'
import logger from '../utils/util.log.js'
import commonUtil from '../utils/util.common'
import commonUtil from '../utils/util.common.js'
export class AbstractDnsProvider {
constructor ({ accessProviders }) {
this.logger = logger

View File

@ -65,10 +65,14 @@ export class AbstractPlugin {
}
getAccessProvider (accessProvider, accessProviders = this.accessProviders) {
let access = accessProvider
if (typeof accessProvider === 'string' && accessProviders) {
accessProvider = accessProviders[accessProvider]
access = accessProviders[accessProvider]
}
return accessProvider
if (access == null) {
throw new Error(`accessProvider ${accessProvider}不存在`)
}
return access
}
async sleep (time) {

View File

@ -63,6 +63,9 @@ export class Executor {
logger.info('证书无更新,无需重新部署')
logger.info('任务完成')
return { cert }
} else {
// 强制重新运行,清空保存的状态
await certd.certStore.setCurrentFile('context.json', '{}')
}
}
// 读取上次执行进度
@ -118,6 +121,7 @@ export class Executor {
logger.info('此流程已被禁用,跳过')
logger.info('')
deployTrace.set({ value: { current: 'skip', status: 'disabled', remark: '流程禁用' } })
deployTrace.set({ tasks: null })
continue
}
try {

View File

@ -29,7 +29,7 @@ export class SshClient {
try {
for (const transport of transports) {
logger.info('上传文件:', JSON.stringify(transport))
await this.exec({ conn, cmd: 'mkdir ' + path.dirname(transport.remotePath) })
await this.exec({ connectConf, script: 'mkdir -p ' + path.dirname(transport.remotePath) })
await this.fastPut({ sftp, ...transport })
}
resolve()
@ -59,10 +59,10 @@ export class SshClient {
let data = null
stream.on('close', (code, signal) => {
console.log(`[${connectConf.host}][close]:code:${code}, signal:${signal} `)
if (code === 0) {
resolve(data.toString())
} else {
reject(data.toString())
data = data ? data.toString() : null
resolve(data)
}
conn.end()
}).on('data', (ret) => {
@ -70,7 +70,7 @@ export class SshClient {
data = ret
}).stderr.on('data', (err) => {
console.log(`[${connectConf.host}][error]: ` + err)
data = err
reject(new Error(err.toString()))
stream.close()
})
})

View File

@ -45,6 +45,7 @@ export class UploadCertToHost extends AbstractHostPlugin {
async execute ({ cert, props, context }) {
const { crtPath, keyPath, accessProvider } = props
const connectConf = this.getAccessProvider(accessProvider)
console.log('connectConf', connectConf)
const sshClient = new SshClient()
await sshClient.uploadFiles({
connectConf,

View File

@ -79,24 +79,22 @@ const defaultOptions = {
},
{
deployName: '流程2-部署到nginx服务器',
disabled: true,
disabled: false,
tasks: [
{
taskName: '上传证书到服务器',
type: 'uploadCertToHost',
props:{
accessProvider: 'aliyun-linux',
upload: [
{ from: '{certPath}', to: '/xxx/xxx/xxx.cert.pem' },
{ from: '{keyPath}', to: '/xxx/xxx/xxx.key' }
]
accessProvider: 'aliyun-ssh',
crtPath: '/root/certd-test/cert.pem',
keyPath: '/root/certd-test/cert.key'
}
},
{
taskName: '重启linux',
type: 'hostShellExecute',
props:{
accessProvider: 'aliyun-linux',
accessProvider: 'aliyun-ssh',
script: ['ls']
}
}