前言

本文章基于 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-composecurl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-composechmod +x /usr/local/bin/docker-compose

一、上传项目并进入流水线

二、新建流水线 – 启动 mysql/redis/nacos

1.新建流水线

2.流水线源配置

3.构建配置

4.部署配置

# 项目文件夹BASE_DIR="/home/witbee-cloud"# 项目包名PACKAGE_NAME="witbee-cloud.tgz"echo "创建项目文件夹"mkdir -p $BASE_DIRecho "开始解压文件"tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIRecho "授权项目文件夹"chmod -R 777 $BASE_DIRecho "执行构建脚本"cd $BASE_DIR/dockersh deploy.sh base

5.保存并运行

三、新建流水线 – 启动 gateway/auth/system

1.新建流水线(同上)

2.流水线源配置(同上)

3.构建配置


4.部署配置(修改部署脚本,其它同上)

# 项目文件夹BASE_DIR="/home/witbee-cloud"# 项目包名PACKAGE_NAME="witbee-cloud.tgz"echo "开始解压文件"tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIRecho "授权项目文件夹"chmod -R 777 $BASE_DIRecho "执行构建脚本"cd $BASE_DIR/dockersh deploy.sh modules

5.保存并运行

三、新建流水线 – 启动 file/gen/job

1.新建流水线(同上)

2.流水线源配置(同上)

3.构建配置

4.部署配置(修改部署脚本,其它同上)

# 项目文件夹BASE_DIR="/home/witbee-cloud"# 项目包名PACKAGE_NAME="witbee-cloud.tgz"echo "开始解压文件"tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIRecho "授权项目文件夹"chmod -R 777 $BASE_DIRecho "执行构建脚本"cd $BASE_DIR/dockersh deploy.sh modulesPlus

5.保存并运行

四、新建流水线 – 启动 nginx

1.新建流水线

2.流水线源配置(同上)

3.构建配置


4.部署配置

# 项目文件夹BASE_DIR="/home/witbee-cloud"# 项目包名PACKAGE_NAME="witbee-ui.tgz"echo "开始解压文件"tar -zxvf $BASE_DIR/$PACKAGE_NAME -C $BASE_DIR/docker/nginx/html/distecho "授权项目文件夹"chmod -R 777 $BASE_DIRecho "执行构建脚本"cd $BASE_DIR/dockerdocker-compose up -d witbee-nginx

5.保存并运行

总结(附上 docker-compose.yml、deploy.sh 脚本)

docker-compose.yml

version : '3.8'services:witbee-nacos:restart: alwayscontainer_name: witbee-nacosbuild:context: ./nacosenvironment:- MODE=standalonevolumes:- ./nacos/logs/:/home/nacos/logs- ./nacos/conf/application.properties:/home/nacos/conf/application.propertiesports:- "8848:8848"- "9848:9848"- "9849:9849"depends_on:witbee-mysql:condition: service_healthywitbee-mysql:restart: alwayscontainer_name: witbee-mysqlbuild:context: ./mysqlports:- "3306:3306"volumes:- ./mysql/conf:/etc/mysql/conf.d- ./mysql/logs:/logs- ./mysql/data:/var/lib/mysqlcommand:# 将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=1environment:TZ: Asia/ShanghaiMYSQL_DATABASE: 'ry-cloud'MYSQL_ROOT_PASSWORD: passwordhealthcheck:test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]timeout: 45sinterval: 10sretries: 10witbee-redis:restart: alwayscontainer_name: witbee-redisimage: redis:7.0.6build:context: ./redisports:- "6379:6379"volumes:- ./redis/conf/redis.conf:/home/witbee/redis/redis.conf- ./redis/data:/datacommand: redis-server /home/witbee/redis/redis.confwitbee-nginx:container_name: witbee-nginximage: nginxbuild:context: ./nginxports:- "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.ddepends_on:- witbee-gatewaywitbee-gateway:restart: alwayscontainer_name: witbee-gatewaybuild:context: ./witbee/gatewaydockerfile: dockerfileports:- "9000:9000"depends_on:- witbee-rediswitbee-auth:restart: alwayscontainer_name: witbee-authbuild:context: ./witbee/authdockerfile: dockerfileports:- "9200:9200"depends_on:- witbee-rediswitbee-modules-system:restart: alwayscontainer_name: witbee-modules-systembuild:context: ./witbee/modules/systemdockerfile: dockerfileports:- "9201:9201"depends_on:- witbee-redis- witbee-mysqlwitbee-modules-gen:restart: alwayscontainer_name: witbee-modules-genbuild:context: ./witbee/modules/gendockerfile: dockerfileports:- "9202:9202"depends_on:- witbee-redis- witbee-mysqlwitbee-modules-job:restart: alwayscontainer_name: witbee-modules-jobbuild:context: ./witbee/modules/jobdockerfile: dockerfileports:- "9203:9203"depends_on:- witbee-redis- witbee-mysqlwitbee-modules-file:restart: alwayscontainer_name: witbee-modules-filebuild:context: ./witbee/modules/filedockerfile: dockerfileports:- "9300:9300"volumes:- ./witbee/uploadPath:/home/witbee/uploadPathwitbee-visual-monitor:restart: alwayscontainer_name: witbee-visual-monitorbuild:context: ./witbee/visual/monitordockerfile: dockerfileports:- "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 --permanentfirewall-cmd --add-port=9000/tcp --permanentfirewall-cmd --add-port=8848/tcp --permanentfirewall-cmd --add-port=9848/tcp --permanentfirewall-cmd --add-port=9849/tcp --permanentfirewall-cmd --add-port=6379/tcp --permanentfirewall-cmd --add-port=3306/tcp --permanentfirewall-cmd --add-port=9100/tcp --permanentfirewall-cmd --add-port=9200/tcp --permanentfirewall-cmd --add-port=9201/tcp --permanentfirewall-cmd --add-port=9202/tcp --permanentfirewall-cmd --add-port=9203/tcp --permanentfirewall-cmd --add-port=9300/tcp --permanentservice 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/dockerrm -f ./witbee/gateway/jar/** ./witbee/auth/jar/** ./witbee/modules/system/jar/**echo "复制 gateway 模块"cp ../witbee-gateway/target/witbee-gateway.jar ./witbee/gateway/jarecho "复制 auth 模块"cp ../witbee-auth/target/witbee-auth.jar ./witbee/auth/jarecho "复制 system 模块"cp ../witbee-modules/witbee-system/target/witbee-modules-system.jar ./witbee/modules/system/jarecho "删除原始镜像"docker-compose stop witbee-gateway witbee-auth witbee-modules-system && docker-compose rm -f witbee-gateway witbee-auth witbee-modules-systemecho "构建启动镜像"docker-compose up -d --build witbee-gateway witbee-auth witbee-modules-system}# 启动程序模块(非必须)modulesPlus(){echo "删除原始文件"cd $BASE_DIR/dockerrm -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/jarecho "复制 gen 模块"cp ../witbee-modules/witbee-gen/target/witbee-modules-gen.jar ./witbee/modules/gen/jarecho "复制 job 模块"cp ../witbee-modules/witbee-job/target/witbee-modules-job.jar ./witbee/modules/job/jarecho "删除原始镜像"docker-compose stop witbee-modules-file witbee-modules-gen witbee-modules-job && docker-compose rm -f witbee-modules-file witbee-modules-gen witbee-modules-jobecho "构建启动镜像"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 微服务架构全部内容了,欢迎讨论!