Skip to content
Closed

ci #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 103 additions & 56 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,48 @@ name: CI/CD Pipeline

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
branches: [ dev,main, master ]
# pull_request:
# branches: [ dev,main, master ]

env:
DOCKER_REGISTRY: ccr.ccs.tencentyun.com
DOCKER_NAMESPACE: your-namespace
DOCKER_REGISTRY: useccr.ccs.tencentyun.com
DOCKER_NAMESPACE: java-im-ai
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

cache: maven

# 更加优化的Maven缓存配置
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: |
~/.m2/repository
.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

# - name: Initialize Maven project with flatten plugin
# run: mvn flatten:flatten

- name: Build with Maven
run: mvn clean package -DskipTests -Pprod
run: mvn -B clean package -DskipTests -Pprod -Dmaven.repo.local=.m2/repository

- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: jar-files
path: "**/target/*.jar"
Expand All @@ -39,85 +53,118 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: jar-files
path: .

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Tencent Cloud Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
username: ${{ secrets.TENCENT_REGISTRY_USERNAME }}
password: ${{ secrets.TENCENT_REGISTRY_PASSWORD }}

- name: Build and push im-gateway
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./im-gateway
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/im-gateway:${{ github.sha }}

- name: Build and push ruoyi-auth
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./framework/ruoyi-auth
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-auth:${{ github.sha }}

- name: Build and push ruoyi-system
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./framework/ruoyi-modules/ruoyi-system
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-system:${{ github.sha }}
- name: Build and push ruoyi-gen
uses: docker/build-push-action@v4
with:
context: ./framework/ruoyi-modules/ruoyi-gen
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-gen:${{ github.sha }}
- name: Build and push ruoyi-job
uses: docker/build-push-action@v4
with:
context: ./framework/ruoyi-modules/ruoyi-job
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-job:${{ github.sha }}

# - name: Build and push ruoyi-gen
# uses: docker/build-push-action@v5
# with:
# context: ./framework/ruoyi-modules/ruoyi-gen
# push: true
# tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-gen:${{ github.sha }}

# - name: Build and push ruoyi-job
# uses: docker/build-push-action@v5
# with:
# context: ./framework/ruoyi-modules/ruoyi-job
# push: true
# tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-job:${{ github.sha }}

- name: Build and push ruoyi-resource
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./framework/ruoyi-modules/ruoyi-resource
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/ruoyi-resource:${{ github.sha }}

- name: Build and push im-core-server
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./im-core/im-core-server
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_NAMESPACE }}/im-core-server:${{ github.sha }}


deploy:
needs: docker-build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master'
steps:
- name: Deploy to production
run: echo "Deployment steps would go here"
- name: Manual approval
uses: trstringer/manual-approval@v1
- uses: actions/checkout@v4

- name: Copy deployment files to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "docker-compose.yml,deploy.sh,env-example"
target: "/home/${{ secrets.SSH_USERNAME }}/im-ai-deploy"
overwrite: true

- name: SSH Deploy
uses: appleboy/[email protected]
with:
secret: ${{ github.token }}
approvers: your-github-username
minimum-approvals: 1
exclude-authors: github-actions[bot]
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/${{ secrets.SSH_USERNAME }}/im-ai-deploy
chmod +x deploy.sh

# 设置环境变量
export DOCKER_REGISTRY=${{ env.DOCKER_REGISTRY }}
export DOCKER_NAMESPACE=${{ env.DOCKER_NAMESPACE }}
export REGISTRY_USERNAME=${{ secrets.TENCENT_REGISTRY_USERNAME }}
export REGISTRY_PASSWORD=${{ secrets.TENCENT_REGISTRY_PASSWORD }}

# 如果不存在.env文件,则复制示例文件
if [ ! -f .env ]; then
cp env-example .env
fi

# 使用GitHub SHA作为标签部署
./deploy.sh ${{ github.sha }}

# - name: Manual approval
# uses: trstringer/manual-approval@v2
# with:
# secret: ${{ github.token }}
# approvers: your-github-username
# minimum-approvals: 1
# exclude-authors: github-actions[bot]
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic"
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
}
115 changes: 115 additions & 0 deletions README-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 部署说明

## 环境要求

- Docker Engine 20.10+
- Docker Compose 2.0+

## 部署步骤

### 1. 准备环境变量文件

复制环境变量示例文件并编辑:

```bash
cp env-example .env
```

根据需要修改.env文件中的变量,特别是Nacos相关配置:

```
# Nacos配置
NACOS_SERVER=nacos.myimkit.com:8848
NACOS_USERNAME=nacos
NACOS_PASSWORD=abcdimkit8989a
NACOS_DISCOVERY_GROUP=DEFAULT_GROUP
NACOS_CONFIG_GROUP=DEFAULT_GROUP
```

### 2. 配置Docker Registry登录信息

设置以下环境变量:

```bash
export REGISTRY_USERNAME=您的用户名
export REGISTRY_PASSWORD=您的密码
```

### 3. 部署服务

使用标签部署(例如使用GitHub SHA作为标签):

```bash
./deploy.sh 具体的标签
```

或者使用最新版本部署:

```bash
./deploy.sh
```

如果想要临时覆盖Nacos配置,可以在启动时指定:

```bash
NACOS_SERVER=192.168.1.100:8848 ./deploy.sh
```

### 4. 查看服务状态

```bash
docker-compose ps
```

### 5. 查看服务日志

```bash
docker-compose logs -f 服务名称
```

例如:

```bash
docker-compose logs -f im-gateway
```

## Host配置说明

docker-compose.yml已配置每个服务的extra_hosts,添加了以下主机映射:

```
nacos.myimkit.com:192.168.1.101
mysql.myimkit.com:192.168.1.101
redis.myimkit.com:192.168.1.101
```

这确保了容器内部可以通过这些域名访问对应的服务。

## Nacos配置说明

在docker-compose.yml中,每个服务都配置了Nacos相关的环境变量:

```yaml
environment:
- SPRING_CLOUD_NACOS_SERVER_ADDR=${NACOS_SERVER:-nacos.myimkit.com:8848}
- SPRING_CLOUD_NACOS_USERNAME=${NACOS_USERNAME:-nacos}
- SPRING_CLOUD_NACOS_PASSWORD=${NACOS_PASSWORD:-abcdimkit8989a}
- SPRING_CLOUD_NACOS_DISCOVERY_GROUP=${NACOS_DISCOVERY_GROUP:-DEFAULT_GROUP}
- SPRING_CLOUD_NACOS_CONFIG_GROUP=${NACOS_CONFIG_GROUP:-DEFAULT_GROUP}
```

这些环境变量会覆盖应用程序中的@nacos.server@等占位符,使应用能够连接到指定的Nacos服务。

## 更新部署

当有新版本发布时,只需重新运行部署脚本即可:

```bash
./deploy.sh 新的标签
```

## 停止所有服务

```bash
docker-compose down
```
Binary file not shown.
18 changes: 18 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# 设置镜像标签,如果没有指定则使用latest
export TAG=${1:-latest}

# 登录Docker Registry
echo "登录Docker Registry..."
docker login ${DOCKER_REGISTRY} --username=$REGISTRY_USERNAME --password=$REGISTRY_PASSWORD

# 拉取最新镜像
echo "拉取最新镜像..."
docker-compose pull

# 启动服务
echo "启动服务..."
docker-compose up -d

echo "部署完成!"
Loading
Loading