Skip to content

【Projects/web_api】GitHub Workflow Docker镜像打包与上传 & 优化Dockerfile占用空间 #1767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/dockerx-web-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Docker Build Image-WebAPI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Clean up unnecessary large folders
run: |
# Delete unnecessary large folders
sudo rm -rf /opt/hostedtoolcache
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/local/share/boost
# Clean apt cache
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
# Show available disk space
df -h

- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: Login to Aliyun Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./projects/web_api
file: ./projects/web_api/Dockerfile
push: true
tags: ${{ secrets.DOCKER_REGISTRY }}/${{secrets.DOCKER_NAMESPACE}}/${{ github.event.repository.name }}:latest
cache-from: type=registry,ref=${{ secrets.DOCKER_REGISTRY }}/${{secrets.DOCKER_NAMESPACE}}/${{ github.event.repository.name }}:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_REGISTRY }}/${{secrets.DOCKER_NAMESPACE}}/${{ github.event.repository.name }}:buildcache,mode=max
11 changes: 6 additions & 5 deletions projects/web_api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Build Python dependencies
COPY requirements.txt .
RUN python -m venv /app/venv && \
. /app/venv/bin/activate && \
pip install -r requirements.txt && \
pip install --no-cache-dir -r requirements.txt && \
pip uninstall -y paddlepaddle && \
pip install -i https://www.paddlepaddle.org.cn/packages/stable/cu118/ \
paddlepaddle-gpu==3.0.0rc1
pip install --no-cache-dir -i https://www.paddlepaddle.org.cn/packages/stable/cu118/ \
paddlepaddle-gpu==3.0.0rc1 && \
find /app/venv -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true

# Download models
COPY download_models.py .
Expand All @@ -48,7 +49,7 @@ RUN apt-get update && \
libglib2.0-0 \
libgomp1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Create volume for paddleocr models
RUN mkdir -p /root/.paddleocr
Expand Down
8 changes: 8 additions & 0 deletions signatures/version1/cla.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@
"created_at": "2025-02-22T07:15:35Z",
"repoId": 765083837,
"pullRequestNo": 1743
},
{
"name": "nadahlberg",
"id": 58701810,
"comment_id": 2676309097,
"created_at": "2025-02-22T17:04:14Z",
"repoId": 765083837,
"pullRequestNo": 1748
}
]
}