diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..75aac1a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.idea/ +.git/ +.gitignore +*/**/target/ +**/*.iml +*.md +.drone.yml +LICENSE +.dockerignore +Dockerfile \ No newline at end of file diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..bb43ac4 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,39 @@ +kind: pipeline +type: docker +name: default + +steps: +- name: build + image: docker:dind + volumes: + - name: dockersock + path: /var/run/docker.sock + - name: dockerconfig + path: /root/.docker + commands: + - docker build -t harbor.picaiba.com/kszny/mes-api:1.0.0-india ./ && docker push harbor.picaiba.com/kszny/mes-api:1.0.0-india + + - name: deploy + image: harbor.picaiba.com/tools/kubectl + commands: + - echo "172.27.0.20 lb.kubesphere.local" >> /etc/hosts + - sleep 1 + - kubectl scale --replicas=0 deployment/mes-api -n mes-india + - sleep 3 + - kubectl scale --replicas=1 deployment/mes-api -n mes-india + depends_on: + - build + +volumes: +- name: dockersock + host: + path: /var/run/docker.sock +- name: dockerconfig + host: + path: /root/.docker + +trigger: + branch: + - porject/yd-monitor + event: + - push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b764535 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +#FROM maven:3-jdk-8-alpine as builder +#WORKDIR /app +#COPY settings.xml /usr/share/maven/ref/repository/settings.xml +#COPY pom.xml . +#COPY gateway/pom.xml gateway/ +#COPY core/pom.xml core/ +#COPY common/pom.xml common/ +#COPY passport/pom.xml passport/ +#COPY upms/pom.xml upms/ +#COPY empty/pom.xml empty/ +#COPY material/pom.xml material/ +#COPY order/pom.xml order/ +#COPY monitor/pom.xml monitor/ +#COPY equipment/pom.xml equipment/ +#COPY basic/pom.xml basic/ +## COPY report/pom.xml report/ +# +#RUN mvn -B -s /usr/share/maven/ref/repository/settings.xml dependency:resolve-plugins dependency:resolve clean package +# +#COPY ./ ./ +# +#RUN mvn -B -s /usr/share/maven/ref/repository/settings.xml -Dmaven.test.skip=true -Ptest clean package +FROM maven:3-jdk-8-alpine as builder +WORKDIR /app +COPY ./ ./ +RUN mvn -s settings.xml clean package -Dmaven.test.skip=true + +FROM anapsix/alpine-java:8_server-jre_unlimited as layers +LABEL mantainer=shihairong@zimonet.com +WORKDIR /app +COPY --from=builder app/ym-gateway/target/ym-gateway.jar /app/app.jar +#ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-jar","app.jar", "--spring.profiles.active=dev"] + +# 通过工具spring-boot-jarmode-layertools从application.jar中提取拆分后的构建结果 +RUN java -Djarmode=layertools -jar app.jar extract + +# 正式构建镜像 +FROM anapsix/alpine-java:8_server-jre_unlimited +# 指定工作目录,目录不存在会自动创建 +WORKDIR /app +# 前一阶段从jar中提取除了多个文件,这里分别执行COPY命令复制到镜像空间中,每次COPY都是一个layer +COPY --from=layers app/dependencies ./ +COPY --from=layers app/spring-boot-loader ./ +COPY --from=layers app/snapshot-dependencies ./ +COPY --from=layers app/company-dependencies ./ +COPY --from=layers app/application ./ +# 指定时区 +ENV TZ="Asia/Shanghai" +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +# 定义一些环境变量,方便环境变量传参 +ENV JVM_OPTS="" +ENV JAVA_OPTS="-Dspring.profiles.active=dev" +# 指定暴露的端口,起到说明的作用,不指定也会暴露对应端口 +EXPOSE 8080 +# 启动 jar 的命令 +ENTRYPOINT ["sh","-c","java $JVM_OPTS $JAVA_OPTS org.springframework.boot.loader.JarLauncher"] diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..b1c7d51 --- /dev/null +++ b/settings.xml @@ -0,0 +1,19 @@ + + + + /usr/share/maven/ref/repository + + + com.spotify + + + + + central + * + aliyun + https://maven.aliyun.com/repository/public + + + \ No newline at end of file diff --git a/ym-gateway/pom.xml b/ym-gateway/pom.xml index b4a2c88..713f8da 100644 --- a/ym-gateway/pom.xml +++ b/ym-gateway/pom.xml @@ -68,11 +68,33 @@ ${project.artifactId} - + org.springframework.boot spring-boot-maven-plugin 2.5.12 - + + + com.cnbm.YmApplication + + + true + ${project.basedir}/src/main/resources/layers.xml + + + + org.projectlombok + lombok + + + + + + + repackage + + + + org.apache.maven.plugins maven-surefire-plugin @@ -99,4 +121,4 @@ - \ No newline at end of file + diff --git a/ym-gateway/src/main/resources/layers.xml b/ym-gateway/src/main/resources/layers.xml new file mode 100644 index 0000000..25736ee --- /dev/null +++ b/ym-gateway/src/main/resources/layers.xml @@ -0,0 +1,27 @@ + + + + org/springframework/boot/loader/** + + + + + + *:*:*SNAPSHOT + + + com.cnbm:* + + + + + dependencies + spring-boot-loader + snapshot-dependencies + company-dependencies + application + +