背景
公司saas项目采用spring cloud,用Jenkins构建,随着微服务越来越多,每增加一个机器/环境都需要修改Jenkins的配置,
那时刚增加了uat环境,开发和测试环境机器由于性能不同需要对调,这时需要修改 Jenkins的项目数=微服务数*3
于是就在github和码云找Jenkins替代方案,类似的软件有很多,流程都是新建项目,单独修改每个项目的构建脚本(分为 maven打包,执行备份,上传jar包,执行重启)
对于多微服务项目来说,修改过程繁琐,于是就想到通过写代码来生成这些脚本。于是基于ansible的java构建工具 就诞生了。
项目截图
技术依赖项
centos (运行环境)
gitlab(微服务项目)
nacos (微服务配置)
redis(缓存,session)
minio(脚本文件存储)
jdk1.8
ansible
nginx 在springcloud gateway读取配置
ansible playbook 模板如下
--- #fileInfo${fileInfo} - hosts: 127.0.0.1 remote_user: root tasks: - shell: rm -rf ${cloneDir} - shell: mkdir -p ${cloneDir} - shell: chmod -R 777 ${cloneDir} - command: chdir: ${cloneDir} cmd: git clone -b '${gitBranch}' ${gitCloneUrl} - shell: chmod -R 777 ${cloneDir} - command: chdir: ${pomDir} cmd: mvn clean package -e -U -Dmaven.test.skip=true - command: chdir: ${servicePomDir}target/ cmd: ls - hosts: ${server.uuid} remote_user: ${server.username} tasks: - shell: mkdir -p ${server.projectDir}${springApplicationName}/ - shell: date +%Y_%m_%d_%H_%M_%S register: backup_date - name: "print_date" debug: msg: "{{ backup_date['stdout'] }}" - shell: rm -rf ${server.projectDir}bak_${springApplicationName}/{{ backup_date['stdout'] }}/ - shell: mkdir -p ${server.projectDir}bak_${springApplicationName}/{{ backup_date['stdout'] }}/ - shell: cp -r ${server.projectDir}${springApplicationName} ${server.projectDir}bak_${springApplicationName}/{{ backup_date['stdout'] }}/ - name: synchronize jar synchronize: src: ${servicePomDir}target/ dest: ${server.projectDir}${springApplicationName}/ mode: push delete: yes compress: yes rsync_opts: - "--exclude=classes" - "--exclude=generated-sources" - "--exclude=maven-archiver" - "--exclude=maven-status" - "--exclude=*.original" - "--exclude=.git" - "--exclude=*.pid" - "--exclude=*.bak" - "--exclude=*.log" - "--exclude=*.sh" - "--cvs-exclude" - "--include=*.jar" # - command: # chdir: ${server.projectDir}${springApplicationName}/ # cmd: chown -R ${server.username}:${server.username} ${server.projectDir}${springApplicationName}/ - command: chdir: ${server.projectDir}${springApplicationName}/ cmd: ./app.sh restart - hosts: 127.0.0.1 remote_user: root tasks: - shell: rm -rf ${cloneDir}