修改部署文件

This commit is contained in:
wuhan 2024-01-31 17:10:26 +08:00
parent bfc937c585
commit cdab03190c
7 changed files with 94 additions and 16 deletions

31
Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM node:18-alpine
# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 指定工作目录
WORKDIR /app
# 复制当前代码到/app工作目录
COPY . .
# npm 源,选用国内镜像源以提高下载速度
RUN npm config set registry https://registry.npm.taobao.org/
# 使用通配符来确保 package.json 和 package-lock.json 被复制
COPY package.json /app/package.json
# 安装应用依赖
RUN cd /app && rm -rf /app/node_modules && node -v && npm cache verify && npm config set strict-ssl false && npm install --force
# 打包
RUN npm run build
# 启动服务
# "start:prod": "cross-env NODE_ENV=production node ./dist/src/main.js",
CMD npm run start:prod
EXPOSE 7666

26
docker-compose.yml Normal file
View File

@ -0,0 +1,26 @@
version: "1.0"
services:
drive-server:
# nestjs服务
container_name: drive-server
build:
# 根据Dockerfile构建镜像
context: .
dockerfile: Dockerfile
ports:
- 7666:7666
restart: on-failure # 设置自动重启这一步必须设置主要是存在mysql还没有启动完成就启动了node服务
volumes:
- ./prod.yaml:/prod:yaml
environment:
- HOST = 192.168.10.13
- PASSWORD = '123456'
# networks:
# - drive-server
# 声明一下网桥 my-server。
# 重要:将所有服务都挂载在同一网桥即可通过容器名来互相通信了
# 如nestjs连接mysql和redis可以通过容器名来互相通信
# networks:
# drive-server:

8
prod.yaml Normal file
View File

@ -0,0 +1,8 @@
TEST_VALUE:
name: cookie
# 数据库相关
DATABASE: drive
USER: root
PORT: 3306
HOST: 192.168.10.13
PASSWORD: '123456'

View File

@ -12,7 +12,11 @@ import { getMysql } from './utils/config';
// 加载连接数据库
TypeOrmModule.forRootAsync({
useFactory: async () => {
return getMysql() as TypeOrmModuleAsyncOptions;
return {
...getMysql(), entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
synchronize: false,
logging: true,
} as TypeOrmModuleAsyncOptions;
},
}),
ClientModule,

View File

@ -16,6 +16,7 @@ export class ClientService {
*
*/
async queryHccNum({ areaCode }) {
console.log('queryHccNum');
const [parent, child] = await Promise.all([
clientMapper.queryHccNum({ areaCode }),
clientMapper.queryHccChildNum({ areaCode }),
@ -51,6 +52,7 @@ export class ClientService {
* @returns
*/
async queryUserNum({ areaCode }) {
console.log('queryUserNum');
const [parent, child, childNum] = await Promise.all([
await clientMapper.queryHccNum({ areaCode }),
await clientMapper.queryUserNum({ areaCode }),
@ -94,6 +96,7 @@ export class ClientService {
* 4.4
*/
async queryMpNum({ areaCode, topLimit = 6, type = 0 }) {
console.log('queryMpNum');
const { startTime, endTime } = this.dealTime(type);
const count = await clientMapper.queryMp({
areaCode,
@ -248,6 +251,7 @@ export class ClientService {
* 4.5
*/
async queryArchiveList({ areaCode, pageNo = 0, pageSize = 10, type }) {
console.log('queryArchiveList');
// await clientMapper.queryArchiveListNum(areaCode, type),
const [info, count] = await clientMapper.queryArchiveList({
areaCode,
@ -274,6 +278,7 @@ export class ClientService {
* 4.6
*/
async queryDataList({ archiveId, hccId, areaCode }) {
console.log('queryDataList');
const dataList = await clientMapper.queryDataList({
archiveId,
hccId,
@ -319,6 +324,7 @@ export class ClientService {
* 4.7
*/
async queryWarnData({ areaCode, timeRange }) {
console.log('queryWarnData');
const tokenResult = await axios.post(
`http://106.14.155.39:60036/api/v1/szjt/getToken`,
{
@ -349,6 +355,7 @@ export class ClientService {
* 4.8
*/
async queryWarnList({ code, type, time, page }) {
console.log('queryWarnList');
// let pageSize, pageIndex;
// if (!page) {
// pageSize = 10;
@ -464,6 +471,7 @@ export class ClientService {
* 4.9使
*/
async queryDataUseNum({ areaCode, dateRange = 1, limit = 7 }) {
console.log('queryDataUseNum');
const { startTime, endTime } = this.dealTime(dateRange);
const result = await clientMapper.queryDataUseNum({
areaCode,

View File

@ -36,6 +36,6 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe());
app.useStaticAssets(join(__dirname, '..', 'public'));
await app.listen(60036, '0.0.0.0');
await app.listen(7666, '0.0.0.0');
}
bootstrap();

View File

@ -18,20 +18,21 @@ export const getConfig = () => {
return configAll
}
const environment = getEnv();
const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
// const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
const yamlPath = path.join(process.cwd(), `./${environment}.yaml`);
const file = fs.readFileSync(yamlPath, 'utf8');
let config = parse(file);
if (process?.argv[2]?.length) {
config = { ...config, HOST: process.argv[2] }
}
if (process?.argv[3]?.length) {
config = { ...config, USER: process.argv[3] }
}
if (process?.argv[4]?.length) {
config = { ...config, PASSWORD: process.argv[4] }
}
// if (process?.argv[2]?.length) {
// config = { ...config, HOST: process.argv[2] }
// }
// if (process?.argv[3]?.length) {
// config = { ...config, USER: process.argv[3] }
// }
// if (process?.argv[4]?.length) {
// config = { ...config, PASSWORD: process.argv[4] }
// }
// 融合注入参数
// config = Object.assign(config, process.env);
config = Object.assign(config, process.env);
console.log(config)
configAll = { ...config, isExist: true }
return config;
@ -51,9 +52,9 @@ export const getMysql = () => {
// username: 'root',
// password: '123456',
// database: 'drive',
entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
synchronize: false,
logging: true,
// entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
// synchronize: false,
// logging: true,
}
console.log(mysql);