42cb37b5e3
- 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
94 lines
2.4 KiB
YAML
94 lines
2.4 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: git.viaeon.com
|
|
IMAGE_NAME: admin/taskpool
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Frontend
|
|
runs-on: ubuntu
|
|
container:
|
|
image: node:22
|
|
defaults:
|
|
run:
|
|
working-directory: web
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v4
|
|
with:
|
|
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
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: 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
|
|
run: echo "${{ secrets.TOKEN }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
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 }}:${{ github.sha }}
|