Refactor Docker setup and enhance file transfer progress handling. Updated Dockerfile for multi-stage builds, modified docker-compose.yml to include image and container name, and improved progress bar functionality in app.js for better user feedback during file transfers.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
# 构建前请先执行: mvn clean package
|
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
*.md
|
*.md
|
||||||
|
|||||||
27
Dockerfile
27
Dockerfile
@@ -1,12 +1,27 @@
|
|||||||
# 构建阶段:先执行 mvn clean package 生成 target/sftp-manager-1.0.0.jar
|
# ========== 阶段一:Maven 构建 ==========
|
||||||
|
FROM eclipse-temurin:8-jdk-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# 先只复制 pom,利用 Docker 缓存依赖层
|
||||||
|
COPY pom.xml .
|
||||||
|
RUN mvn dependency:go-offline -B -q
|
||||||
|
|
||||||
|
# 复制源码并打包(跳过测试,加快构建)
|
||||||
|
COPY src ./src
|
||||||
|
RUN mvn clean package -DskipTests -B -q
|
||||||
|
|
||||||
|
# ========== 阶段二:运行 ==========
|
||||||
FROM eclipse-temurin:8-jre-alpine
|
FROM eclipse-temurin:8-jre-alpine
|
||||||
|
|
||||||
VOLUME /tmp
|
WORKDIR /app
|
||||||
ARG JAR_FILE=target/sftp-manager-1.0.0.jar
|
|
||||||
|
|
||||||
COPY ${JAR_FILE} app.jar
|
# 从构建阶段复制 jar
|
||||||
|
COPY --from=builder /build/target/sftp-manager-1.0.0.jar app.jar
|
||||||
|
|
||||||
# 数据与日志目录
|
# 数据与日志目录(挂载卷时会覆盖)
|
||||||
RUN mkdir -p /app/data /app/logs
|
RUN mkdir -p /app/data /app/logs
|
||||||
|
|
||||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
EXPOSE 48081
|
||||||
|
|
||||||
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
version: '3'
|
# SFTP Manager - 拉代码后执行 run.sh / run.bat 即可运行
|
||||||
services:
|
services:
|
||||||
sftp-manager:
|
sftp-manager:
|
||||||
build: .
|
build: .
|
||||||
|
image: sftp-manager:latest
|
||||||
|
container_name: sftp-manager
|
||||||
ports:
|
ports:
|
||||||
- "48081:48081"
|
- "48081:48081"
|
||||||
volumes:
|
volumes:
|
||||||
@@ -9,4 +11,4 @@ services:
|
|||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
environment:
|
environment:
|
||||||
- SPRING_PROFILES_ACTIVE=prod
|
- SPRING_PROFILES_ACTIVE=prod
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
|
|||||||
16
run.bat
Normal file
16
run.bat
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
REM 一键运行:拉代码后执行 run.bat 即可
|
||||||
|
REM 需要本机已安装 Docker 和 Docker Compose
|
||||||
|
|
||||||
|
cd /d "%~dp0"
|
||||||
|
|
||||||
|
echo ^>^>^> 构建并启动 SFTP Manager...
|
||||||
|
docker compose up -d --build
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ^>^>^> 启动完成。
|
||||||
|
echo 访问地址: http://localhost:48081/sftp-manager
|
||||||
|
echo 停止服务: docker compose down
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
15
run.sh
Normal file
15
run.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 一键运行:拉代码后执行 ./run.sh 即可
|
||||||
|
# 需要本机已安装 Docker 和 Docker Compose
|
||||||
|
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
echo ">>> 构建并启动 SFTP Manager..."
|
||||||
|
docker compose up -d --build
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ">>> 启动完成。"
|
||||||
|
echo " 访问地址: http://localhost:48081/sftp-manager"
|
||||||
|
echo " 停止服务: docker compose down"
|
||||||
|
echo ""
|
||||||
@@ -363,7 +363,7 @@ function handleFileDrop(data, targetPanelId) {
|
|||||||
const fileName = getFileNameFromPath(sourcePath);
|
const fileName = getFileNameFromPath(sourcePath);
|
||||||
|
|
||||||
showTransferCountProgress(0, 1, fileName);
|
showTransferCountProgress(0, 1, fileName);
|
||||||
updateTransferProgress(0, '传输中 ' + fileName);
|
updateTransferProgress(0, '传输中 ' + fileName, true); // 拖拽跨面板传输,后端无流式进度
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: API_BASE + 'api/files/transfer',
|
url: API_BASE + 'api/files/transfer',
|
||||||
@@ -975,10 +975,18 @@ function showTransferProgress(show, label) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新传输进度条与标签
|
// 更新传输进度条与标签
|
||||||
function updateTransferProgress(percent, label) {
|
// indeterminate: 当后端无流式进度时(如跨面板传输 API),设为 true 显示动画进度条
|
||||||
|
function updateTransferProgress(percent, label, indeterminate) {
|
||||||
const progressBar = $('#transfer-progress-bar');
|
const progressBar = $('#transfer-progress-bar');
|
||||||
progressBar.css('width', percent + '%');
|
if (indeterminate) {
|
||||||
progressBar.text(percent + '%');
|
progressBar.css('width', '100%');
|
||||||
|
progressBar.text('');
|
||||||
|
progressBar.addClass('progress-bar-striped progress-bar-animated');
|
||||||
|
} else {
|
||||||
|
progressBar.removeClass('progress-bar-striped progress-bar-animated');
|
||||||
|
progressBar.css('width', percent + '%');
|
||||||
|
progressBar.text(percent + '%');
|
||||||
|
}
|
||||||
if (label !== undefined) {
|
if (label !== undefined) {
|
||||||
$('#transfer-progress-label').text(label);
|
$('#transfer-progress-label').text(label);
|
||||||
}
|
}
|
||||||
@@ -1083,7 +1091,7 @@ function doTransfer(sourcePanelId, targetPanelId) {
|
|||||||
const total = selectedFiles.length;
|
const total = selectedFiles.length;
|
||||||
|
|
||||||
showTransferCountProgress(0, total, '');
|
showTransferCountProgress(0, total, '');
|
||||||
updateTransferProgress(0, '传输中 (0/' + total + ')');
|
updateTransferProgress(0, '传输中 (0/' + total + ')', true); // 后端无流式进度,使用动画条
|
||||||
|
|
||||||
selectedFiles.forEach(function(sourcePath) {
|
selectedFiles.forEach(function(sourcePath) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -1105,7 +1113,7 @@ function doTransfer(sourcePanelId, targetPanelId) {
|
|||||||
}
|
}
|
||||||
const done = completed + failed;
|
const done = completed + failed;
|
||||||
showTransferCountProgress(done, total, getFileNameFromPath(sourcePath));
|
showTransferCountProgress(done, total, getFileNameFromPath(sourcePath));
|
||||||
updateTransferProgress(total > 0 ? Math.round((done / total) * 100) : 0, '传输中 (' + done + '/' + total + ')');
|
updateTransferProgress(total > 0 ? Math.round((done / total) * 100) : 0, '传输中 (' + done + '/' + total + ')', false);
|
||||||
if (done === total) {
|
if (done === total) {
|
||||||
showTransferProgress(false);
|
showTransferProgress(false);
|
||||||
if (failed === 0) {
|
if (failed === 0) {
|
||||||
@@ -1122,7 +1130,7 @@ function doTransfer(sourcePanelId, targetPanelId) {
|
|||||||
alert('传输失败: ' + errMsg);
|
alert('传输失败: ' + errMsg);
|
||||||
const done = completed + failed;
|
const done = completed + failed;
|
||||||
showTransferCountProgress(done, total, getFileNameFromPath(sourcePath));
|
showTransferCountProgress(done, total, getFileNameFromPath(sourcePath));
|
||||||
updateTransferProgress(total > 0 ? Math.round((done / total) * 100) : 0, '传输中 (' + done + '/' + total + ')');
|
updateTransferProgress(total > 0 ? Math.round((done / total) * 100) : 0, '传输中 (' + done + '/' + total + ')', false);
|
||||||
if (done === total) {
|
if (done === total) {
|
||||||
showTransferProgress(false);
|
showTransferProgress(false);
|
||||||
updateStatus('传输完成:成功 ' + completed + ',失败 ' + failed);
|
updateStatus('传输完成:成功 ' + completed + ',失败 ' + failed);
|
||||||
|
|||||||
Reference in New Issue
Block a user