From e8b65edff7cd88ea03ab071af5c03fa0e306c838 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Wed, 27 Dec 2023 05:05:47 +0800 Subject: [PATCH] add all-in-one docker image build scripts --- CHANGELOG.md | 3 +- README.md | 23 +++++++-- docker/build/finalize.sh | 4 +- docker/config.yaml | 6 +-- docker/s6/meilisearch/setup | 3 ++ docker/s6/paopao-ce/setup | 2 + scripts/docker/Dockerfile.allinone-runner | 11 ++-- scripts/docker/README.md | 2 +- .../sqlite3/0008_content_type_alter.up.sql | 51 +++---------------- 9 files changed, 45 insertions(+), 60 deletions(-) create mode 100755 docker/s6/meilisearch/setup diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d65bf0ca..d049da8a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ All notable changes to paopao-ce are documented in this file. ## 0.6.0+dev ([`dev`](https://github.com/rocboss/paopao-ce/tree/dev)) -TODO; +### Added +- add all-in-one docker image build scripts. ## 0.5.2 ### Change diff --git a/README.md b/README.md index 69a5c8606..afd50c483 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ PaoPao主要由以下优秀的开源项目/工具构建 * [Mir](https://github.com/alimy/mir 'go-mir') * [Buf](https://github.com/bufbuild/buf 'buf') * [gRPC](https://github.com/grpc/grpc-go 'grpc-go') -* [Zinc](https://zinclabs.io/ 'zinc') +* [Meilisearch](https://https://www.meilisearch.com/ 'meilisearch') #### 前端: * [Naive UI](https://www.naiveui.com/) @@ -69,9 +69,7 @@ PaoPao主要由以下优秀的开源项目/工具构建 * Node.js (14+) * MySQL (5.7+) * Redis -* Zinc - -> Zinc是一款轻量级全文搜索引擎,可以查阅 安装 +* Meilisearch 以上环境版本为PaoPao官方的开发版本,仅供参考,其他版本的环境未进行充分测试 @@ -221,6 +219,23 @@ PaoPao主要由以下优秀的开源项目/工具构建 docker run -d -p 8010:80 your/paopao-ce:web ``` + * All-In-One: + ```sh + # 构建Image + docker buildx build --build-arg USE_DIST="yes" -t your/paopao-ce:all-in-one-latest -f Dockerfile.allinone . + + # 运行 + docker run --name paopao-ce-allinone -d -p 8000:8008 -p 7700:7700 -v ./data/custom:/app/custom -v ./data/meili_data:/app/meili_data your/paopao-ce:all-in-one-latest + + # 或者使用官方Image运行 + docker run --name paopao-ce-allinone -d -p 8000:8008 -p 7700:7700 -v ./data/custom:/app/custom -v ./data/meili_data:/app/meili_data bitbus/paopao-ce:all-in-one-latest + + # 或者使用官方Image运行 + 自定义config.yaml + docker run --name paopao-ce-allinone -d -p 8000:8008 -p 7700:7700 -v ./config.yaml:/app/config.yaml -v ./data/custom:/app/custom -v ./data/meili_data:/app/meili_data bitbus/paopao-ce:all-in-one-latest + ``` + > 注意在`config.yaml` 中`Meili.ApiKey`的值必须与容器中meili启动时设定的`MEILI_MASTER_KEY`环境变量值相同,默认为`paopao-meilisearch`. 可以在docker启动容器时通过`-e MEILI_MASTER_KEY=`设置该值。 + + ### 方式三. 使用 docker-compose 运行 ```sh git clone https://github.com/rocboss/paopao-ce.git diff --git a/docker/build/finalize.sh b/docker/build/finalize.sh index 004874a3a..c6fceb82b 100755 --- a/docker/build/finalize.sh +++ b/docker/build/finalize.sh @@ -4,8 +4,8 @@ set -xe # Create paopao user for paopao-ce addgroup -S paopao -adduser -G paopao -H -D -g 'paopao User' paopao -h /data/paopao -s /bin/bash && usermod -p '*' paopao && passwd -u paopao -echo "export PAOPAO_CUSTOM=${PAOPAO_CUSTOM}" >> /etc/profile +adduser -G paopao -H -D -g 'paopao User' paopao -h /app -s /bin/sh && usermod -p '*' paopao && passwd -u paopao +# echo "export PAOPAO_CUSTOM=${PAOPAO_CUSTOM}" >> /etc/profile # Final cleaning mv /app/docker/config.yaml /app/config.yaml diff --git a/docker/config.yaml b/docker/config.yaml index 7eb0f52ee..a34327275 100644 --- a/docker/config.yaml +++ b/docker/config.yaml @@ -21,7 +21,7 @@ SmsJuhe: Logger: # 日志通用配置 Level: debug # 日志级别 panic|fatal|error|warn|info|debug|trace LoggerFile: # 使用File写日志 - SavePath: custom/data/paopao-ce/logs + SavePath: custom/logs FileName: app FileExt: .log JWT: # 鉴权加密 @@ -37,7 +37,7 @@ ObjectStorage: # 对象存储通用配置 RetainInDays: 2 # 临时对象过期时间多少天 TempDir: tmp # 临时对象存放目录名 LocalOSS: # 本地文件OSS存储配置 - SavePath: custom/data/paopao-ce/oss + SavePath: custom/oss Secure: False Bucket: paopao Domain: 127.0.0.1:8008 @@ -45,7 +45,7 @@ Database: # Database通用配置 LogLevel: error # 日志级别 silent|error|warn|info TablePrefix: p_ # 表名前缀 Sqlite3: # Sqlite3数据库 - Path: custom/data/sqlite3/paopao-ce.db + Path: custom/paopao-ce.db Redis: InitAddress: - 127.0.0.1:6379 diff --git a/docker/s6/meilisearch/setup b/docker/s6/meilisearch/setup new file mode 100755 index 000000000..21239fd5a --- /dev/null +++ b/docker/s6/meilisearch/setup @@ -0,0 +1,3 @@ +#!/bin/sh + +cd /app/meili_data || exit 1 diff --git a/docker/s6/paopao-ce/setup b/docker/s6/paopao-ce/setup index b41d740f6..790a945da 100755 --- a/docker/s6/paopao-ce/setup +++ b/docker/s6/paopao-ce/setup @@ -1,3 +1,5 @@ #!/bin/sh +# sleep 10s等待meilisearch启动完成,这是笨方法,暂时先凑着,后面再找更靠谱的法子;这里之所以要等待meili启动完成,是因为paopao-ce首次启动时需要初始化一次meili的index,如果初始化失败就无法在后续使用。 +sleep 10 cd /app || exit 1 diff --git a/scripts/docker/Dockerfile.allinone-runner b/scripts/docker/Dockerfile.allinone-runner index 2cf3dc19a..b5528db65 100644 --- a/scripts/docker/Dockerfile.allinone-runner +++ b/scripts/docker/Dockerfile.allinone-runner @@ -1,4 +1,4 @@ -FROM getmeili/meilisearch:v1.4 as meilisearch +FROM getmeili/meilisearch:v1.5 as meilisearch FROM redis:7.2-alpine ENV TZ=Asia/Shanghai @@ -8,7 +8,7 @@ RUN apk update --quiet \ ca-certificates \ libgcc \ curl \ - s6 + s6 \ && update-ca-certificates WORKDIR /app @@ -17,13 +17,14 @@ COPY ./docker ./docker # add meilisearch and meilitool to the `/bin` so you can run it from anywhere # and it's easy to find. COPY --from=meilisearch /bin/meilisearch /bin/meilisearch -COPY --from-meilisearch /bin/meilitool /bin/meilitool +COPY --from=meilisearch /bin/meilitool /bin/meilitool # To stay compatible with the older version of the container (pre v0.27.0) we're # going to symlink the meilisearch binary in the path to `/meilisearch` RUN ln -s /bin/meilisearch /meilisearch - +ENV MEILI_HTTP_ADDR 0.0.0.0:7700 +ENV MEILI_SERVER_PROVIDER docker ENV MEILI_DB_PATH=/app/meili_data -VOLUME ["/app/meili_data"] +ENV MEILI_MASTER_KEY=paopao-meilisearch RUN ./docker/build/finalize.sh diff --git a/scripts/docker/README.md b/scripts/docker/README.md index 5bde71be4..7a374060a 100644 --- a/scripts/docker/README.md +++ b/scripts/docker/README.md @@ -3,5 +3,5 @@ ```sh docker build -t bitbus/paopao-ce-backend-builder:latest -f Dockerfile.backend-builder . docker build -t bitbus/paopao-ce-backend-runner:latest -f Dockerfile.backend-runner . -docker build -t bitbus/paopao-ce-allinone-runner:latest -f Dockerfile.allinone-runner . +docker build -t bitbus/paopao-ce-allinone-runner:latest -f scripts/docker/Dockerfile.allinone-runner . ``` \ No newline at end of file diff --git a/scripts/migration/sqlite3/0008_content_type_alter.up.sql b/scripts/migration/sqlite3/0008_content_type_alter.up.sql index ba4db9e19..1059dc9d5 100644 --- a/scripts/migration/sqlite3/0008_content_type_alter.up.sql +++ b/scripts/migration/sqlite3/0008_content_type_alter.up.sql @@ -1,7 +1,5 @@ PRAGMA foreign_keys=off; -BEGIN TRANSACTION; - ALTER TABLE p_post_content RENAME TO _p_post_content; ALTER TABLE p_comment_content RENAME TO _p_comment_content; @@ -53,46 +51,6 @@ CREATE TABLE p_comment_reply PRIMARY KEY ("id") ); --- ---------------------------- --- Indexes structure for table p_post_content --- ---------------------------- -CREATE INDEX "idx_post_content_post_id" -ON "p_post_content" ( - "post_id" ASC -); -CREATE INDEX "idx_post_content_user_id" -ON "p_post_content" ( - "user_id" ASC -); - --- ---------------------------- --- Indexes structure for table p_comment_reply --- ---------------------------- -CREATE INDEX "idx_comment_reply_comment_id" -ON "p_comment_reply" ( - "comment_id" ASC -); - --- ---------------------------- --- Indexes structure for table p_comment_content --- ---------------------------- -CREATE INDEX "idx_comment_content_comment_id" -ON "p_comment_content" ( - "comment_id" ASC -); -CREATE INDEX "idx_comment_content_sort" -ON "p_comment_content" ( - "sort" ASC -); -CREATE INDEX "idx_comment_content_type" -ON "p_comment_content" ( - "type" ASC -); -CREATE INDEX "idx_comment_content_user_id" -ON "p_comment_content" ( - "user_id" ASC -); - INSERT INTO p_post_content (id, post_id, user_id, content, `type`, sort, created_on, modified_on, deleted_on, is_del) SELECT id, post_id, user_id, content, `type`, sort, created_on, modified_on, deleted_on, is_del FROM _p_post_content; @@ -112,10 +70,12 @@ DROP TABLE _p_comment_reply; -- ---------------------------- -- Indexes structure for table p_post_content -- ---------------------------- +DROP INDEX IF EXISTS "idx_post_content_post_id"; CREATE INDEX "idx_post_content_post_id" ON "p_post_content" ( "post_id" ASC ); +DROP INDEX IF EXISTS "idx_post_content_user_id"; CREATE INDEX "idx_post_content_user_id" ON "p_post_content" ( "user_id" ASC @@ -124,6 +84,7 @@ ON "p_post_content" ( -- ---------------------------- -- Indexes structure for table p_comment_reply -- ---------------------------- +DROP INDEX IF EXISTS "idx_comment_reply_comment_id"; CREATE INDEX "idx_comment_reply_comment_id" ON "p_comment_reply" ( "comment_id" ASC @@ -132,23 +93,25 @@ ON "p_comment_reply" ( -- ---------------------------- -- Indexes structure for table p_comment_content -- ---------------------------- +DROP INDEX IF EXISTS "idx_comment_content_comment_id"; CREATE INDEX "idx_comment_content_comment_id" ON "p_comment_content" ( "comment_id" ASC ); +DROP INDEX IF EXISTS "idx_comment_content_sort"; CREATE INDEX "idx_comment_content_sort" ON "p_comment_content" ( "sort" ASC ); +DROP INDEX IF EXISTS "idx_comment_content_type"; CREATE INDEX "idx_comment_content_type" ON "p_comment_content" ( "type" ASC ); +DROP INDEX IF EXISTS "idx_comment_content_user_id"; CREATE INDEX "idx_comment_content_user_id" ON "p_comment_content" ( "user_id" ASC ); -COMMIT; - PRAGMA foreign_keys=on;