Skip to content

Commit

Permalink
Merge pull request #62 from sophongo/build/docker-image
Browse files Browse the repository at this point in the history
Build/docker image
  • Loading branch information
samzong authored Nov 14, 2024
2 parents ac762a6 + 534758f commit 7cecd53
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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;"]
4 changes: 2 additions & 2 deletions docs/zh/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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";
}
}

0 comments on commit 7cecd53

Please sign in to comment.