mirror of
https://github.com/yyhuni/xingrin.git
synced 2026-02-14 10:23:17 +08:00
85 lines
2.3 KiB
YAML
85 lines
2.3 KiB
YAML
name: Build and Push Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'backend/**'
|
|
- 'frontend/**'
|
|
- 'docker/**'
|
|
- '.github/workflows/**'
|
|
workflow_dispatch: # 手动触发
|
|
|
|
# 并发控制:同一分支只保留最新的构建,取消之前正在运行的
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: docker.io
|
|
IMAGE_PREFIX: yyhuni
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- image: xingrin-server
|
|
dockerfile: docker/server/Dockerfile
|
|
context: .
|
|
- image: xingrin-frontend
|
|
dockerfile: docker/frontend/Dockerfile
|
|
context: .
|
|
- image: xingrin-worker
|
|
dockerfile: docker/worker/Dockerfile
|
|
context: .
|
|
- image: xingrin-nginx
|
|
dockerfile: docker/nginx/Dockerfile
|
|
context: .
|
|
- image: xingrin-agent
|
|
dockerfile: docker/agent/Dockerfile
|
|
context: .
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Free disk space (for large builds like worker)
|
|
run: |
|
|
echo "=== Before cleanup ==="
|
|
df -h
|
|
# 删除不需要的大型软件包
|
|
sudo rm -rf /usr/share/dotnet
|
|
sudo rm -rf /usr/local/lib/android
|
|
sudo rm -rf /opt/ghc
|
|
sudo rm -rf /opt/hostedtoolcache/CodeQL
|
|
sudo docker image prune -af
|
|
echo "=== After cleanup ==="
|
|
df -h
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ${{ matrix.context }}
|
|
file: ${{ matrix.dockerfile }}
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:latest
|
|
${{ env.IMAGE_PREFIX }}/${{ matrix.image }}:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|