Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use dumb-init as the init system for Docker container #4901

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,4 +100,4 @@ ENV PORT 3000

ENV launchpath=./${path}/server.js

ENTRYPOINT ["sh","-c","node ${launchpath}"]
ENTRYPOINT ["dumb-init", "sh", "-c", "node ${launchpath}"]
6 changes: 3 additions & 3 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?",
Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions frontend/providers/template/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -203,4 +203,4 @@
"Delete successful": "Delete successful",
"Delete Failed": "Delete Failed",
"Description": "Description"
}
}
4 changes: 2 additions & 2 deletions frontend/providers/template/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "确认删除",
Expand Down Expand Up @@ -209,4 +209,4 @@
"Delete successful": "删除成功",
"Delete Failed": "删除失败",
"Description": "描述"
}
}
21 changes: 13 additions & 8 deletions frontend/providers/template/src/pages/api/listTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions frontend/providers/template/src/pages/api/updateRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
6 changes: 6 additions & 0 deletions frontend/providers/template/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import Cron from 'croner';

declare global {
var updateRepoCronJob: Cron;
}

export type QueryType = {
name: string;
templateName: string;
Expand Down
3 changes: 2 additions & 1 deletion frontend/providers/workorder/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
"region": "region",
"userId": "userId",
"other": "other",
"fastgpt": "FastGPT"
"fastgpt": "FastGPT",
"account_center": "Account Center"
}
3 changes: 2 additions & 1 deletion frontend/providers/workorder/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
"region": "可用区",
"userId": "用户ID",
"other": "其他",
"fastgpt": "FastGPT"
"fastgpt": "FastGPT",
"account_center": "账号中心"
}
4 changes: 4 additions & 0 deletions frontend/providers/workorder/src/constants/workorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const OrderTypeList: {
id: WorkOrderType.FunctionServer,
label: 'functionserver'
},
{
id: WorkOrderType.AccountCenter,
label: 'account_center'
},
{
id: WorkOrderType.Other,
label: 'other'
Expand Down
7 changes: 7 additions & 0 deletions frontend/providers/workorder/src/pages/api/workorder/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions frontend/providers/workorder/src/types/workorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export enum WorkOrderType {
ObjectStorage = 'objectstorage',
FunctionServer = 'functionserver',
FastGPT = 'fastgpt',
AccountCenter = 'account_center',
Other = 'other'
}

Expand Down
Loading