mirror of https://github.com/certd/certd
Merge branch 'v2-dev' into v2-dev-suite
commit
8814ffeda6
49
README.md
49
README.md
|
@ -90,7 +90,7 @@ https://certd.handfree.work/
|
||||||
1. 修改`docker-compose.yaml`中的镜像版本号
|
1. 修改`docker-compose.yaml`中的镜像版本号
|
||||||
2. 运行`docker compose up -d` 即可
|
2. 运行`docker compose up -d` 即可
|
||||||
|
|
||||||
如果使用`latest`版本
|
如果需要使用最新版本
|
||||||
```shell
|
```shell
|
||||||
#重新拉取镜像
|
#重新拉取镜像
|
||||||
docker pull registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest
|
docker pull registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest
|
||||||
|
@ -98,7 +98,54 @@ docker pull registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest
|
||||||
docker compose down
|
docker compose down
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
关于自动升级(仅限尝鲜建议非生产使用)
|
||||||
|
```yaml
|
||||||
|
version: '3.3'
|
||||||
|
services:
|
||||||
|
certd:
|
||||||
|
image: registry.cn-shenzhen.aliyuncs.com/handsfree/certd:latest
|
||||||
|
container_name: certd
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- /data/certd:/app/data
|
||||||
|
ports:
|
||||||
|
- "7001:7001"
|
||||||
|
- "7002:7002"
|
||||||
|
# 如果需要修改系统配置,可以通过环境变量传递;初次运行请保持默认配置
|
||||||
|
environment:
|
||||||
|
- certd_system_resetAdminPasswd=false
|
||||||
|
# 如果需要切换数据库类型,可以在此处设置为mysql或postgres
|
||||||
|
# - certd_typeorm_dataSource_default_type=mysql
|
||||||
|
# - certd_typeorm_dataSource_default_host=localhost
|
||||||
|
# - certd_typeorm_dataSource_default_port=3306
|
||||||
|
# - certd_typeorm_dataSource_default_username=root
|
||||||
|
# - certd_typeorm_dataSource_default_password=123456
|
||||||
|
# - certd_typeorm_dataSource_default_database=certd
|
||||||
|
labels:
|
||||||
|
com.centurylinklabs.watchtower.enable: "true"
|
||||||
|
|
||||||
|
certd-updater: # 添加 Watchtower 服务
|
||||||
|
image: containrrr/watchtower:latest
|
||||||
|
container_name: certd-updater
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
# 配置 自动更新
|
||||||
|
environment:
|
||||||
|
- WATCHTOWER_CLEANUP=true # 自动清理旧版本容器
|
||||||
|
- WATCHTOWER_INCLUDE_STOPPED=false # 不更新已停止的容器
|
||||||
|
- WATCHTOWER_LABEL_ENABLE=true # 根据容器标签进行更新
|
||||||
|
- WATCHTOWER_POLL_INTERVAL=300 # 每 5 分钟检查一次更新
|
||||||
|
|
||||||
|
# 如果需要支持 IPv6,请取消以下注释
|
||||||
|
# networks:
|
||||||
|
# ip6net:
|
||||||
|
# enable_ipv6: true
|
||||||
|
# ipam:
|
||||||
|
# config:
|
||||||
|
# - subnet: 2001:db8::/64
|
||||||
|
|
||||||
|
```
|
||||||
> 数据默认存在`/data/certd`目录下,不用担心数据丢失
|
> 数据默认存在`/data/certd`目录下,不用担心数据丢失
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ function buildGroupOptions(options: any[], inDomains: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const optionsUtils = {
|
export const optionsUtils = {
|
||||||
|
//获取分组
|
||||||
groupByDomain,
|
groupByDomain,
|
||||||
|
//构建分组后的选项列表,常用
|
||||||
buildGroupOptions,
|
buildGroupOptions,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import axios, { AxiosRequestConfig } from 'axios';
|
import axios, { AxiosHeaders, AxiosRequestConfig } from 'axios';
|
||||||
import { ILogger, logger } from './util.log.js';
|
import { ILogger, logger } from './util.log.js';
|
||||||
import { Logger } from 'log4js';
|
import { Logger } from 'log4js';
|
||||||
import { HttpProxyAgent } from 'http-proxy-agent';
|
import { HttpProxyAgent } from 'http-proxy-agent';
|
||||||
|
@ -13,7 +13,7 @@ export class HttpError extends Error {
|
||||||
statusText?: string;
|
statusText?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
request?: { baseURL: string; url: string; method: string; params?: any; data?: any };
|
request?: { baseURL: string; url: string; method: string; params?: any; data?: any };
|
||||||
response?: { data: any };
|
response?: { data: any; headers: AxiosHeaders };
|
||||||
cause?: any;
|
cause?: any;
|
||||||
constructor(error: any) {
|
constructor(error: any) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
@ -55,6 +55,7 @@ export class HttpError extends Error {
|
||||||
|
|
||||||
this.response = {
|
this.response = {
|
||||||
data: error.response?.data,
|
data: error.response?.data,
|
||||||
|
headers: error.response?.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { stack, cause } = error;
|
const { stack, cause } = error;
|
||||||
|
@ -156,13 +157,13 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
||||||
error.message = '请求错误';
|
error.message = '请求错误';
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
error.message = '未授权,请登录';
|
error.message = '认证/登录失败';
|
||||||
break;
|
break;
|
||||||
case 403:
|
case 403:
|
||||||
error.message = '拒绝访问';
|
error.message = '拒绝访问';
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
error.message = `请求地址出错: ${error.response.config.url}`;
|
error.message = `请求地址出错`;
|
||||||
break;
|
break;
|
||||||
case 408:
|
case 408:
|
||||||
error.message = '请求超时';
|
error.message = '请求超时';
|
||||||
|
@ -216,6 +217,7 @@ export type HttpRequestConfig<D = any> = {
|
||||||
logParams?: boolean;
|
logParams?: boolean;
|
||||||
logRes?: boolean;
|
logRes?: boolean;
|
||||||
httpProxy?: string;
|
httpProxy?: string;
|
||||||
|
returnResponse?: boolean;
|
||||||
} & AxiosRequestConfig<D>;
|
} & AxiosRequestConfig<D>;
|
||||||
export type HttpClient = {
|
export type HttpClient = {
|
||||||
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
||||||
|
|
|
@ -385,7 +385,7 @@ export class Executor {
|
||||||
content = `流水线ID:${this.pipeline.id},运行ID:${this.runtime.id}`;
|
content = `流水线ID:${this.pipeline.id},运行ID:${this.runtime.id}`;
|
||||||
} else if (when === "error") {
|
} else if (when === "error") {
|
||||||
subject = `执行失败,${this.pipeline.title}【${this.pipeline.id}】`;
|
subject = `执行失败,${this.pipeline.title}【${this.pipeline.id}】`;
|
||||||
content = `流水线ID:${this.pipeline.id},运行ID:${this.runtime.id}\n错误详情:${error.message}`;
|
content = `流水线ID:${this.pipeline.id},运行ID:${this.runtime.id}\n\n${this.currentStatusMap?.currentStep?.title} 执行失败\n\n错误详情:${error.message}`;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ export class RunHistory {
|
||||||
export class RunnableCollection {
|
export class RunnableCollection {
|
||||||
private collection: RunnableMap = {};
|
private collection: RunnableMap = {};
|
||||||
private pipeline!: Pipeline;
|
private pipeline!: Pipeline;
|
||||||
|
currentStep!: Step;
|
||||||
constructor(pipeline?: Pipeline) {
|
constructor(pipeline?: Pipeline) {
|
||||||
if (!pipeline) {
|
if (!pipeline) {
|
||||||
return;
|
return;
|
||||||
|
@ -193,5 +194,8 @@ export class RunnableCollection {
|
||||||
|
|
||||||
add(runnable: Runnable) {
|
add(runnable: Runnable) {
|
||||||
this.collection[runnable.id] = runnable;
|
this.collection[runnable.id] = runnable;
|
||||||
|
if (runnable.runnableType === "step") {
|
||||||
|
this.currentStep = runnable as Step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ export type CertInfo = {
|
||||||
pfx?: string;
|
pfx?: string;
|
||||||
der?: string;
|
der?: string;
|
||||||
jks?: string;
|
jks?: string;
|
||||||
|
one?: string;
|
||||||
};
|
};
|
||||||
export type SSLProvider = "letsencrypt" | "google" | "zerossl";
|
export type SSLProvider = "letsencrypt" | "google" | "zerossl";
|
||||||
export type PrivateKeyType = "rsa_1024" | "rsa_2048" | "rsa_3072" | "rsa_4096" | "ec_256" | "ec_384" | "ec_521";
|
export type PrivateKeyType = "rsa_1024" | "rsa_2048" | "rsa_3072" | "rsa_4096" | "ec_256" | "ec_384" | "ec_521";
|
||||||
|
|
|
@ -192,6 +192,7 @@ export abstract class CertApplyBasePlugin extends AbstractTaskPlugin {
|
||||||
zip.file("cert.key", cert.key);
|
zip.file("cert.key", cert.key);
|
||||||
zip.file("intermediate.crt", cert.ic);
|
zip.file("intermediate.crt", cert.ic);
|
||||||
zip.file("origin.crt", cert.oc);
|
zip.file("origin.crt", cert.oc);
|
||||||
|
zip.file("one.pem", cert.one);
|
||||||
if (cert.pfx) {
|
if (cert.pfx) {
|
||||||
zip.file("cert.pfx", Buffer.from(cert.pfx, "base64"));
|
zip.file("cert.pfx", Buffer.from(cert.pfx, "base64"));
|
||||||
}
|
}
|
||||||
|
@ -209,6 +210,7 @@ cert.crt:证书文件,包含证书链,pem格式
|
||||||
cert.key:私钥文件,pem格式
|
cert.key:私钥文件,pem格式
|
||||||
intermediate.crt:中间证书文件,pem格式
|
intermediate.crt:中间证书文件,pem格式
|
||||||
origin.crt:原始证书文件,不含证书链,pem格式
|
origin.crt:原始证书文件,不含证书链,pem格式
|
||||||
|
one.pem: 证书和私钥简单合并成一个文件,pem格式,crt正文+key正文
|
||||||
cert.pfx:pfx格式证书文件,iis服务器使用
|
cert.pfx:pfx格式证书文件,iis服务器使用
|
||||||
cert.der:der格式证书文件
|
cert.der:der格式证书文件
|
||||||
cert.jks:jks格式证书文件,java服务器使用
|
cert.jks:jks格式证书文件,java服务器使用
|
||||||
|
|
|
@ -15,6 +15,7 @@ export type CertReaderHandleContext = {
|
||||||
tmpDerPath?: string;
|
tmpDerPath?: string;
|
||||||
tmpIcPath?: string;
|
tmpIcPath?: string;
|
||||||
tmpJksPath?: string;
|
tmpJksPath?: string;
|
||||||
|
tmpOnePath?: string;
|
||||||
};
|
};
|
||||||
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
export type CertReaderHandle = (ctx: CertReaderHandleContext) => Promise<void>;
|
||||||
export type HandleOpts = { logger: ILogger; handle: CertReaderHandle };
|
export type HandleOpts = { logger: ILogger; handle: CertReaderHandle };
|
||||||
|
@ -25,6 +26,7 @@ export class CertReader {
|
||||||
key: string;
|
key: string;
|
||||||
csr: string;
|
csr: string;
|
||||||
ic: string; //中间证书
|
ic: string; //中间证书
|
||||||
|
one: string; //crt + key 合成一个pem文件
|
||||||
|
|
||||||
detail: any;
|
detail: any;
|
||||||
expires: number;
|
expires: number;
|
||||||
|
@ -46,6 +48,12 @@ export class CertReader {
|
||||||
this.cert.oc = this.oc;
|
this.cert.oc = this.oc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.one = certInfo.one;
|
||||||
|
if (!this.one) {
|
||||||
|
this.one = this.crt + "\n" + this.key;
|
||||||
|
this.cert.one = this.one;
|
||||||
|
}
|
||||||
|
|
||||||
const { detail, expires } = this.getCrtDetail(this.cert.crt);
|
const { detail, expires } = this.getCrtDetail(this.cert.crt);
|
||||||
this.detail = detail;
|
this.detail = detail;
|
||||||
this.expires = expires.getTime();
|
this.expires = expires.getTime();
|
||||||
|
@ -88,7 +96,7 @@ export class CertReader {
|
||||||
return domains;
|
return domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveToFile(type: "crt" | "key" | "pfx" | "der" | "oc" | "ic" | "jks", filepath?: string) {
|
saveToFile(type: "crt" | "key" | "pfx" | "der" | "oc" | "one" | "ic" | "jks", filepath?: string) {
|
||||||
if (!this.cert[type]) {
|
if (!this.cert[type]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +110,7 @@ export class CertReader {
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
}
|
}
|
||||||
if (type === "crt" || type === "key" || type === "ic" || type === "oc") {
|
if (type === "crt" || type === "key" || type === "ic" || type === "oc" || type === "one") {
|
||||||
fs.writeFileSync(filepath, this.cert[type]);
|
fs.writeFileSync(filepath, this.cert[type]);
|
||||||
} else {
|
} else {
|
||||||
fs.writeFileSync(filepath, Buffer.from(this.cert[type], "base64"));
|
fs.writeFileSync(filepath, Buffer.from(this.cert[type], "base64"));
|
||||||
|
@ -120,6 +128,7 @@ export class CertReader {
|
||||||
const tmpOcPath = this.saveToFile("oc");
|
const tmpOcPath = this.saveToFile("oc");
|
||||||
const tmpDerPath = this.saveToFile("der");
|
const tmpDerPath = this.saveToFile("der");
|
||||||
const tmpJksPath = this.saveToFile("jks");
|
const tmpJksPath = this.saveToFile("jks");
|
||||||
|
const tmpOnePath = this.saveToFile("one");
|
||||||
logger.info("本地文件写入成功");
|
logger.info("本地文件写入成功");
|
||||||
try {
|
try {
|
||||||
return await opts.handle({
|
return await opts.handle({
|
||||||
|
@ -131,6 +140,7 @@ export class CertReader {
|
||||||
tmpIcPath: tmpIcPath,
|
tmpIcPath: tmpIcPath,
|
||||||
tmpJksPath: tmpJksPath,
|
tmpJksPath: tmpJksPath,
|
||||||
tmpOcPath: tmpOcPath,
|
tmpOcPath: tmpOcPath,
|
||||||
|
tmpOnePath,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -149,6 +159,7 @@ export class CertReader {
|
||||||
removeFile(tmpDerPath);
|
removeFile(tmpDerPath);
|
||||||
removeFile(tmpIcPath);
|
removeFile(tmpIcPath);
|
||||||
removeFile(tmpJksPath);
|
removeFile(tmpJksPath);
|
||||||
|
removeFile(tmpOnePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||||
{ value: 'pfx', label: 'pfx,一般用于IIS' },
|
{ value: 'pfx', label: 'pfx,一般用于IIS' },
|
||||||
{ value: 'der', label: 'der,一般用于Apache' },
|
{ value: 'der', label: 'der,一般用于Apache' },
|
||||||
{ value: 'jks', label: 'jks,一般用于JAVA应用' },
|
{ value: 'jks', label: 'jks,一般用于JAVA应用' },
|
||||||
|
{ value: 'one', label: '证书私钥一体,crt+key简单合并为一个pem文件' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -150,6 +151,24 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||||
})
|
})
|
||||||
jksPath!: string;
|
jksPath!: string;
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: '一体证书保存路径',
|
||||||
|
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/crt_key.pem',
|
||||||
|
component: {
|
||||||
|
placeholder: '/root/deploy/app/crt_key.pem',
|
||||||
|
},
|
||||||
|
mergeScript: `
|
||||||
|
return {
|
||||||
|
show: ctx.compute(({form})=>{
|
||||||
|
return form.certType === 'one';
|
||||||
|
})
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
required: true,
|
||||||
|
rules: [{ type: 'filepath' }],
|
||||||
|
})
|
||||||
|
onePath!: string;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '主机登录配置',
|
title: '主机登录配置',
|
||||||
helper: 'access授权',
|
helper: 'access授权',
|
||||||
|
|
Loading…
Reference in New Issue