mirror of https://github.com/certd/certd
refactor: host
parent
2232f21b48
commit
399c23623d
|
@ -1,6 +1,6 @@
|
||||||
import _ from 'lodash-es'
|
import _ from 'lodash-es'
|
||||||
import logger from '../utils/util.log.js'
|
import logger from '../utils/util.log.js'
|
||||||
import commonUtil from '../utils/util.common'
|
import commonUtil from '../utils/util.common.js'
|
||||||
export class AbstractDnsProvider {
|
export class AbstractDnsProvider {
|
||||||
constructor ({ accessProviders }) {
|
constructor ({ accessProviders }) {
|
||||||
this.logger = logger
|
this.logger = logger
|
||||||
|
|
|
@ -65,10 +65,14 @@ export class AbstractPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccessProvider (accessProvider, accessProviders = this.accessProviders) {
|
getAccessProvider (accessProvider, accessProviders = this.accessProviders) {
|
||||||
|
let access = accessProvider
|
||||||
if (typeof accessProvider === 'string' && accessProviders) {
|
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) {
|
async sleep (time) {
|
||||||
|
|
|
@ -63,6 +63,9 @@ export class Executor {
|
||||||
logger.info('证书无更新,无需重新部署')
|
logger.info('证书无更新,无需重新部署')
|
||||||
logger.info('任务完成')
|
logger.info('任务完成')
|
||||||
return { cert }
|
return { cert }
|
||||||
|
} else {
|
||||||
|
// 强制重新运行,清空保存的状态
|
||||||
|
await certd.certStore.setCurrentFile('context.json', '{}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 读取上次执行进度
|
// 读取上次执行进度
|
||||||
|
@ -118,6 +121,7 @@ export class Executor {
|
||||||
logger.info('此流程已被禁用,跳过')
|
logger.info('此流程已被禁用,跳过')
|
||||||
logger.info('')
|
logger.info('')
|
||||||
deployTrace.set({ value: { current: 'skip', status: 'disabled', remark: '流程禁用' } })
|
deployTrace.set({ value: { current: 'skip', status: 'disabled', remark: '流程禁用' } })
|
||||||
|
deployTrace.set({ tasks: null })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class SshClient {
|
||||||
try {
|
try {
|
||||||
for (const transport of transports) {
|
for (const transport of transports) {
|
||||||
logger.info('上传文件:', JSON.stringify(transport))
|
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 })
|
await this.fastPut({ sftp, ...transport })
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -59,10 +59,10 @@ export class SshClient {
|
||||||
let data = null
|
let data = null
|
||||||
stream.on('close', (code, signal) => {
|
stream.on('close', (code, signal) => {
|
||||||
console.log(`[${connectConf.host}][close]:code:${code}, signal:${signal} `)
|
console.log(`[${connectConf.host}][close]:code:${code}, signal:${signal} `)
|
||||||
|
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve(data.toString())
|
data = data ? data.toString() : null
|
||||||
} else {
|
resolve(data)
|
||||||
reject(data.toString())
|
|
||||||
}
|
}
|
||||||
conn.end()
|
conn.end()
|
||||||
}).on('data', (ret) => {
|
}).on('data', (ret) => {
|
||||||
|
@ -70,7 +70,7 @@ export class SshClient {
|
||||||
data = ret
|
data = ret
|
||||||
}).stderr.on('data', (err) => {
|
}).stderr.on('data', (err) => {
|
||||||
console.log(`[${connectConf.host}][error]: ` + err)
|
console.log(`[${connectConf.host}][error]: ` + err)
|
||||||
data = err
|
reject(new Error(err.toString()))
|
||||||
stream.close()
|
stream.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,6 +45,7 @@ export class UploadCertToHost extends AbstractHostPlugin {
|
||||||
async execute ({ cert, props, context }) {
|
async execute ({ cert, props, context }) {
|
||||||
const { crtPath, keyPath, accessProvider } = props
|
const { crtPath, keyPath, accessProvider } = props
|
||||||
const connectConf = this.getAccessProvider(accessProvider)
|
const connectConf = this.getAccessProvider(accessProvider)
|
||||||
|
console.log('connectConf', connectConf)
|
||||||
const sshClient = new SshClient()
|
const sshClient = new SshClient()
|
||||||
await sshClient.uploadFiles({
|
await sshClient.uploadFiles({
|
||||||
connectConf,
|
connectConf,
|
||||||
|
|
|
@ -79,24 +79,22 @@ const defaultOptions = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deployName: '流程2-部署到nginx服务器',
|
deployName: '流程2-部署到nginx服务器',
|
||||||
disabled: true,
|
disabled: false,
|
||||||
tasks: [
|
tasks: [
|
||||||
{
|
{
|
||||||
taskName: '上传证书到服务器',
|
taskName: '上传证书到服务器',
|
||||||
type: 'uploadCertToHost',
|
type: 'uploadCertToHost',
|
||||||
props:{
|
props:{
|
||||||
accessProvider: 'aliyun-linux',
|
accessProvider: 'aliyun-ssh',
|
||||||
upload: [
|
crtPath: '/root/certd-test/cert.pem',
|
||||||
{ from: '{certPath}', to: '/xxx/xxx/xxx.cert.pem' },
|
keyPath: '/root/certd-test/cert.key'
|
||||||
{ from: '{keyPath}', to: '/xxx/xxx/xxx.key' }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
taskName: '重启linux',
|
taskName: '重启linux',
|
||||||
type: 'hostShellExecute',
|
type: 'hostShellExecute',
|
||||||
props:{
|
props:{
|
||||||
accessProvider: 'aliyun-linux',
|
accessProvider: 'aliyun-ssh',
|
||||||
script: ['ls']
|
script: ['ls']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue