支持通过docker构建镜像
This commit is contained in:
57
README.md
57
README.md
@@ -67,6 +67,63 @@ sudo systemctl start document-server
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 构建Docker镜像以便于通过Docker容器运行
|
||||||
|
|
||||||
|
1.先通过maven打包[jodconverter-document-server](document-server/jodconverter-document-server)
|
||||||
|
|
||||||
|
2.执行[build.sh](document-docker/build.sh)
|
||||||
|
|
||||||
|
3.通过`docker load -i document-server-1.0.tar.gz`导入镜像,通过`docker ps | grep document-server`查看镜像版本
|
||||||
|
|
||||||
|
4.编写`docker-compose.yml`,在其中指定镜像启动
|
||||||
|
```yml
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
document-server:
|
||||||
|
image: document-server:1.0
|
||||||
|
environment:
|
||||||
|
- CUSTOM_PORT=3000
|
||||||
|
- CUSTOM_HTTPS_PORT=3001
|
||||||
|
- DOCUMENT_SERVER_PORT=9004
|
||||||
|
- PORT_NUMBERS=2001,2002,2003
|
||||||
|
- MAX_TASKS_PER_PROCESS=100
|
||||||
|
ports:
|
||||||
|
# 用于通过http访问libreoffice
|
||||||
|
- 3000:3000
|
||||||
|
# 用于通过https访问libreoffice
|
||||||
|
- 3001:3001
|
||||||
|
# 文书转换服务端口,用于document-api远程调用document-server
|
||||||
|
- 9004:9004
|
||||||
|
volumes:
|
||||||
|
# libreoffice的配置保存路径
|
||||||
|
- ./config:/config
|
||||||
|
# document-server的配置,如不指定,则以默认为准。建议通过环境变量修改关键配置
|
||||||
|
- ./application.yml:/app/application.yml
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
`application.yml`默认内容如下:
|
||||||
|
```yml
|
||||||
|
server:
|
||||||
|
port: ${DOCUMENT_SERVER_PORT:9004}
|
||||||
|
|
||||||
|
jodconverter:
|
||||||
|
local:
|
||||||
|
# 启动本地转换
|
||||||
|
enabled: true
|
||||||
|
# macOS下:program/soffice 的 program 所在目录 或 MacOS/soffice 的 MacOS 所在目录
|
||||||
|
# windows下:program/soffice.exe 的 program 所在目录
|
||||||
|
# linux下:program/soffice.bin 的 program 所在目录
|
||||||
|
# 如果不配置,则自动查找
|
||||||
|
#office-home: /Applications/LibreOffice.app/Contents
|
||||||
|
# 一个端口表示一个常驻进程,默认只有一个进程,端口为2002
|
||||||
|
port-numbers: ${PORT_NUMBERS:2002}
|
||||||
|
# 每个进程最多处理多个任务,默认为200
|
||||||
|
max-tasks-per-process: ${MAX_TASKS_PER_PROCESS:200}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## windows下才用[docto-document-server](document-server/docto-document-server)
|
## windows下才用[docto-document-server](document-server/docto-document-server)
|
||||||
|
|
||||||
通过`java -jar ./document-server-2.0.0.jar --spring.config.location=./application.yml`执行
|
通过`java -jar ./document-server-2.0.0.jar --spring.config.location=./application.yml`执行
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.optima</groupId>
|
<groupId>com.optima</groupId>
|
||||||
<artifactId>document</artifactId>
|
<artifactId>document</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>document-api</artifactId>
|
<artifactId>document-api</artifactId>
|
||||||
<name>Document API</name>
|
<name>Document API</name>
|
||||||
<description>文档操作api</description>
|
<description>文档操作api</description>
|
||||||
<properties>
|
<properties>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.16.20</version>
|
<version>1.16.20</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- 1. 使用 maven-jar-plugin 打包当前模块的代码(不含依赖) -->
|
<!-- 1. 使用 maven-jar-plugin 打包当前模块的代码(不含依赖) -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- 2. 使用 maven-source-plugin 生成源码 JAR -->
|
<!-- 2. 使用 maven-source-plugin 生成源码 JAR -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>3.2.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<id>attach-sources</id>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar-no-fork</goal>
|
<goal>jar-no-fork</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- 3. 跳过可执行 JAR 的生成 -->
|
<!-- 3. 跳过可执行 JAR 的生成 -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skip>true</skip>
|
<skip>true</skip>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
34
document-docker/Dockerfile
Normal file
34
document-docker/Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
FROM lscr.io/linuxserver/libreoffice:latest
|
||||||
|
|
||||||
|
RUN echo "https://mirrors.tencent.com/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/main/" > /etc/apk/repositories
|
||||||
|
RUN echo "https://mirrors.tencent.com/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/community/" >> /etc/apk/repositories
|
||||||
|
|
||||||
|
RUN apk update
|
||||||
|
RUN apk add --no-cache openjdk17-jre
|
||||||
|
RUN rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN mkdir -p /app/logs
|
||||||
|
|
||||||
|
COPY app/document-server-*.jar /app/application.jar
|
||||||
|
COPY app/application.yml /app/application.yml
|
||||||
|
|
||||||
|
COPY fonts /usr/share/fonts/truetype
|
||||||
|
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
#see https://hub.docker.com/r/linuxserver/libreoffice
|
||||||
|
ENV PUID=1000
|
||||||
|
ENV PGID=1000
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
ENV LC_ALL=zh_CN.UTF-8
|
||||||
|
ENV TITLE="Libre Office"
|
||||||
|
ENV CUSTOM_PORT=3000
|
||||||
|
ENV CUSTOM_HTTPS_PORT1=3001
|
||||||
|
|
||||||
|
ENV DOCUMENT_SERVER_PORT=9004
|
||||||
|
ENV PORT_NUMBERS=2002
|
||||||
|
ENV MAX_TASKS_PER_PROCESS=200
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
34
document-docker/build.sh
Normal file
34
document-docker/build.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 设置Maven路径
|
||||||
|
export PATH=$PATH:/Volumes/Working/Software/apache-maven-3.9.3/bin
|
||||||
|
|
||||||
|
# 创建临时目录存放需要运行的jar
|
||||||
|
mkdir -p app
|
||||||
|
|
||||||
|
# 构建jar
|
||||||
|
echo 构建jar
|
||||||
|
mvn -f ../document-server/jodconverter-document-server/pom.xml clean package -Dmaven.test.skip=true
|
||||||
|
echo jar构建完成
|
||||||
|
|
||||||
|
# 复制所需文件
|
||||||
|
cp ../document-server/jodconverter-document-server/target/document-server-*.jar app/
|
||||||
|
cp ../document-server/jodconverter-document-server/target/application.yml app/
|
||||||
|
|
||||||
|
# 执行构建
|
||||||
|
|
||||||
|
#amd64
|
||||||
|
echo 开始构建amd64镜像...
|
||||||
|
docker buildx build --platform linux/amd64 -t document-server:1.0 ./
|
||||||
|
rm -rf document-server-1.0.tar.gz
|
||||||
|
docker save document-server:1.0 | gzip > document-server-1.0.tar.gz
|
||||||
|
echo amd64镜像构建成功.
|
||||||
|
|
||||||
|
#arm64
|
||||||
|
echo 开始构建arm64镜像...
|
||||||
|
docker buildx build --platform linux/arm64 -t document-server:1.0.arm64 ./
|
||||||
|
rm -rf document-server-1.0.arm64.tar.gz
|
||||||
|
docker save document-server:1.0.arm64 | gzip > document-server-1.0.arm64.tar.gz
|
||||||
|
echo arm64镜像构建成功.
|
||||||
|
|
||||||
|
# 清理临时文件
|
||||||
|
rm -rf app
|
||||||
20
document-docker/entrypoint.sh
Normal file
20
document-docker/entrypoint.sh
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# 确保目录存在
|
||||||
|
mkdir -p /etc/services.d/java
|
||||||
|
|
||||||
|
# 创建Java服务启动脚本
|
||||||
|
cat > /etc/services.d/java/run <<EOF
|
||||||
|
#!/bin/sh
|
||||||
|
exec java -jar /app/application.jar \
|
||||||
|
--server.port=${DOCUMENT_SERVER_PORT} \
|
||||||
|
--spring.config.location=/app/application.yml \
|
||||||
|
--jodconverter.local.port-numbers=${PORT_NUMBERS} \
|
||||||
|
--jodconverter.local.max-tasks-per-process=${MAX_TASKS_PER_PROCESS}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 设置可执行权限
|
||||||
|
chmod +x /etc/services.d/java/run
|
||||||
|
|
||||||
|
# 启动s6-overlay(它会自动管理所有服务)
|
||||||
|
exec /init
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 9004
|
port: ${DOCUMENT_SERVER_PORT:9004}
|
||||||
|
|
||||||
jodconverter:
|
jodconverter:
|
||||||
local:
|
local:
|
||||||
@@ -9,8 +9,8 @@ jodconverter:
|
|||||||
# windows下:program/soffice.exe 的 program 所在目录
|
# windows下:program/soffice.exe 的 program 所在目录
|
||||||
# linux下:program/soffice.bin 的 program 所在目录
|
# linux下:program/soffice.bin 的 program 所在目录
|
||||||
# 如果不配置,则自动查找
|
# 如果不配置,则自动查找
|
||||||
office-home: /Applications/LibreOffice.app/Contents
|
#office-home: /Applications/LibreOffice.app/Contents
|
||||||
# 一个端口表示一个常驻进程,默认只有一个进程,端口为2002
|
# 一个端口表示一个常驻进程,默认只有一个进程,端口为2002
|
||||||
port-numbers: [ 2002 ]
|
port-numbers: ${PORT_NUMBERS:2002}
|
||||||
# 每个进程最多处理多个任务,默认为200
|
# 每个进程最多处理多个任务,默认为200
|
||||||
max-tasks-per-process: 200
|
max-tasks-per-process: ${MAX_TASKS_PER_PROCESS:200}
|
||||||
|
|||||||
Reference in New Issue
Block a user