CI/CD集成-update

master
chenyuepan 3 weeks ago
parent 6883562241
commit 47feedf4c7

@ -3,47 +3,57 @@ type: docker
name: venue_reservation_service name: venue_reservation_service
steps: steps:
# 1. Maven打包阶段 # 1.maven打包
- name: build java package - name: maven compile
pull: if-not-exists pull: if-not-exists
image: maven:3.8.7-openjdk-17-slim # 构建镜像的maven+jdk选择最好选择满足匹配你的项目版本的
image: matderosa/maven-3.8-openjdk-17-gcc8.5
volumes: volumes:
# maven构建缓存
- name: maven-cache - name: maven-cache
path: /root/.m2 path: /root/.m2
- name: build-output # 挂载宿主机的目录
path: /build-output - name: maven-build
path: /venue/build
commands: commands:
# 开始打包maven工程
- mvn clean package -Dmaven.test.skip=true - mvn clean package -Dmaven.test.skip=true
- cp target/*.jar /build-output/app.jar # 将打包后的文件复制到宿主机映射目录
- cp Dockerfile /build-output - cp target/*.jar /venue/build
- cp docker.sh /build-output - cp Dockerfile /venue/build
environment: - cp docker.sh /venue/build
DRONE_REPO_NAME: venue_reservation_service # 确保这个变量设置正确
# 2. Docker构建和部署阶段 - name: build docker
- name: build and deploy docker image: plugins/docker
image: docker:20.10-dind
volumes: volumes:
- name: build-output # 将容器内目录挂载到宿主机仓库需要开启Trusted设置
path: /build-output - name: maven-build
- name: docker-sock path: /venue/build # 将应用打包好的Jar和执行脚本挂载出来
path: /var/run/docker.sock - name: docker
path: /var/run/docker.sock # 挂载宿主机的docker
settings:
dockerfile: /venue/build/Dockerfile
commands: commands:
- cd /build-output # 定义在Docker容器中执行的shell命令
- cd /venue/build
- chmod +x docker.sh - chmod +x docker.sh
- ./docker.sh - sh docker.sh
- docker ps
volumes:
- name: build-output volumes: # 定义流水线挂载目录,用于共享数据
- name: maven-build
host: host:
path: /home/projects/venue/build path: /home/projects/venue/maven/build # 从宿主机中挂载的目录
- name: maven-cache - name: maven-cache
host: host:
path: /home/projects/venue/maven/cache path: /home/projects/venue/maven/cache
- name: docker-sock - name: docker
host: host:
path: /var/run/docker.sock path: /var/run/docker.sock
# drone执行触发器
trigger: trigger:
branch: branch:
- master - master

Loading…
Cancel
Save