diff --git a/.dockerignore b/.dockerignore index 7bde2ad..a7680f7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,17 +1,7 @@ # Docker builds read only the plain JAR, Maven runtime dependencies and config. -* +** !Dockerfile -!docker/ -!docker/Dockerfile.base -!docker/kkfileview-base/ -!docker/kkfileview-base/fonts/ !docker/kkfileview-base/fonts/** -!server/ -!server/target/ !server/target/eap-fileview-*.jar -!server/target/dependency/ !server/target/dependency/*.jar -!server/src/ -!server/src/main/ -!server/src/main/config/ !server/src/main/config/application.properties diff --git a/.env.example b/.env.example index ff12c32..8dbd9d0 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ EAP_FILEVIEW_VERSION=3.0.3 EAP_FILEVIEW_PORT=18012 EAP_FILEVIEW_IMAGE=ghcr.io/eaopen/eap-fileview:3.0.2 -EAP_FILEVIEW_BASE_IMAGE=ghcr.io/eaopen/eap-fileview-base:java21-sb41-r2 +EAP_FILEVIEW_BUILD_IMAGE=eap-fileview:dev KK_BASE_URL=http://localhost:18012/fileview/ KK_TRUST_HOST=files.example.org KK_NOT_TRUST_HOST=default diff --git a/.github/workflows/base-image.yml b/.github/workflows/base-image.yml index 3500b27..16a4528 100644 --- a/.github/workflows/base-image.yml +++ b/.github/workflows/base-image.yml @@ -16,6 +16,9 @@ jobs: cache: maven - name: Resolve stable dependency tree run: mvn -B -pl server -am -DskipTests clean package + - uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 with: @@ -26,7 +29,8 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: docker/Dockerfile.base + file: Dockerfile + target: runtime push: true platforms: linux/amd64,linux/arm64 tags: ghcr.io/eaopen/eap-fileview-base:java21-sb41-r2 diff --git a/.github/workflows/container-smoke.yml b/.github/workflows/container-smoke.yml index 14183a1..eb03c0c 100644 --- a/.github/workflows/container-smoke.yml +++ b/.github/workflows/container-smoke.yml @@ -10,34 +10,16 @@ permissions: jobs: smoke: runs-on: ubuntu-latest + env: + KK_BASE_URL: http://localhost:18012/fileview/ + KK_TRUST_HOST: localhost steps: - - name: Start published Java 21 and LibreOffice image - run: | - set -euo pipefail - docker pull ghcr.io/eaopen/eap-fileview:3.0.2 - docker run -d --name fileview-smoke \ - --publish 127.0.0.1:18012:8012 \ - --env KK_CONTEXT_PATH=/fileview \ - --env KK_SERVER_PORT=8012 \ - --env KK_BASE_URL=http://localhost:18012/fileview/ \ - --env KK_TRUST_HOST=localhost \ - --env KK_FILE_DIR=/tmp/fileview-smoke \ - ghcr.io/eaopen/eap-fileview:3.0.2 - trap 'docker logs --tail 75 fileview-smoke || true; docker rm -f fileview-smoke || true' EXIT - ready=false - for i in $(seq 1 90); do - if ! docker inspect -f '{{.State.Running}}' fileview-smoke | grep -q true; then - echo 'Container exited before becoming healthy' - exit 1 - fi - code="$(curl --silent --output /tmp/health.out --write-out '%{http_code}' \ - http://127.0.0.1:18012/fileview/actuator/health || true)" - if [ "$code" = "200" ]; then - grep -q '"status":"UP"' /tmp/health.out - ready=true - break - fi - sleep 4 - done - [ "$ready" = true ] || { echo 'Viewer health endpoint never became UP'; exit 1; } - echo 'Viewer container healthy; Java/LibreOffice startup successful' + - uses: actions/checkout@v4 + - name: Start published image with the deployment configuration + run: docker compose up -d --pull always --wait --wait-timeout 180 + - name: Verify health through the published port + run: curl -fsS http://127.0.0.1:18012/fileview/actuator/health | jq -e '.status == "UP"' + - if: failure() + run: docker compose logs --tail 75 + - if: always() + run: docker compose down --volumes diff --git a/.github/workflows/images.yml b/.github/workflows/images.yml index 48ed10c..cefbfc2 100644 --- a/.github/workflows/images.yml +++ b/.github/workflows/images.yml @@ -27,6 +27,9 @@ jobs: fi - name: Package only plain JAR run: mvn -B -pl server -am -DskipTests clean package + - uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 with: @@ -43,5 +46,7 @@ jobs: build-args: | APP_VERSION=${{ steps.version.outputs.value }} tags: ghcr.io/eaopen/eap-fileview:${{ steps.version.outputs.value }} - cache-from: type=gha,scope=fileview-app + cache-from: | + type=gha,scope=fileview-app + type=gha,scope=fileview-stable-base cache-to: type=gha,mode=max,scope=fileview-app diff --git a/AGENTS.md b/AGENTS.md index f9d6f0e..67c8043 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,7 @@ Active coding guidance for this repository. The original kkFileView agent instru - `server/src/main/resources/web/`: FreeMarker viewer templates. - `server/src/main/resources/static/`: viewer JS/CSS/assets. - `server/src/main/config/`: application and test runtime properties. -- `Dockerfile`: thin app layer; `docker/Dockerfile.base`: stable Java/LibreOffice/dependencies layer. +- `Dockerfile`: shared `runtime` stage for Java/LibreOffice/dependencies and a thin `application` stage. - `compose.yaml` and `compose.build.yaml`: pull-only and local-build Compose configurations. - `.github/workflows/`: active GitHub CI, CNB/Central Maven publishing and image workflows. - `doc/kkfileview/`: preserved upstream README, original AGENTS, CI/E2E notes. These are **not current runbooks**. diff --git a/Dockerfile b/Dockerfile index fe6e3e8..31ebb97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # Self-contained runtime: avoid dependency on a separately published GHCR base package. -FROM ubuntu:24.04 +FROM ubuntu:24.04 AS runtime ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -15,6 +15,8 @@ WORKDIR /opt/eap-fileview # Copy Maven runtime jars resolved by the release build. COPY server/target/dependency/ ./lib/ ENV LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 + +FROM runtime AS application ARG APP_VERSION=3.0.3 COPY server/target/eap-fileview-${APP_VERSION}.jar ./app.jar COPY server/src/main/config/application.properties ./config/application.properties diff --git a/README.cn.md b/README.cn.md index 5e80d35..24347f8 100644 --- a/README.cn.md +++ b/README.cn.md @@ -71,14 +71,16 @@ flowchart LR ```bash cp .env.example .env # 修改 .env 中的 KK_BASE_URL / KK_TRUST_HOST 等配置 -docker compose up -d +docker compose up -d --wait --wait-timeout 180 ``` +升级前记录当前 `EAP_FILEVIEW_IMAGE`,将其改为目标版本标签或摘要,执行 `docker compose pull` 后重跑启动命令。需要回退时恢复原镜像引用并重跑这两步。Compose 等待健康检查通过,预览缓存保存在命名卷中。 + 自行构建开发镜像时,先执行 Maven clean package;Dockerfile 自包含运行环境,不需要预先构建基础镜像: ```bash -docker compose -f compose.yaml -f compose.build.yaml build -docker compose -f compose.yaml -f compose.build.yaml up -d +mvn -B -pl server -am -DskipTests clean package +docker compose -f compose.yaml -f compose.build.yaml up -d --build --wait --wait-timeout 180 ``` **当前应用镜像自包含** Java 21、LibreOffice、字体、运行依赖和普通 JAR;单独的基础镜像属于可选产物,并非当前 Dockerfile 的前置依赖。默认监听容器内 8012,Compose 映射本机 `127.0.0.1:18012`,上下文路径 `/fileview`。镜像是否已公开可拉取以 [GitHub Actions 发布记录](https://github.com/eaopen/eap-fileview/actions) 为准。 diff --git a/README.md b/README.md index 02844d7..34f26fc 100644 --- a/README.md +++ b/README.md @@ -73,14 +73,16 @@ Using the last **published** 3.0.2 image (Boot 4.1.1); 3.0.3 is not yet released ```bash cp .env.example .env # Configure KK_BASE_URL and KK_TRUST_HOST inside .env -docker compose up -d +docker compose up -d --wait --wait-timeout 180 ``` +Before upgrading, record the current `EAP_FILEVIEW_IMAGE`. Set it to the target version tag or digest, run `docker compose pull`, then repeat the startup command. To roll back, restore the previous image reference and repeat both commands. Compose waits for the health check and keeps the preview cache in its named volume. + To build the unreleased version locally, first run Maven clean package. The Dockerfile is self-contained: ```bash -docker compose -f compose.yaml -f compose.build.yaml build -docker compose -f compose.yaml -f compose.build.yaml up -d +mvn -B -pl server -am -DskipTests clean package +docker compose -f compose.yaml -f compose.build.yaml up -d --build --wait --wait-timeout 180 ``` The current application Dockerfile is self-contained: Java 21, LibreOffice, fonts, runtime dependencies and the ordinary JAR. The separately published base image is optional and not used by this Dockerfile. Compose defaults to `127.0.0.1:18012` and the `/fileview` context path. Verify actual [image publication status](https://github.com/eaopen/eap-fileview/actions) before attempting a pull. diff --git a/compose.build.yaml b/compose.build.yaml index 68e139c..9cd20a4 100644 --- a/compose.build.yaml +++ b/compose.build.yaml @@ -2,6 +2,7 @@ services: eap-fileview: image: ${EAP_FILEVIEW_BUILD_IMAGE:-eap-fileview:dev} + pull_policy: build build: context: . dockerfile: Dockerfile diff --git a/compose.yaml b/compose.yaml index 391d38c..50e66b0 100644 --- a/compose.yaml +++ b/compose.yaml @@ -17,6 +17,20 @@ services: KK_OFFICE_PREVIEW_TYPE: pdf volumes: - fileview-preview-cache:/opt/eap-fileview/file + healthcheck: + test: + - CMD + - bash + - -ec + - | + exec 3<>/dev/tcp/127.0.0.1/8012 + printf 'GET /fileview/actuator/health HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n' >&3 + read -r proto status rest <&3 + test "$$status" = 200 + interval: 15s + timeout: 5s + retries: 4 + start_period: 60s restart: unless-stopped volumes: diff --git a/doc/EXTENSION_RELEASE.md b/doc/EXTENSION_RELEASE.md index 2f1dfce..4969437 100644 --- a/doc/EXTENSION_RELEASE.md +++ b/doc/EXTENSION_RELEASE.md @@ -42,8 +42,8 @@ Ubuntu 24.04 + OpenJDK 21 + LibreOffice + 开源中文字体 + **Maven 已解析 该镜像只在 Java/LibreOffice/字体/依赖变化时才考虑手动构建;**当前 Dockerfile 自包含,不需要预先构建此基础镜像**。旧的 r1 镜像标签不能覆盖。 ```bash -mvn -B -pl server -am -DskipTests package -docker build -f docker/Dockerfile.base \ +mvn -B -pl server -am -DskipTests clean package +docker build --target runtime \ -t ghcr.io/eaopen/eap-fileview-base:java21-sb41-r2 . ``` @@ -58,7 +58,7 @@ docker compose --env-file .env.example -f compose.yaml -f compose.build.yaml bui # 正常部署(镜像已经发布后): cp .env.example .env # 修改来源主机白名单和公网访问地址 -docker compose up -d +docker compose up -d --wait --wait-timeout 180 ``` GHCR 最终镜像工作流:`.github/workflows/images.yml`,采用 `revision` 作为应用标签;下一次正式版本的 Git tag 应为 `v3.0.3`。 diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base deleted file mode 100644 index c542c82..0000000 --- a/docker/Dockerfile.base +++ /dev/null @@ -1,17 +0,0 @@ -# syntax=docker/dockerfile:1 -# Build infrequently: JRE, LibreOffice, fonts, and stable runtime dependency JARs. -FROM ubuntu:24.04 -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - openjdk-21-jre-headless libreoffice-nogui fontconfig \ - fonts-noto-cjk fonts-liberation fonts-wqy-microhei fonts-wqy-zenhei \ - tzdata locales \ - && locale-gen zh_CN.UTF-8 \ - && apt-get clean && rm -rf /var/lib/apt/lists/* -COPY docker/kkfileview-base/fonts/ /usr/local/share/fonts/eap/ -RUN fc-cache -f -WORKDIR /opt/eap-fileview -# Stable intermediate image carries Maven resolved runtime jars, not the app. -COPY server/target/dependency/ ./lib/ -ENV LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 diff --git a/docker/kkfileview-base/README.cn.md b/docker/kkfileview-base/README.cn.md index 5305f8e..7b424fd 100644 --- a/docker/kkfileview-base/README.cn.md +++ b/docker/kkfileview-base/README.cn.md @@ -1,3 +1,3 @@ # 稳定镜像字体资源 -本目录只保留额外字体资源。新版本以仓库 docker/Dockerfile.base 构建基础镜像,不是从本目录独立构建。参考 ../../doc/EXTENSION_RELEASE.md。 +本目录只保留额外字体资源。新版本以仓库 `docker build --target runtime .` 构建基础镜像,不是从本目录独立构建。参考 ../../doc/EXTENSION_RELEASE.md。 diff --git a/docker/kkfileview-base/README.md b/docker/kkfileview-base/README.md index d457d20..d68a7e9 100644 --- a/docker/kkfileview-base/README.md +++ b/docker/kkfileview-base/README.md @@ -1,3 +1,3 @@ # Stable runtime fonts only -This folder contains optional extra fonts. The supported build is now docker/Dockerfile.base at the repository root. See ../../doc/EXTENSION_RELEASE.md. +This folder contains optional extra fonts. The supported build is now `docker build --target runtime .` at the repository root. See ../../doc/EXTENSION_RELEASE.md.