Files
aiot-platform/.gitea/workflows/cicd.yaml
lzh 3191877191
All checks were successful
aiot-platform CI/CD / build-and-deploy (push) Successful in 10m22s
feat: 修改分支为master
2025-12-18 11:48:54 +08:00

99 lines
3.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: aiot-platform CI/CD
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: xw-runner
container:
image: catthehacker/ubuntu:act-latest
# Runner 可能已默认挂载 docker.sock如遇权限问题再尝试添加 options: --user root
steps:
# 1. 手动检出代码
- name: Checkout (Native)
run: |
# 清理工作目录
ls -A1 | xargs rm -rf
# 手动拼接 Git URL
SERVER_DOMAIN=$(echo "${{ gitea.server_url }}" | sed -E 's|https?://||')
PROTO="http"
if [[ "${{ gitea.server_url }}" == https* ]]; then
PROTO="https"
fi
GIT_URL="${PROTO}://${{ gitea.actor }}:${{ gitea.token }}@${SERVER_DOMAIN}/${{ gitea.repository }}.git"
echo "Cloning from ${PROTO}://${SERVER_DOMAIN}/${{ gitea.repository }}.git ..."
git clone --depth 1 "$GIT_URL" .
git log -1 --format='%h - %s'
# 2. 准备 Docker 网络 (用于容器间通信)
- name: Create Docker Network
run: |
docker network create aiot-net || true
# 3. 构建并部署主服务 (Server)
- name: Build & Deploy Server
id: build-server
env:
IMAGE_NAME: 'aiot-server'
CONTAINER_NAME: aiot-server
run: |
# --- 构建 ---
SHORT_SHA=$(git log -1 --format='%h')
FULL_IMAGE_NAME="${IMAGE_NAME}:${SHORT_SHA}"
echo "Building Server $FULL_IMAGE_NAME..."
# 使用默认 Dockerfile
docker build -t "$FULL_IMAGE_NAME" -f Dockerfile .
docker tag "$FULL_IMAGE_NAME" "${IMAGE_NAME}:latest"
# --- 部署 ---
echo "Deploying Server..."
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
docker run -d \
--name $CONTAINER_NAME \
--network aiot-net \
--restart always \
-p 48080:48080 \
"${IMAGE_NAME}:latest"
# 4. 构建并部署 IoT 网关 (Gateway)
- name: Build & Deploy Gateway
id: build-gateway
env:
IMAGE_NAME: 'aiot-gateway'
CONTAINER_NAME: aiot-gateway
run: |
# --- 构建 ---
SHORT_SHA=$(git log -1 --format='%h')
FULL_IMAGE_NAME="${IMAGE_NAME}:${SHORT_SHA}"
echo "Building Gateway $FULL_IMAGE_NAME..."
# 使用 Dockerfile.gateway
docker build -t "$FULL_IMAGE_NAME" -f Dockerfile.gateway .
docker tag "$FULL_IMAGE_NAME" "${IMAGE_NAME}:latest"
# --- 部署 ---
echo "Deploying Gateway..."
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
# 覆盖 RPC 地址,使其指向 aiot-server 容器
# 假设 application.yaml 中配置的是 viewshanghai.iot.gateway.rpc.url
docker run -d \
--name $CONTAINER_NAME \
--network aiot-net \
--restart always \
-p 1883:1883 \
-p 8092:8092 \
-e VIEWSHANGHAI_IOT_GATEWAY_RPC_URL="http://aiot-server:48080" \
"${IMAGE_NAME}:latest"