本文章基于 ruoyi-cloud 项目改编。
阿里云云效工作台点击进入,主要使用到代码管理及流水线模块。
主机配置:CentOS 7.9.2009 x86_64
环境配置:安装 docker、docker-compose
# 安装 docker 使用 daocloud 的一键安装脚本
curl -sSL https://get.daocloud.io/docker | sh
# 安装 daocloud 加速器,避免 dockerhub 网络问题
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
# 启动 docker 服务
systemctl start docker
# 安装 docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# 项目文件夹
BASE_DIR="/home/witbee-cloud"
# 项目包名
PACKAGE_NAME="witbee-cloud.tgz"
echo "创建项目文件夹"
mkdir -p $BASE_DIR
echo "开始解压文件"
tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIR
echo "授权项目文件夹"
chmod -R 777 $BASE_DIR
echo "执行构建脚本"
cd $BASE_DIR/docker
sh deploy.sh base
# 项目文件夹
BASE_DIR="/home/witbee-cloud"
# 项目包名
PACKAGE_NAME="witbee-cloud.tgz"
echo "开始解压文件"
tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIR
echo "授权项目文件夹"
chmod -R 777 $BASE_DIR
echo "执行构建脚本"
cd $BASE_DIR/docker
sh deploy.sh modules
# 项目文件夹
BASE_DIR="/home/witbee-cloud"
# 项目包名
PACKAGE_NAME="witbee-cloud.tgz"
echo "开始解压文件"
tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIR
echo "授权项目文件夹"
chmod -R 777 $BASE_DIR
echo "执行构建脚本"
cd $BASE_DIR/docker
sh deploy.sh modulesPlus
# 项目文件夹
BASE_DIR="/home/witbee-cloud"
# 项目包名
PACKAGE_NAME="witbee-ui.tgz"
echo "开始解压文件"
tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIR/docker/nginx/html/dist
echo "授权项目文件夹"
chmod -R 777 $BASE_DIR
echo "执行构建脚本"
cd $BASE_DIR/docker
docker-compose up -d witbee-nginx
docker-compose.yml
version : '3.8'
services:
witbee-nacos:
restart: always
container_name: witbee-nacos
build:
context: ./nacos
environment:
- MODE=standalone
volumes:
- ./nacos/logs/:/home/nacos/logs
- ./nacos/conf/application.properties:/home/nacos/conf/application.properties
ports:
- "8848:8848"
- "9848:9848"
- "9849:9849"
depends_on:
witbee-mysql:
condition: service_healthy
witbee-mysql:
restart: always
container_name: witbee-mysql
build:
context: ./mysql
ports:
- "3306:3306"
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/logs
- ./mysql/data:/var/lib/mysql
command:
# 将mysql8.0默认密码策略 修改为 原先 策略 (mysql8.0对其默认策略做了更改 会导致密码无法匹配)
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
environment:
TZ: Asia/Shanghai
MYSQL_DATABASE: 'ry-cloud'
MYSQL_ROOT_PASSWORD: password
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
timeout: 45s
interval: 10s
retries: 10
witbee-redis:
restart: always
container_name: witbee-redis
image: redis:7.0.6
build:
context: ./redis
ports:
- "6379:6379"
volumes:
- ./redis/conf/redis.conf:/home/witbee/redis/redis.conf
- ./redis/data:/data
command: redis-server /home/witbee/redis/redis.conf
witbee-nginx:
container_name: witbee-nginx
image: nginx
build:
context: ./nginx
ports:
- "8000:80"
volumes:
- ./nginx/html/dist:/home/witbee/projects/witbee-ui
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/logs:/var/log/nginx
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- witbee-gateway
witbee-gateway:
restart: always
container_name: witbee-gateway
build:
context: ./witbee/gateway
dockerfile: dockerfile
ports:
- "9000:9000"
depends_on:
- witbee-redis
witbee-auth:
restart: always
container_name: witbee-auth
build:
context: ./witbee/auth
dockerfile: dockerfile
ports:
- "9200:9200"
depends_on:
- witbee-redis
witbee-modules-system:
restart: always
container_name: witbee-modules-system
build:
context: ./witbee/modules/system
dockerfile: dockerfile
ports:
- "9201:9201"
depends_on:
- witbee-redis
- witbee-mysql
witbee-modules-gen:
restart: always
container_name: witbee-modules-gen
build:
context: ./witbee/modules/gen
dockerfile: dockerfile
ports:
- "9202:9202"
depends_on:
- witbee-redis
- witbee-mysql
witbee-modules-job:
restart: always
container_name: witbee-modules-job
build:
context: ./witbee/modules/job
dockerfile: dockerfile
ports:
- "9203:9203"
depends_on:
- witbee-redis
- witbee-mysql
witbee-modules-file:
restart: always
container_name: witbee-modules-file
build:
context: ./witbee/modules/file
dockerfile: dockerfile
ports:
- "9300:9300"
volumes:
- ./witbee/uploadPath:/home/witbee/uploadPath
witbee-visual-monitor:
restart: always
container_name: witbee-visual-monitor
build:
context: ./witbee/visual/monitor
dockerfile: dockerfile
ports:
- "9100:9100"
deploy.sh
#!/bin/sh
# 使用说明,用来提示输入参数
usage() {
echo "Usage: sh 执行脚本.sh [port|base|modules|modulesPlus|stop|rm]"
exit 1
}
# 开启所需端口
port(){
firewall-cmd --add-port=8000/tcp --permanent
firewall-cmd --add-port=9000/tcp --permanent
firewall-cmd --add-port=8848/tcp --permanent
firewall-cmd --add-port=9848/tcp --permanent
firewall-cmd --add-port=9849/tcp --permanent
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --add-port=9100/tcp --permanent
firewall-cmd --add-port=9200/tcp --permanent
firewall-cmd --add-port=9201/tcp --permanent
firewall-cmd --add-port=9202/tcp --permanent
firewall-cmd --add-port=9203/tcp --permanent
firewall-cmd --add-port=9300/tcp --permanent
service firewalld restart
}
# 项目文件夹
BASE_DIR="/home/witbee-cloud"
# 项目包名
PACKAGE_NAME="witbee-cloud.tgz"
# 启动基础环境(必须)
base(){
docker-compose up -d witbee-mysql witbee-redis witbee-nacos
}
# 启动程序模块(必须)
modules(){
echo "删除原始文件"
cd $BASE_DIR/docker
rm -f ./witbee/gateway/jar/** ./witbee/auth/jar/** ./witbee/modules/system/jar/**
echo "复制 gateway 模块"
cp ../witbee-gateway/target/witbee-gateway.jar ./witbee/gateway/jar
echo "复制 auth 模块"
cp ../witbee-auth/target/witbee-auth.jar ./witbee/auth/jar
echo "复制 system 模块"
cp ../witbee-modules/witbee-system/target/witbee-modules-system.jar ./witbee/modules/system/jar
echo "删除原始镜像"
docker-compose stop witbee-gateway witbee-auth witbee-modules-system && docker-compose rm -f witbee-gateway witbee-auth witbee-modules-system
echo "构建启动镜像"
docker-compose up -d --build witbee-gateway witbee-auth witbee-modules-system
}
# 启动程序模块(非必须)
modulesPlus(){
echo "删除原始文件"
cd $BASE_DIR/docker
rm -f ./witbee/modules/file/jar/** ./witbee/modules/gen/jar/** ./witbee/modules/job/jar/**
echo "复制 file 模块"
cp ../witbee-modules/witbee-file/target/witbee-modules-file.jar ./witbee/modules/file/jar
echo "复制 gen 模块"
cp ../witbee-modules/witbee-gen/target/witbee-modules-gen.jar ./witbee/modules/gen/jar
echo "复制 job 模块"
cp ../witbee-modules/witbee-job/target/witbee-modules-job.jar ./witbee/modules/job/jar
echo "删除原始镜像"
docker-compose stop witbee-modules-file witbee-modules-gen witbee-modules-job && docker-compose rm -f witbee-modules-file witbee-modules-gen witbee-modules-job
echo "构建启动镜像"
docker-compose up -d --build witbee-modules-file witbee-modules-gen witbee-modules-job
}
# 关闭所有环境/模块
stop(){
docker-compose stop
}
# 删除所有环境/模块
rm(){
docker-compose rm
}
# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"port")
port
;;
"base")
base
;;
"modules")
modules
;;
"modulesPlus")
modulesPlus
;;
"stop")
stop
;;
"rm")
rm
;;
*)
usage
;;
esac
由于使用 docker-compose 部署可能会产生多余的镜像,可以使用 docker image prune 命令清理。也可能产生许多没用的储存卷,使用 docker volume rm $(docker volume ls -qf dangling=true) 命令清理。以上就是阿里云云效流水线自动化部署 ruoyi-cloud 微服务架构全部内容了,欢迎讨论!