模版一(pig/.circleci/config.yml):
# 版本定义,指定为CircleCI的2.1版本 version: 2.1 # 定义执行器,这里定义了一个使用OpenJDK 17.0的Docker执行器 executors: openjdk-executor: docker: - image: cimg/openjdk:17.0 # 定义构建任务 jobs: # 构建任务,使用上面定义的OpenJDK执行器 build: executor: openjdk-executor steps: # 检出代码 - checkout # 执行编译和打包命令,跳过测试,并指定构建profile为cloud - run: name: 编译及打包 command: mvn clean package -DskipTests -Pcloud # 将构建好的jar包持久化到工作空间 - persist_to_workspace: root: . paths: - pig-register/target/pig-register.jar - pig-gateway/target/pig-gateway.jar - pig-auth/target/pig-auth.jar - pig-upms/pig-upms-biz/target/pig-upms-biz.jar - pig-visual/pig-monitor/target/pig-monitor.jar - pig-visual/pig-codegen/target/pig-codegen.jar - pig-visual/pig-quartz/target/pig-quartz.jar # Docker任务,用于构建Docker镜像 docker: docker: - image: docker:19.03.12 steps: # 设置远程Docker环境 - setup_remote_docker: version: 19.03.12 # 检出代码 - checkout # 附加之前构建好的jar包到工作空间 - attach_workspace: at: . - run: name: 登录Harbor镜像仓库 command: | echo "登录Harbor镜像仓库..." docker login --username your-harbor-username --password your-harbor-password reg.istack.com # 构建Docker镜像 - run: name: 构建Docker镜像 command: | docker build -t reg.istack.com/saas/pig-register:latest -f ./pig-register/Dockerfile ./pig-register/ docker build -t reg.istack.com/saas/pig-gateway:latest -f ./pig-gateway/Dockerfile ./pig-gateway/ docker build -t reg.istack.com/saas/pig-auth:latest -f ./pig-auth/Dockerfile ./pig-auth/ docker build -t reg.istack.com/saas/pig-upms:latest -f ./pig-upms/pig-upms-biz/Dockerfile ./pig-upms/pig-upms-biz/ docker build -t reg.istack.com/saas/pig-monitor:latest -f ./pig-visual/pig-monitor/Dockerfile ./pig-visual/pig-monitor/ docker build -t reg.istack.com/saas/pig-codegen:latest -f ./pig-visual/pig-codegen/Dockerfile ./pig-visual/pig-codegen/ docker build -t reg.istack.com/saas/pig-quartz:latest -f ./pig-visual/pig-quartz/Dockerfile ./pig-visual/pig-quartz/ - run: name: 推送Docker镜像 command: | docker push reg.istack.com/saas/pig-register:latest docker push reg.istack.com/saas/pig-gateway:latest docker push reg.istack.com/saas/pig-auth:latest docker push reg.istack.com/saas/pig-upms:latest docker push reg.istack.com/saas/pig-monitor:latest docker push reg.istack.com/saas/pig-codegen:latest docker push reg.istack.com/saas/pig-quartz:latest # 部署任务 deploy: docker: - image: cimg/base:current steps: # 添加SSH密钥,用于远程服务器登录 - add_ssh_keys: fingerprints: - "your-ssh-key-fingerprint" # 执行部署命令 - run: name: 部署到远程服务器 command: | echo "部署到远程服务器..." ssh root@172.16.24.193 "cd /data/server/$JOB_BASE_NAME && /usr/local/bin/docker-compose pull && /usr/local/bin/docker-compose up -d" # 定义工作流,指定构建和部署的任务顺序 workflows: version: 2 pig: jobs: - build - docker: requires: - build - deploy: requires: - docker
模版二(pig-ui.circleci/config.yml):
# 版本定义,指定为CircleCI的2.1版本 version: 2.1 # 定义执行器,这里定义了一个使用Node.js 18的执行器 executors: nodejs-executor: docker: - image: cimg/node:18 # 定义构建任务 jobs: # 构建任务,使用上面定义的Node.js执行器 build: executor: nodejs-executor steps: # 检出代码 - checkout # 安装项目依赖 - run: npm install --registry=https://registry.npmmirror.com # 构建项目(使用自定义的Docker命令) - run: npm run build:docker # 将构建好的dist目录持久化到工作空间 - persist_to_workspace: root: . paths: - docker/dist/ # Docker任务,用于构建Docker镜像 docker: docker: - image: docker:19.03.12 steps: # 设置远程Docker环境 - setup_remote_docker: version: 19.03.12 # 检出代码 - checkout # 附加之前构建好的dist目录到工作空间 - attach_workspace: at: . - run: name: 登录Harbor镜像仓库 command: | echo "登录Harbor镜像仓库..." docker login --username your-harbor-username --password your-harbor-password reg.istack.com # 构建Docker镜像 - run: name: 构建Docker镜像 command: | docker build -t reg.istack.com/saas/pig-ui:latest -f ./docker/Dockerfile ./docker/ - run: name: 推送Docker镜像 command: | docker push reg.istack.com/saas/pig-ui:latest # 部署任务 deploy: docker: - image: cimg/base:current steps: # 添加SSH密钥,用于远程服务器登录 - add_ssh_keys: fingerprints: - "your-ssh-key-fingerprint" # 执行部署命令 - run: name: 部署到远程服务器 command: | echo "部署到远程服务器..." ssh root@172.16.24.193 "cd /data/server/$JOB_BASE_NAME && /usr/local/bin/docker-compose pull && /usr/local/bin/docker-compose up -d" # 定义工作流,指定构建和部署的任务顺序 workflows: version: 2 pig-ui: jobs: - build - docker: requires: - build - deploy: requires: - docker