mirror of https://github.com/certd/certd
feat: config merge
parent
99522fb49a
commit
fdc25dc0d7
|
@ -1 +0,0 @@
|
||||||
CERTD_AUTH_JWT_KEY=certd666
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
koa:
|
||||||
|
port: 7001
|
|
@ -0,0 +1,2 @@
|
||||||
|
koa:
|
||||||
|
port: 7001
|
|
@ -0,0 +1,2 @@
|
||||||
|
koa:
|
||||||
|
port: 7001
|
|
@ -7,9 +7,6 @@ COPY . .
|
||||||
#RUN npm install --registry=https://registry.npmmirror.com
|
#RUN npm install --registry=https://registry.npmmirror.com
|
||||||
RUN npm install -g cnpm
|
RUN npm install -g cnpm
|
||||||
RUN cnpm install
|
RUN cnpm install
|
||||||
RUN npm run build:preview
|
RUN npm run build
|
||||||
|
|
||||||
# 如果端口更换,这边可以更新一下
|
CMD ["npm", "run", "online"]
|
||||||
EXPOSE 7001
|
|
||||||
|
|
||||||
CMD ["npm", "run", "online:preview"]
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"glob": "^7.2.3",
|
"glob": "^7.2.3",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"kubernetes-client": "^9.0.0",
|
"kubernetes-client": "^9.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|
|
@ -4,13 +4,13 @@ import { FlywayHistory } from 'midway-flyway-js/dist/entity';
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
import { UserEntity } from '../modules/authority/entity/user';
|
import { UserEntity } from '../modules/authority/entity/user';
|
||||||
import { PipelineEntity } from '../modules/pipeline/entity/pipeline';
|
import { PipelineEntity } from '../modules/pipeline/entity/pipeline';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
//import { logger } from '../utils/logger';
|
//import { logger } from '../utils/logger';
|
||||||
// load .env file in process.cwd
|
// load .env file in process.cwd
|
||||||
dotenv.config();
|
import _ from 'lodash';
|
||||||
export default {
|
import { load } from './loader';
|
||||||
|
const development = {
|
||||||
// use for cookie sign key, should change to your own and keep security
|
// use for cookie sign key, should change to your own and keep security
|
||||||
keys: process.env.CERTD_AUTH_JWT_KEY,
|
keys: 'certd666',
|
||||||
koa: {
|
koa: {
|
||||||
port: 7001,
|
port: 7001,
|
||||||
},
|
},
|
||||||
|
@ -68,7 +68,7 @@ export default {
|
||||||
|
|
||||||
biz: {
|
biz: {
|
||||||
jwt: {
|
jwt: {
|
||||||
secret: process.env.CERTD_AUTH_JWT_KEYS,
|
secret: 'certd666',
|
||||||
expire: 7 * 24 * 60, //单位秒
|
expire: 7 * 24 * 60, //单位秒
|
||||||
},
|
},
|
||||||
auth: {
|
auth: {
|
||||||
|
@ -76,3 +76,5 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
|
_.merge(development, load('development'));
|
||||||
|
export default development;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
|
import { load } from './loader';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
export default {
|
const preview = {
|
||||||
/**
|
/**
|
||||||
* 演示环境
|
* 演示环境
|
||||||
*/
|
*/
|
||||||
|
@ -8,3 +10,7 @@ export default {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
|
|
||||||
|
_.merge(preview, load('preview'));
|
||||||
|
|
||||||
|
export default preview;
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
import { MidwayConfig } from '@midwayjs/core';
|
||||||
|
import { load } from './loader';
|
||||||
export default {
|
import _ from 'lodash';
|
||||||
|
const production = {
|
||||||
/**
|
/**
|
||||||
* 演示环境
|
* 演示环境
|
||||||
*/
|
*/
|
||||||
preview: {
|
preview: {
|
||||||
enabled: true,
|
enabled: false,
|
||||||
},
|
},
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
|
|
||||||
|
_.merge(production, load('production'));
|
||||||
|
|
||||||
|
export default production;
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import path from 'path';
|
||||||
|
import _ from 'lodash';
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
function parseEnv() {
|
||||||
|
const config = {};
|
||||||
|
for (const key in process.env) {
|
||||||
|
let keyName = key;
|
||||||
|
if (!keyName.startsWith('certd_')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
keyName = keyName.replace('certd_', '');
|
||||||
|
const configKey = keyName.replace('_', '.');
|
||||||
|
_.set(config, configKey, process.env[key]);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function load(env = '') {
|
||||||
|
// Get document, or throw exception on error
|
||||||
|
const yamlPath = path.join(process.cwd(), `.env.${env}.yaml`);
|
||||||
|
const doc = yaml.load(fs.readFileSync(yamlPath, 'utf8'));
|
||||||
|
_.merge(doc, parseEnv());
|
||||||
|
return doc;
|
||||||
|
}
|
|
@ -1,9 +1,5 @@
|
||||||
import { Provide } from '@midwayjs/decorator';
|
import { Provide } from '@midwayjs/decorator';
|
||||||
import {
|
import { IWebMiddleware, IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
|
||||||
IWebMiddleware,
|
|
||||||
IMidwayKoaContext,
|
|
||||||
NextFunction,
|
|
||||||
} from '@midwayjs/koa';
|
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
|
|
Loading…
Reference in New Issue