From 8da55b01ed6b09613bccce40327611f02256eb5c Mon Sep 17 00:00:00 2001 From: fandongqiang <1075044867@qq.com> Date: Sat, 7 Oct 2023 11:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95CI=EF=BC=8C=E5=8F=91=E5=B8=83?= =?UTF-8?q?springboot=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 15 ++++++++++++--- Dockerfile | 2 +- entrypoint.sh | 2 +- run.sh | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 run.sh diff --git a/.drone.yml b/.drone.yml index b04a6ff..90137a2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,7 +2,16 @@ kind: pipeline # 定义一个管道 type: docker # 当前管道的类型 name: test # 当前管道的名称 steps: # 定义管道的执行步骤 - - name: test # 步骤名称 - image: node:latest # 当前步骤使用的镜像 + - name: build-jar # 步骤名称 + image: maven:3.8.5-openjdk-8 # 当前步骤使用的镜像 + volumes: + - name: maven-cache + path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载 + - name: maven-build + path: /app/build # 将应用打包好的Jar和执行脚本挂载出来 commands: # 当前步骤执行的命令 - - echo 测试drone执行2 \ No newline at end of file + - mvn clean package -DskipTests=true # 应用打包命 + - cp target/ips-ci-demo-1.0.jar /app/build/ips-ci-demo-1.0.jar + - cp entrypoint.sh /app/build/ + - cp Dockerfile /app/build/ + - cp run.sh /app/build/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7860522..5ff7dfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /app COPY ./entrypoint.sh /app/ RUN chmod 755 -R /app/ -COPY ./mypubdemo*.jar /app/ +COPY ./ips-ci-demo-1.0*.jar /app/ ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index a029abd..874fac2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -java -Xms128m -Xmx128m -jar /app/mypubdemo*.jar +java -Xms128m -Xmx128m -jar /app/ips-ci-demo-1.0*.jar if [ $? != 0 ]; then echo Failed to start java >&2 diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..d8212a0 --- /dev/null +++ b/run.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# 定义应用组名 +group_name='com.ipsplm' +# 定义应用名称 +app_name='ips-ci-demo' +# 定义应用版本 +app_version='latest' +echo '----copy jar----' +docker stop ${app_name} +echo '----stop container----' +docker rm ${app_name} +echo '----rm container----' +docker rmi ${group_name}/${app_name}:${app_version} +echo '----rm image----' +# 打包编译docker镜像 +docker build -t ${group_name}/${app_name}:${app_version} . +echo '----build image----' +docker run -p 8000:8000 --name ${app_name} \ +-e TZ="Asia/Shanghai" \ +-v /etc/localtime:/etc/localtime \ +-d ${group_name}/${app_name}:${app_version} +echo '----start container----' \ No newline at end of file