From 4fd0ebc4742df34b0196b106f67c2271bb95bf30 Mon Sep 17 00:00:00 2001 From: jingyang <72259332+zjy365@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:21:41 +0800 Subject: [PATCH] feat: use dumb-init as the init system for Docker container (#4901) * feat: use dumb-init as the init system for Docker container * add account center * update pause_message --- frontend/Dockerfile | 5 +++-- frontend/pnpm-lock.yaml | 6 +++--- .../public/locales/en/common.json | 2 +- .../public/locales/zh/common.json | 2 +- frontend/providers/template/package.json | 2 +- .../template/public/locales/en/common.json | 4 ++-- .../template/public/locales/zh/common.json | 4 ++-- .../template/src/pages/api/listTemplate.ts | 21 ++++++++++++------- .../template/src/pages/api/updateRepo.ts | 3 --- .../providers/template/src/types/index.ts | 6 ++++++ .../workorder/public/locales/en/common.json | 3 ++- .../workorder/public/locales/zh/common.json | 3 ++- .../workorder/src/constants/workorder.ts | 4 ++++ .../src/pages/api/workorder/check.ts | 7 +++++++ .../workorder/src/types/workorder.ts | 1 + 15 files changed, 48 insertions(+), 25 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 455349c305a..268652949b6 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -71,7 +71,8 @@ RUN adduser --system --uid 1001 nextjs RUN apk add curl \ && apk add ca-certificates \ - && update-ca-certificates + && update-ca-certificates \ + && apk add --no-cache dumb-init ARG name ARG path @@ -99,4 +100,4 @@ ENV PORT 3000 ENV launchpath=./${path}/server.js -ENTRYPOINT ["sh","-c","node ${launchpath}"] \ No newline at end of file +ENTRYPOINT ["dumb-init", "sh", "-c", "node ${launchpath}"] \ No newline at end of file diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index ce3a28c29c6..8c102672906 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -2006,6 +2006,9 @@ importers: cron-parser: specifier: ^4.9.0 version: 4.9.0 + croner: + specifier: ^8.1.0 + version: 8.1.0 cronstrue: specifier: ^2.32.0 version: 2.44.0 @@ -2048,9 +2051,6 @@ importers: next-i18next: specifier: ^15.3.0 version: 15.3.0(i18next@23.12.1)(next@13.1.6)(react-i18next@14.1.2)(react@18.2.0) - node-cron: - specifier: ^3.0.3 - version: 3.0.3 nprogress: specifier: ^0.2.0 version: 0.2.0 diff --git a/frontend/providers/applaunchpad/public/locales/en/common.json b/frontend/providers/applaunchpad/public/locales/en/common.json index 0ed07064299..78a069ba35a 100644 --- a/frontend/providers/applaunchpad/public/locales/en/common.json +++ b/frontend/providers/applaunchpad/public/locales/en/common.json @@ -158,7 +158,7 @@ "Password": "Password", "Password for the image registry": "Image Registry Password", "Pause": "Pause", - "pause_message": "App update is not allowed while paused. Storage fees will still apply if storage is in use. Please confirm.", + "pause_message": "Pausing the service will stop the calculation of charges for CPU and memory, but charges for storage and external network ports will still apply. Would you like to pause now?", "Paused": "Paused", "Perday": "\/day", "Please confirm to restart the Pod?": "Are you sure you want to restart this pod?", diff --git a/frontend/providers/applaunchpad/public/locales/zh/common.json b/frontend/providers/applaunchpad/public/locales/zh/common.json index f6f9c51cba2..7fb91040805 100644 --- a/frontend/providers/applaunchpad/public/locales/zh/common.json +++ b/frontend/providers/applaunchpad/public/locales/zh/common.json @@ -158,7 +158,7 @@ "Password": "密码", "Password for the image registry": "镜像仓库密码", "Pause": "暂停", - "pause_message": "暂停状态下无法变更应用,并且如果您使用了存储卷,存储费用仍会继续计费,请确认!", + "pause_message": "暂停服务将停止计算 CPU 和内存等费用,但存储和外网端口仍将产生费用。是否现在暂停?", "Paused": "已暂停", "Perday": "每日", "Please confirm to restart the Pod?": "请确认是否重启 Pod ?", diff --git a/frontend/providers/template/package.json b/frontend/providers/template/package.json index 7c0f55ad8b3..c39bcab52c3 100644 --- a/frontend/providers/template/package.json +++ b/frontend/providers/template/package.json @@ -29,6 +29,7 @@ "axios": "^1.5.1", "codemirror": "^6.0.1", "cron-parser": "^4.9.0", + "croner": "^8.1.0", "cronstrue": "^2.32.0", "dayjs": "^1.11.10", "echarts": "^5.4.3", @@ -43,7 +44,6 @@ "nanoid": "^4.0.2", "next": "13.1.6", "next-i18next": "^15.3.0", - "node-cron": "^3.0.3", "nprogress": "^0.2.0", "octokit": "^3.1.1", "pluralize": "^8.0.0", diff --git a/frontend/providers/template/public/locales/en/common.json b/frontend/providers/template/public/locales/en/common.json index 7f93cf6faa8..8cf0f92c6cd 100644 --- a/frontend/providers/template/public/locales/en/common.json +++ b/frontend/providers/template/public/locales/en/common.json @@ -63,7 +63,7 @@ "Prompt": "Prompt", "jump_prompt": "Jump prompt", "jump_message": "This application cannot be used independently. Please click 'OK' to proceed to Sealos Desktop.", - "pause_message": "The resources occupied by storage will continue to be charged.", + "pause_message": "Pausing the service will stop the calculation of charges for CPU and memory, but charges for storage and external network ports will still apply. Would you like to pause now?", "Confirm to restart this application?": "Confirm to restart this application?", "You haven't created any application yet.": "You haven't created any application yet.", "Confirm deletion": "Confirm deletion", @@ -203,4 +203,4 @@ "Delete successful": "Delete successful", "Delete Failed": "Delete Failed", "Description": "Description" -} +} \ No newline at end of file diff --git a/frontend/providers/template/public/locales/zh/common.json b/frontend/providers/template/public/locales/zh/common.json index cd046f01783..02f31bf600a 100644 --- a/frontend/providers/template/public/locales/zh/common.json +++ b/frontend/providers/template/public/locales/zh/common.json @@ -63,7 +63,7 @@ "Prompt": "提示", "jump_prompt": "跳转提示", "jump_message": "该应用不允许单独使用,点击确认前往 Sealos Desktop 使用。", - "pause_message": "请注意,暂停状态下无法变更应用,并且如果您使用了存储卷,存储券仍会收费,请确认!", + "pause_message": "暂停服务将停止计算 CPU 和内存等费用,但存储和外网端口仍将产生费用。是否现在暂停?", "Confirm to restart this application?": "确认重启该应用?", "You haven't created any application yet.": "您还没有新建应用。", "Confirm deletion": "确认删除", @@ -209,4 +209,4 @@ "Delete successful": "删除成功", "Delete Failed": "删除失败", "Description": "描述" -} +} \ No newline at end of file diff --git a/frontend/providers/template/src/pages/api/listTemplate.ts b/frontend/providers/template/src/pages/api/listTemplate.ts index c5cd9913d59..1dc294d4a7f 100644 --- a/frontend/providers/template/src/pages/api/listTemplate.ts +++ b/frontend/providers/template/src/pages/api/listTemplate.ts @@ -6,8 +6,7 @@ import { parseGithubUrl } from '@/utils/tools'; import fs from 'fs'; import type { NextApiRequest, NextApiResponse } from 'next'; import path from 'path'; -const cron = require('node-cron'); -let hasAddCron = false; +import { Cron } from 'croner'; export function replaceRawWithCDN(url: string, cdnUrl: string) { let parsedUrl = parseGithubUrl(url); @@ -58,12 +57,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const menuCount = Number(process.env.SIDEBAR_MENU_COUNT) || 10; try { - if (!hasAddCron) { - hasAddCron = true; - cron.schedule('*/5 * * * *', async () => { - const result = await (await fetch(`${baseurl}/api/updateRepo`)).json(); - console.log(`scheduling cron`); - }); + if (!global.updateRepoCronJob) { + global.updateRepoCronJob = new Cron( + '*/5 * * * *', + async () => { + const result = await (await fetch(`${baseurl}/api/updateRepo`)).json(); + const now = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }); + console.log(`[${now}] updateRepoCronJob`); + }, + { + timezone: 'Asia/Shanghai' + } + ); } if (!fs.existsSync(jsonPath)) { diff --git a/frontend/providers/template/src/pages/api/updateRepo.ts b/frontend/providers/template/src/pages/api/updateRepo.ts index ea8eb793901..c64ca7afcc9 100644 --- a/frontend/providers/template/src/pages/api/updateRepo.ts +++ b/frontend/providers/template/src/pages/api/updateRepo.ts @@ -78,9 +78,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< 'git config --global --add safe.directory /app/providers/template/templates', { timeout: 10000 } ); - - console.log('git config:', gitConfigResult); - const gitCommand = !fs.existsSync(targetPath) ? `git clone -b ${branch} ${repoHttpUrl} ${targetPath} --depth=1` : `cd ${targetPath} && git pull --depth=1 --rebase`; diff --git a/frontend/providers/template/src/types/index.ts b/frontend/providers/template/src/types/index.ts index cfc745576a7..3dabc708a48 100644 --- a/frontend/providers/template/src/types/index.ts +++ b/frontend/providers/template/src/types/index.ts @@ -1,3 +1,9 @@ +import Cron from 'croner'; + +declare global { + var updateRepoCronJob: Cron; +} + export type QueryType = { name: string; templateName: string; diff --git a/frontend/providers/workorder/public/locales/en/common.json b/frontend/providers/workorder/public/locales/en/common.json index 52212d169b2..8b064dd7c91 100644 --- a/frontend/providers/workorder/public/locales/en/common.json +++ b/frontend/providers/workorder/public/locales/en/common.json @@ -62,5 +62,6 @@ "region": "region", "userId": "userId", "other": "other", - "fastgpt": "FastGPT" + "fastgpt": "FastGPT", + "account_center": "Account Center" } \ No newline at end of file diff --git a/frontend/providers/workorder/public/locales/zh/common.json b/frontend/providers/workorder/public/locales/zh/common.json index 8090d32602b..bc20ce70b92 100644 --- a/frontend/providers/workorder/public/locales/zh/common.json +++ b/frontend/providers/workorder/public/locales/zh/common.json @@ -62,5 +62,6 @@ "region": "可用区", "userId": "用户ID", "other": "其他", - "fastgpt": "FastGPT" + "fastgpt": "FastGPT", + "account_center": "账号中心" } \ No newline at end of file diff --git a/frontend/providers/workorder/src/constants/workorder.ts b/frontend/providers/workorder/src/constants/workorder.ts index 25cb9253172..a2ee6f1d5f1 100644 --- a/frontend/providers/workorder/src/constants/workorder.ts +++ b/frontend/providers/workorder/src/constants/workorder.ts @@ -36,6 +36,10 @@ export const OrderTypeList: { id: WorkOrderType.FunctionServer, label: 'functionserver' }, + { + id: WorkOrderType.AccountCenter, + label: 'account_center' + }, { id: WorkOrderType.Other, label: 'other' diff --git a/frontend/providers/workorder/src/pages/api/workorder/check.ts b/frontend/providers/workorder/src/pages/api/workorder/check.ts index bc17caba030..637328faaae 100644 --- a/frontend/providers/workorder/src/pages/api/workorder/check.ts +++ b/frontend/providers/workorder/src/pages/api/workorder/check.ts @@ -139,6 +139,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } }); + if (recentUnresponded.length === 0 && overdueAutoCloseIn7Days.length === 0) { + return jsonRes(res, { + code: 204, + message: 'No content to send' + }); + } + await Promise.all([ ...overdueAutoCloseIn7Days.map((order) => updateOrder({ diff --git a/frontend/providers/workorder/src/types/workorder.ts b/frontend/providers/workorder/src/types/workorder.ts index bb7b3f697f2..80b009276fd 100644 --- a/frontend/providers/workorder/src/types/workorder.ts +++ b/frontend/providers/workorder/src/types/workorder.ts @@ -40,6 +40,7 @@ export enum WorkOrderType { ObjectStorage = 'objectstorage', FunctionServer = 'functionserver', FastGPT = 'fastgpt', + AccountCenter = 'account_center', Other = 'other' }