forked from DaoCloud/DaoCloud-docs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from sophongo/build/docker-image
Build/docker image
- Loading branch information
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |