mirror of
https://github.com/certd/certd.git
synced 2026-07-09 14:17:37 +08:00
refactor: ```
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"name": "@certd/samples",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"main": "./src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
@@ -11,7 +11,9 @@
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@types/node": "^14.14.13",
|
||||
"lodash": "^4.17.20",
|
||||
"log4js": "^6.3.0"
|
||||
"log4js": "^6.3.0",
|
||||
"@certd/certd": "^0.0.1",
|
||||
"@certd/plugins": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
import Certd from '@certd/certd'
|
||||
import CertdPlugins from '@certd/plugins'
|
||||
import options from './options'
|
||||
import log from './util.log'
|
||||
export class DeployFlow {
|
||||
async run () {
|
||||
import log from './util.log.js'
|
||||
export class Deployer {
|
||||
async run (options) {
|
||||
const certd = new Certd()
|
||||
const cert = certd.certApply(options)
|
||||
const context = {}
|
||||
for (const deploy of options.deploy) {
|
||||
log.info(`-------部署任务【${deploy.deployName}】开始-------`)
|
||||
|
||||
for (const task of deploy.tasks) {
|
||||
await this.runTask({ options, cert, task })
|
||||
await this.runTask({ options, cert, task, context })
|
||||
}
|
||||
log.info(`-------部署任务【${deploy.deployName}】完成-------`)
|
||||
}
|
||||
return {
|
||||
cert,
|
||||
context
|
||||
}
|
||||
}
|
||||
|
||||
async runTask ({ options, task, cert }) {
|
||||
async runTask ({ options, task, cert, context }) {
|
||||
const taskType = task.type
|
||||
const plugin = CertdPlugins[taskType]
|
||||
if (plugin == null) {
|
||||
throw new Error(`插件:${taskType}还未安装`)
|
||||
}
|
||||
const context = {}
|
||||
|
||||
log.info(`--插件【${task.taskName}】开始执行-------`)
|
||||
await plugin.execute({ cert, providers: options.providers, args: task, context })
|
||||
await plugin.execute({ cert, accessProviders: options.accessProviders, args: task, context })
|
||||
log.info(`--插件【${task.taskName}】执行完成-------`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import util from './util.js'
|
||||
import log4js from 'log4js'
|
||||
import path from 'path'
|
||||
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
|
||||
const filename = path.join(util.getUserBasePath(), '/logs/certd.log')
|
||||
log4js.configure({
|
||||
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
|
||||
categories: { default: { appenders: ['std'], level: level } }
|
||||
appenders: { std: { type: 'stdout' } },
|
||||
categories: { default: { appenders: ['std'], level: 'info' } }
|
||||
})
|
||||
const logger = log4js.getLogger('certd')
|
||||
export default logger
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import pkg from 'chai'
|
||||
import options from './options.js'
|
||||
import Deployer from '../src/index.js'
|
||||
const { expect } = pkg
|
||||
describe('AutoDeploy', function () {
|
||||
it('#run', async function () {
|
||||
const deploy = new Deployer()
|
||||
const ret = deploy.run(options)
|
||||
expect(ret).ok
|
||||
expect(ret.cert).ok
|
||||
expect(ret.AliyunCertId).ok
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash'
|
||||
import optionsPrivate from './options.private.js'
|
||||
import optionsPrivate from '../../../test/options.private.js'
|
||||
const defaultOptions = {
|
||||
providers: {
|
||||
accessProviders: {
|
||||
aliyun: {
|
||||
providerType: 'aliyun',
|
||||
accessKeyId: '',
|
||||
@@ -17,7 +17,7 @@ const defaultOptions = {
|
||||
}
|
||||
},
|
||||
cert: {
|
||||
domains: ['*.docmirror.club', 'docmirror.club'],
|
||||
domains: ['*.docmirror.club', 'docmirror.xyz'],
|
||||
email: 'xiaojunnuo@qq.com',
|
||||
challenge: {
|
||||
challengeType: 'dns',
|
||||
@@ -38,17 +38,17 @@ const defaultOptions = {
|
||||
tasks: [
|
||||
{
|
||||
name: '上传证书到云',
|
||||
taskType: 'uploadCertToCloud',
|
||||
type: 'uploadCertToAliyun',
|
||||
certStore: 'aliyun'
|
||||
},
|
||||
{
|
||||
{ // CDN、SCDN、DCDN和负载均衡(SLB)
|
||||
name: '部署证书到SLB',
|
||||
taskType: 'deployCertToAliyunSLB',
|
||||
type: 'deployCertToAliyunSLB',
|
||||
certStore: 'aliyun'
|
||||
},
|
||||
{
|
||||
name: '部署证书到阿里云集群Ingress',
|
||||
taskType: 'deployCertToAliyunK8sIngress',
|
||||
type: 'deployCertToAliyunK8sIngress',
|
||||
certStore: 'aliyun'
|
||||
}
|
||||
]
|
||||
@@ -58,7 +58,7 @@ const defaultOptions = {
|
||||
tasks: [
|
||||
{
|
||||
name: '上传证书到服务器,并重启nginx',
|
||||
taskType: 'sshAndExecute',
|
||||
type: 'sshAndExecute',
|
||||
ssh: 'myLinux',
|
||||
upload: [
|
||||
{ from: '{certPath}', to: '/xxx/xxx/xxx.cert.pem' },
|
||||
@@ -73,7 +73,7 @@ const defaultOptions = {
|
||||
tasks: [
|
||||
{
|
||||
name: '触发jenkins任务',
|
||||
taskType: 'sshAndExecute',
|
||||
type: 'sshAndExecute',
|
||||
ssh: 'myLinux',
|
||||
script: 'sudo systemctl restart nginx'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user