Spaces:
Running
Running
orztv
commited on
Commit
·
395af2d
1
Parent(s):
c843b85
update
Browse files- Dockerfile +4 -3
- src/remix.sh +71 -5
- src/startup.sh +3 -8
Dockerfile
CHANGED
@@ -2,7 +2,8 @@ FROM nikolaik/python-nodejs:python3.10-nodejs20
|
|
2 |
|
3 |
ENV USER=pn \
|
4 |
HOMEDIR=/home/pn \
|
5 |
-
PORT=7860
|
|
|
6 |
|
7 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
8 |
apt-utils \
|
@@ -22,8 +23,8 @@ RUN chmod +x ${HOMEDIR}/*.sh
|
|
22 |
|
23 |
# 运行 setup.sh、sshx.sh 和 remix.sh
|
24 |
RUN ${HOMEDIR}/setup.sh \
|
25 |
-
&& ${HOMEDIR}/
|
26 |
-
&& ${HOMEDIR}/
|
27 |
|
28 |
# 暴露 Remix 端口
|
29 |
EXPOSE ${PORT}
|
|
|
2 |
|
3 |
ENV USER=pn \
|
4 |
HOMEDIR=/home/pn \
|
5 |
+
PORT=7860 \
|
6 |
+
REMIX_NAME=remix-app
|
7 |
|
8 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
9 |
apt-utils \
|
|
|
23 |
|
24 |
# 运行 setup.sh、sshx.sh 和 remix.sh
|
25 |
RUN ${HOMEDIR}/setup.sh \
|
26 |
+
&& ${HOMEDIR}/remix.sh \
|
27 |
+
&& ${HOMEDIR}/sshx.sh
|
28 |
|
29 |
# 暴露 Remix 端口
|
30 |
EXPOSE ${PORT}
|
src/remix.sh
CHANGED
@@ -4,20 +4,86 @@ set -e
|
|
4 |
echo "开始安装 Remix..."
|
5 |
|
6 |
# 使用 npx 来运行 create-remix
|
7 |
-
npx create-remix@latest
|
8 |
|
9 |
# 进入 Remix 项目目录
|
10 |
-
cd ${HOMEDIR}
|
11 |
|
12 |
# 安装依赖并构建
|
13 |
pnpm install
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
pnpm run build
|
19 |
|
20 |
# 返回 HOMEDIR
|
21 |
cd ${HOMEDIR}
|
22 |
|
23 |
-
echo "Remix
|
|
|
4 |
echo "开始安装 Remix..."
|
5 |
|
6 |
# 使用 npx 来运行 create-remix
|
7 |
+
npx create-remix@latest ${REMIX_NAME} --yes --no-install --no-git-init
|
8 |
|
9 |
# 进入 Remix 项目目录
|
10 |
+
cd ${HOMEDIR}/${REMIX_NAME}
|
11 |
|
12 |
# 安装依赖并构建
|
13 |
pnpm install
|
14 |
|
15 |
+
# 创建 sshx 路由文件
|
16 |
+
cat << EOF > app/routes/sshx.tsx
|
17 |
+
import { useState, useEffect } from 'react';
|
18 |
+
import { json, ActionFunction } from '@remix-run/node';
|
19 |
+
import { useLoaderData, Form, useSubmit } from '@remix-run/react';
|
20 |
+
import { spawn } from 'child_process';
|
21 |
+
|
22 |
+
let sshxProcess: any = null;
|
23 |
+
let sshxOutput = '';
|
24 |
+
|
25 |
+
export const loader = async () => {
|
26 |
+
return json({ status: sshxProcess ? 'running' : 'stopped', output: sshxOutput });
|
27 |
+
};
|
28 |
+
|
29 |
+
export const action: ActionFunction = async ({ request }) => {
|
30 |
+
const formData = await request.formData();
|
31 |
+
const action = formData.get('action');
|
32 |
+
|
33 |
+
if (action === 'start' && !sshxProcess) {
|
34 |
+
sshxProcess = spawn('${HOMEDIR}/sshx/sshx', []);
|
35 |
+
sshxProcess.stdout.on('data', (data: Buffer) => {
|
36 |
+
sshxOutput += data.toString();
|
37 |
+
});
|
38 |
+
sshxProcess.stderr.on('data', (data: Buffer) => {
|
39 |
+
sshxOutput += data.toString();
|
40 |
+
});
|
41 |
+
return json({ status: 'started' });
|
42 |
+
} else if (action === 'stop' && sshxProcess) {
|
43 |
+
sshxProcess.kill();
|
44 |
+
sshxProcess = null;
|
45 |
+
return json({ status: 'stopped' });
|
46 |
+
}
|
47 |
+
|
48 |
+
return json({ error: 'Invalid action' }, { status: 400 });
|
49 |
+
};
|
50 |
+
|
51 |
+
export default function Sshx() {
|
52 |
+
const { status, output } = useLoaderData();
|
53 |
+
const submit = useSubmit();
|
54 |
+
const [localOutput, setLocalOutput] = useState(output);
|
55 |
+
|
56 |
+
useEffect(() => {
|
57 |
+
const interval = setInterval(() => {
|
58 |
+
submit(null, { method: 'get', replace: true });
|
59 |
+
}, 1000);
|
60 |
+
return () => clearInterval(interval);
|
61 |
+
}, [submit]);
|
62 |
+
|
63 |
+
useEffect(() => {
|
64 |
+
setLocalOutput(output);
|
65 |
+
}, [output]);
|
66 |
+
|
67 |
+
return (
|
68 |
+
<div>
|
69 |
+
<h1>SSHX Control</h1>
|
70 |
+
<p>Status: {status}</p>
|
71 |
+
<Form method="post">
|
72 |
+
<button type="submit" name="action" value="start">Start SSHX</button>
|
73 |
+
</Form>
|
74 |
+
<Form method="post">
|
75 |
+
<button type="submit" name="action" value="stop">Stop SSHX</button>
|
76 |
+
</Form>
|
77 |
+
<h2>Output:</h2>
|
78 |
+
<pre>{localOutput}</pre>
|
79 |
+
</div>
|
80 |
+
);
|
81 |
+
}
|
82 |
+
EOF
|
83 |
|
84 |
pnpm run build
|
85 |
|
86 |
# 返回 HOMEDIR
|
87 |
cd ${HOMEDIR}
|
88 |
|
89 |
+
echo "Remix 安装完成,并添加了 SSHX 控制页面"
|
src/startup.sh
CHANGED
@@ -3,13 +3,8 @@
|
|
3 |
echo "$HOMEDIR"
|
4 |
|
5 |
# 使用 PM2 启动 Remix 应用,并传递 PORT 环境变量
|
6 |
-
cd ${HOMEDIR}
|
7 |
PORT=$PORT pm2 start npm --name "remix" -- start
|
|
|
8 |
|
9 |
-
#
|
10 |
-
$HOMEDIR/sshx/sshx --help
|
11 |
-
|
12 |
-
$HOMEDIR/sshx/sshx
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
3 |
echo "$HOMEDIR"
|
4 |
|
5 |
# 使用 PM2 启动 Remix 应用,并传递 PORT 环境变量
|
6 |
+
cd ${HOMEDIR}/${REMIX_NAME}
|
7 |
PORT=$PORT pm2 start npm --name "remix" -- start
|
8 |
+
pm2 save
|
9 |
|
10 |
+
# PM2 会保持前台运行,无需额外的命令来保持容器运行
|
|
|
|
|
|
|
|
|
|
|
|