CI and Docker Build / Frontend Build (push) Successful in 18s
CI and Docker Build / Backend Build (push) Successful in 1m49s
CI and Docker Build / Build and Push Docker Image (push) Successful in 1m40s
CI and Docker Build / Deploy to Remote Server (push) Successful in 9s
- 移除 GitHub Actions 的 build.yml / build_test.yml(依赖 Docker Hub、GHCR 与 GitHub 上的前端仓) - 新增 Dockerfile.ci:容器内完整构建(Go 1.23 + CGO/musl,前端从 git.viaeon.com 拉取) - 新增 .github/workflows/ci-docker.yml:构建校验 -> 推送 git.viaeon.com 镜像 -> SSH 远程部署 - 新增 docker-compose.prod.yml 供部署机使用
129 lines
3.9 KiB
YAML
129 lines
3.9 KiB
YAML
name: CI and Docker Build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
|
|
jobs:
|
|
frontend:
|
|
name: Frontend Build
|
|
runs-on: ubuntu
|
|
container:
|
|
image: node:22
|
|
steps:
|
|
- name: Clone rustdesk-api-web
|
|
run: |
|
|
git clone --depth 1 -b master https://git.viaeon.com/admin/rustdesk-api-web.git /tmp/web
|
|
cd /tmp/web
|
|
npm install
|
|
npm run build
|
|
|
|
backend:
|
|
name: Backend Build
|
|
runs-on: ubuntu
|
|
container:
|
|
image: golang:1.23
|
|
steps:
|
|
- name: Checkout and build
|
|
run: |
|
|
cd /tmp
|
|
git clone --depth=1 https://admin:${{ secrets.TOKEN }}@git.viaeon.com/admin/rustdesk-api.git repo
|
|
cd repo
|
|
go env -w GOPROXY=https://goproxy.cn,direct
|
|
go mod tidy
|
|
go mod download
|
|
CGO_ENABLED=1 go build -v -o bin/apimain ./cmd/apimain.go
|
|
|
|
docker:
|
|
name: Build and Push Docker Image
|
|
runs-on: ubuntu
|
|
needs: [frontend, backend]
|
|
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 Gitea Container Registry
|
|
run: |
|
|
echo "${{ secrets.TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
echo "Building image..."
|
|
docker build \
|
|
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/rustdesk-api" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
-f Dockerfile.ci \
|
|
-t git.viaeon.com/admin/rustdesk-api:${{ github.ref_name }} \
|
|
-t git.viaeon.com/admin/rustdesk-api:latest . 2>&1
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
echo "Pushing ${{ github.ref_name }}..."
|
|
docker push git.viaeon.com/admin/rustdesk-api:${{ github.ref_name }} 2>&1
|
|
echo "Pushing latest..."
|
|
docker push git.viaeon.com/admin/rustdesk-api:latest 2>&1
|
|
|
|
deploy:
|
|
name: Deploy to Remote Server
|
|
runs-on: ubuntu
|
|
needs: docker
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
env:
|
|
RUNNER_TOOL_CACHE: /toolcache
|
|
|
|
steps:
|
|
- name: Install SSH Client
|
|
run: |
|
|
if command -v apk &> /dev/null; then
|
|
apk add --no-cache openssh-client sshpass
|
|
elif command -v apt-get &> /dev/null; then
|
|
apt-get update && apt-get install -y openssh-client sshpass
|
|
else
|
|
echo "Cannot install sshpass"
|
|
exit 1
|
|
fi
|
|
ssh -V
|
|
|
|
- name: Deploy via SSH
|
|
run: |
|
|
sshpass -p '${{ secrets.DEPLOY_PASSWORD }}' ssh -o StrictHostKeyChecking=no -p ${{ secrets.DEPLOY_PORT || '22' }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << ENDSSH
|
|
set -e
|
|
cd "${{ secrets.DEPLOY_PATH }}"
|
|
echo "Current directory: \$(pwd)"
|
|
echo "Pulling latest image..."
|
|
docker pull git.viaeon.com/admin/rustdesk-api:latest
|
|
echo "Restarting containers..."
|
|
docker compose down || true
|
|
docker compose up -d
|
|
echo "Cleaning up old images..."
|
|
docker image prune -f
|
|
echo "Deployment completed!"
|
|
ENDSSH
|