refactor(ci): use container-based approach like license project
Build and Deploy / Build Frontend (push) Successful in 2m2s
Build and Deploy / Build and Push Docker Image (push) Failing after 1s

- Split into build and docker jobs
- Use node:22 container for frontend build
- Add pnpm cache for faster builds
- Support multiple package managers for Docker CLI installation
This commit is contained in:
2026-08-07 21:28:59 +08:00
parent 2bf410c825
commit 42cb37b5e3
+55 -15
View File
@@ -15,19 +15,17 @@ env:
IMAGE_NAME: admin/taskpool IMAGE_NAME: admin/taskpool
jobs: jobs:
build-and-push: build:
runs-on: ubuntu-latest name: Build Frontend
if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu
steps: container:
- name: Install Node.js image: node:22
run: | defaults:
apt-get update run:
apt-get install -y curl working-directory: web
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs
node --version
- name: Checkout steps:
- name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup pnpm - name: Setup pnpm
@@ -35,19 +33,61 @@ jobs:
with: with:
version: 9 version: 9
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
id: pnpm-cache
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies - name: Install dependencies
working-directory: web
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile
- name: Build - name: Build
working-directory: web
run: pnpm build run: pnpm build
docker:
name: Build and Push Docker Image
runs-on: ubuntu
needs: build
if: github.event_name == 'push'
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Registry - name: Login to Registry
run: echo "${{ secrets.TOKEN }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin run: echo "${{ secrets.TOKEN }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
- name: Build and push Docker image - name: Build Docker image
run: | run: |
docker build -f Dockerfile.standalone -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} . docker build -f Dockerfile.standalone -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
- name: Push Docker image
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}