From 31ff5143b5fafa4cd0e8cacb1e6912d62cc00145 Mon Sep 17 00:00:00 2001 From: samzong Date: Thu, 14 Nov 2024 09:08:31 +0800 Subject: [PATCH 1/2] feat: build image Signed-off-by: samzong --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ docs/zh/mkdocs.yml | 4 ++-- nginx.conf | 22 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..39c95b3ad7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# 构建阶段 +FROM python:3.12-slim AS builder + +WORKDIR /docs + +# 安装 mkdocs 和依赖 +RUN pip install --no-cache-dir \ + mkdocs \ + mkdocs-material \ + mkdocs-minify-plugin \ + pymdown-extensions \ + mkdocs-swagger-ui-tag + +# 复制项目文件 +COPY docs/zh/ /docs + +# 构建静态文件 +RUN mkdocs build -f mkdocs.yml + +# Nginx 阶段 +FROM nginx:alpine + +# 复制 Nginx 配置文件 +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# 从构建阶段复制构建好的静态文件 +COPY --from=builder /docs/site /usr/share/nginx/html + +# 暴露端口 +EXPOSE 8000 + +# Nginx 使用 daemon off 模式运行 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docs/zh/mkdocs.yml b/docs/zh/mkdocs.yml index c19b7d3201..e1936d5886 100644 --- a/docs/zh/mkdocs.yml +++ b/docs/zh/mkdocs.yml @@ -134,8 +134,8 @@ markdown_extensions: - pymdownx.emoji: # emoji_index: !!python/name:materialx.emoji.twemoji # emoji_generator: !!python/name:material.extensions.emoji.to_svg - emoji_index: !!python/name:materialx.emoji.twemoji - emoji_generator: !!python/name:materialx.emoji.to_svg + emoji_index: !!python/name:material.extensions.emoji.twemoji + emoji_generator: !!python/name:material.extensions.emoji.to_svg - pymdownx.highlight: anchor_linenums: true - pymdownx.inlinehilite diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000000..b73fc7ce38 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 8000; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # 处理静态文件 + location / { + try_files $uri $uri/ =404; + } + + # 压缩配置 + gzip on; + gzip_types text/plain text/css application/javascript application/json; + gzip_min_length 1000; + + # 缓存配置 + location ~* \.(css|js|png|jpg|jpeg|gif|ico)$ { + expires 30d; + add_header Cache-Control "public, no-transform"; + } +} From 534758f708ad919ecf2aac098b90fcc509e0511a Mon Sep 17 00:00:00 2001 From: samzong Date: Thu, 14 Nov 2024 01:19:20 +0000 Subject: [PATCH 2/2] add workflow action Signed-off-by: GitHub --- .github/workflows/build-image.yaml | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/build-image.yaml diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000000..34f4906af1 --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,41 @@ +name: Build and Push Multi-Arch Docker Image + +on: + push: + tags: + - "*" + +permissions: + packages: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: linux/arm64, linux/amd64, darwin/arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository }}/sophdoc:latest + platforms: linux/amd64, linux/arm64, darwin/arm64