Workflow tự động build, tối ưu Docker image với docker-slim và push lên GitHub Container Registry.
Workflow chính để build và tối ưu Docker images:
Trigger:
- Push to
mainhoặcdevelopbranch - Pull requests to
main - Manual dispatch
Các bước thực hiện:
- ✅ Checkout source code
- 🔧 Setup Docker Buildx
- 🔐 Login to GitHub Container Registry
- 📦 Build Docker image gốc
- 📊 Thu thập size của image gốc
- ⚙️ Cài đặt docker-slim
- 🎯 Tối ưu image với docker-slim
- 📊 Thu thập size của image đã tối ưu
- 📈 So sánh và hiển thị kết quả
- 🚀 Push images đã tối ưu lên registry
- 💬 Comment kết quả trên PR (nếu là PR)
Workflow sẽ tự động so sánh và hiển thị:
- Size của image gốc
- Size của image đã tối ưu
- Phần trăm giảm sau khi tối ưu
Kết quả được hiển thị trong:
- GitHub Actions logs
- GitHub Actions summary
- PR comments (nếu là PR)
# Pull latest version
docker pull ghcr.io/cong-ty-tnnh-q-tech/createvideo:latest
# Pull by branch
docker pull ghcr.io/cong-ty-tnnh-q-tech/createvideo:main
# Pull by commit SHA
docker pull ghcr.io/cong-ty-tnnh-q-tech/createvideo:main-abc1234# WebUI
docker run -v $(pwd)/config.toml:/MoneyPrinterTurbo/config.toml \
-v $(pwd)/storage:/MoneyPrinterTurbo/storage \
-p 8501:8501 \
ghcr.io/cong-ty-tnnh-q-tech/createvideo:latest
# API
docker run -v $(pwd)/config.toml:/MoneyPrinterTurbo/config.toml \
-v $(pwd)/storage:/MoneyPrinterTurbo/storage \
-p 8080:8080 \
ghcr.io/cong-ty-tnnh-q-tech/createvideo:latest \
python3 main.pyDocker-slim được cấu hình với các options sau:
--http-probe=false: Tắt HTTP probing--continue-after=20: Tiếp tục sau 20 giây--include-path: Bao gồm các đường dẫn cần thiết/MoneyPrinterTurbo: Application code/usr/local/lib/python3.11: Python libraries/usr/local/bin: Python binaries/usr/bin/ffmpeg: FFmpeg binary/usr/bin/convert: ImageMagick binary/etc/ImageMagick-6: ImageMagick config
--include-bin=/usr/bin/git: Git binary--preserve-path: Preserve directories/tmp: Temporary files/root/.cache: Cache directory
Workflow sử dụng các environment variables sau:
REGISTRY:ghcr.io- GitHub Container RegistryIMAGE_NAME:${{ github.repository }}- Repository name
Workflow cần các permissions sau:
contents: read- Đọc repository codepackages: write- Push images to GitHub Container Registry
Images được tag tự động với:
latest- Latest commit on default branchmainhoặcdevelop- Branch namepr-123- Pull request numbermain-abc1234- Branch + commit SHA- Semantic version tags (nếu có)
Kiểm tra kết quả build:
- Vào tab Actions trên GitHub repository
- Chọn workflow run mới nhất
- Xem Summary để thấy so sánh size
- Xem logs chi tiết cho từng step
Điều chỉnh docker-slim parameters trong workflow:
- Thêm
--include-pathcho các dependencies còn thiếu - Điều chỉnh
--continue-afterđể tăng thời gian analysis
Kiểm tra logs và thêm các paths cần thiết vào --include-path hoặc --preserve-path.
Kiểm tra:
- Repository có enable GitHub Packages
- Workflow có permission
packages: write - Personal Access Token (nếu dùng) có scope
write:packages