Pārlūkot izejas kodu

可以部署了。

skyfffire 2 mēneši atpakaļ
vecāks
revīzija
2d817e3760
4 mainītis faili ar 133 papildinājumiem un 37 dzēšanām
  1. 17 0
      Dockerfile
  2. 40 0
      README.MD
  3. 67 0
      package.xml
  4. 9 37
      pom.xml

+ 17 - 0
Dockerfile

@@ -0,0 +1,17 @@
+# --- Stage 1: Build ---
+FROM maven:3.9.0-eclipse-temurin-8 as mvn
+WORKDIR /app
+COPY . .
+RUN mvn clean package -DskipTests
+
+# --- Stage 2: Runtime ---
+FROM openjdk:8-jre-slim
+WORKDIR /app
+
+# 只从构建阶段复制最终的 JAR 包
+COPY --from=mvn /app/target/dalian-nft-api.jar app.jar
+
+EXPOSE 8888
+
+# 启动命令保持不变
+ENTRYPOINT ["java", "-jar", "app.jar"]

+ 40 - 0
README.MD

@@ -0,0 +1,40 @@
+# 运行指南之远程部署
+
+## 步骤 1:在 IDEA 中配置远程 Docker 连接
+> 打开设置:File -> Settings (Windows/Linux) 或 IntelliJ IDEA -> Preferences (Mac)。<br>
+> 导航到:Build, Execution, Deployment -> Docker。<br>
+> 点击 + 号添加一个新的 Docker 配置。<br>
+> 选择 SSH。<br>
+> 在弹出的窗口中配置 SSH 连接信息:<br>
+> 点击 ... 按钮创建一个新的 SSH 配置。<br>
+> Host: 您服务器的 IP 地址或域名。<br>
+> Port: SSH 端口,默认为 22。<br>
+> Username: 登录服务器的用户名(例如 ec2-user, ubuntu, root 等)。<br>
+> Authentication type: 选择 Key pair。<br>
+> Private key file: 点击文件夹图标,选择您本地的 .pem 密钥文件。<br>
+> Passphrase: 如果您的密钥有密码,请填写。<br>
+> 点击 Test Connection 测试连接是否成功。成功后保存。<br>
+> 返回 Docker 配置页面,IDEA 会自动填好 SSH connection。点击 OK 保存。现在 IDEA 已经可以管理您远程服务器上的 Docker 了。<br>
+
+---
+## 步骤 2:创建并配置 Docker 运行配置 (Run Configuration)
+> 在 IDEA 的右上角,点击 Add Configuration...。<br>
+>  +,选择 Docker -> Dockerfile。<br>
+> 进行核心配置:<br>
+> Name: 给这个配置起个名字,例如 Deploy to Production Server。<br>
+> Server: 在下拉菜单中,选择你刚刚配置好的那个远程 SSH 服务器。这是最关键的一步!<br>
+> : 选择您项目中的 Dockerfile 文件。<br>
+> Image tag: 为即将在服务器上构建的镜像起个名字,例如 my-jfinal-app:latest。<br>
+> Container name: 为即将运行的容器起个名字,例如 jfinal-prod-container。<br>
+
+> 关键:配置环境变量<br>
+> 点击 Run options 右边的文件夹图标,打开 Modify options。<br>
+> 勾选 Environment variables。<br>
+> 在 Environment variables 输入框中,点击右侧的图标,添加服务器的数据库配置:<br>
+> DB_URL = jdbc:mysql://your_server_db_host:3306/dalian-nft-api<br>
+> DB_USER = root<br>
+> DB_PASSWORD = your_server_db_password<br>
+
+> 关键:配置端口映射<br>
+> 勾选 Bind ports。<br>
+> 添加一个映射,将服务器的端口(Host port)映射到容器的端口(Container port),例如 8080:8080。<br>

+ 67 - 0
package.xml

@@ -0,0 +1,67 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+  <!--
+  assembly 打包配置更多配置可参考官司方文档:
+  http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
+  -->
+
+  <id>release</id>
+
+  <!--
+      设置打包格式,可同时设置多种格式,常用格式有:dir、zip、tar、tar.gz
+      dir 格式便于在本地测试打包结果
+      zip 格式便于 windows 系统下解压运行
+      tar、tar.gz 格式便于 linux 系统下解压运行
+  -->
+  <formats>
+    <format>dir</format>
+    <format>zip</format>
+    <!-- <format>tar.gz</format> -->
+  </formats>
+
+  <!-- 打 zip 设置为 true 会在包在存在总目录,打 dir 时设置为 false 少层目录 -->
+  <includeBaseDirectory>true</includeBaseDirectory>
+
+  <fileSets>
+    <!-- src/main/resources 全部 copy 到 config 目录下 -->
+    <fileSet>
+      <directory>${basedir}/src/main/resources</directory>
+      <outputDirectory>config</outputDirectory>
+    </fileSet>
+
+    <!-- src/main/webapp 全部 copy 到 webapp 目录下 -->
+    <fileSet>
+      <directory>${basedir}/src/main/webapp</directory>
+      <outputDirectory>webapp</outputDirectory>
+    </fileSet>
+
+    <!-- 项目根下面的脚本文件 copy 到根目录下 -->
+    <fileSet>
+      <directory>${basedir}</directory>
+      <outputDirectory>./</outputDirectory>
+      <!-- 脚本文件在 linux 下的权限设为 755,无需 chmod 可直接运行 -->
+      <fileMode>755</fileMode>
+      <includes>
+        <include>*.sh</include>
+      </includes>
+    </fileSet>
+    
+    <fileSet>
+      <directory>${basedir}</directory>
+      <outputDirectory>./</outputDirectory>
+      <fileMode>755</fileMode>
+      <lineEnding>windows</lineEnding>
+      <includes>
+        <include>*.bat</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+
+  <!-- 依赖的 jar 包 copy 到 lib 目录下 -->
+  <dependencySets>
+    <dependencySet>
+      <outputDirectory>lib</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+</assembly>

+ 9 - 37
pom.xml

@@ -55,7 +55,7 @@
     </dependencies>
 
     <build>
-        <finalName>ethereum_viewer_interface</finalName>
+        <finalName>dalian-nft-api</finalName>
 
         <!--
             添加 includes 配置后,excludes 默认为所有文件 **/*.*,反之亦然
@@ -95,55 +95,27 @@
                     <source>1.8</source>
                     <target>1.8</target>
                     <encoding>UTF-8</encoding>
-                    <!-- java8 保留参数名编译参数 -->
                     <compilerArgument>-parameters</compilerArgument>
                     <compilerArguments><verbose /></compilerArguments>
                 </configuration>
             </plugin>
 
-            <!--
-                jar 包中的配置文件优先级高于 config 目录下的 "同名文件"
-                因此,打包时需要排除掉 jar 包中来自 src/main/resources 目录的
-                配置文件,否则部署时 config 目录中的同名配置文件不会生效
-            -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
-                <version>2.6</version>
-                <configuration>
-                    <excludes>
-                        <exclude>*.txt</exclude>
-                        <exclude>*.xml</exclude>
-                        <exclude>*.properties</exclude>
-                    </excludes>
-                </configuration>
-            </plugin>
-
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-assembly-plugin</artifactId>
-                <version>3.1.0</version>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.2.4</version>
                 <executions>
                     <execution>
-                        <id>make-assembly</id>
                         <phase>package</phase>
                         <goals>
-                            <goal>single</goal>
+                            <goal>shade</goal>
                         </goals>
-
                         <configuration>
-                            <!-- 打包生成的文件名 -->
-                            <finalName>${project.artifactId}</finalName>
-                            <!-- jar 等压缩文件在被打包进入 zip、tar.gz 时是否压缩,设置为 false 可加快打包速度 -->
-                            <recompressZippedFiles>false</recompressZippedFiles>
-                            <!-- 打包生成的文件是否要追加 release.xml 中定义的 id 值 -->
-                            <appendAssemblyId>true</appendAssemblyId>
-                            <!-- 指向打包描述文件 package.xml -->
-                            <descriptors>
-                                <descriptor>package.xml</descriptor>
-                            </descriptors>
-                            <!-- 打包结果输出的基础目录 -->
-                            <outputDirectory>${project.build.directory}/</outputDirectory>
+                            <transformers>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>common.jfinal.AppConfig</mainClass>
+                                </transformer>
+                            </transformers>
                         </configuration>
                     </execution>
                 </executions>