From d7ba9b06574a6879b54c22ffe269dcf7e680e071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=89=E6=9D=A5=E6=8A=80=E6=9C=AF?= <1490493387@qq.com> Date: Wed, 22 Sep 2021 00:01:10 +0800 Subject: [PATCH] =?UTF-8?q?style(Dockerfile):Dockerfile=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall-pms/pms-boot/Dockerfile | 28 +++++-- mall-sms/sms-boot/Dockerfile | 22 +++-- youlai-admin/admin-boot/Dockerfile | 28 +++++-- youlai-auth/Dockerfile | 22 +++-- .../common/web/aspect/LoginLogAspect.java | 83 ------------------- .../common/web/listener/LoggingListener.java | 35 -------- youlai-gateway/Dockerfile | 23 +++-- 7 files changed, 98 insertions(+), 143 deletions(-) delete mode 100644 youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java delete mode 100644 youlai-common/common-web/src/main/java/com/youlai/common/web/listener/LoggingListener.java diff --git a/mall-pms/pms-boot/Dockerfile b/mall-pms/pms-boot/Dockerfile index bec119838..a23fbf0a0 100644 --- a/mall-pms/pms-boot/Dockerfile +++ b/mall-pms/pms-boot/Dockerfile @@ -1,6 +1,24 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp -ADD target/pms-boot.jar mall-pms.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/mall-pms.jar"] -EXPOSE 8602 +# 基础镜像 +FROM openjdk:8-jre + +# 维护者信息 +MAINTAINER youlai + +# 设置容器时区为当前时区 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + +# /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层,从而保证容器存储层的无状态化 +# 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 +VOLUME /tmp + +# 复制主机文件至镜像内,复制的目录需放置在 Dockerfile 文件同级目录下 +ADD target/pms-boot.jar app.jar + +# 容器启动执行命令 +ENTRYPOINT ["java", "-Xms128M -Xmx128M", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] + +# 声明运行时容器提供服务端口,仅仅是声明 +EXPOSE 8802 + + + diff --git a/mall-sms/sms-boot/Dockerfile b/mall-sms/sms-boot/Dockerfile index b2c7bbefd..085a4e88e 100644 --- a/mall-sms/sms-boot/Dockerfile +++ b/mall-sms/sms-boot/Dockerfile @@ -1,6 +1,18 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp -ADD target/sms-boot.jar mall-sms.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/mall-sms.jar"] -EXPOSE 8604 +FROM openjdk:8-jre +MAINTAINER youlai youlaitech@163.com + RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + +# /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层,从而保证容器存储层的无状态化 +# 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 +VOLUME /tmp + +# 复制jar到镜像 +ADD target/sms-boot.jar app.jar + +ENTRYPOINT ["java", "-Xmx128m", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] + +EXPOSE 8804 + + + diff --git a/youlai-admin/admin-boot/Dockerfile b/youlai-admin/admin-boot/Dockerfile index 16a1b094f..54cb88503 100644 --- a/youlai-admin/admin-boot/Dockerfile +++ b/youlai-admin/admin-boot/Dockerfile @@ -1,6 +1,24 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp -ADD target/admin-boot.jar youlai-admin.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/youlai-admin.jar"] -EXPOSE 8100 +# 基础镜像 +FROM openjdk:8-jre + +# 维护者信息 +MAINTAINER youlai + +# 设置容器时区为当前时区 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + +# /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层,从而保证容器存储层的无状态化 +# 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 +VOLUME /tmp + +# 复制主机文件至镜像内,复制的目录需放置在 Dockerfile 文件同级目录下 +ADD target/admin-boot.jar app.jar + +# 容器启动执行命令 +ENTRYPOINT ["java", "-Xms128M -Xmx128M", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] + +# 声明容器提供服务端口 +EXPOSE 8802 + + + diff --git a/youlai-auth/Dockerfile b/youlai-auth/Dockerfile index e8f143768..98fdd15ae 100644 --- a/youlai-auth/Dockerfile +++ b/youlai-auth/Dockerfile @@ -1,6 +1,18 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp -ADD target/youlai-auth.jar youlai-auth.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/youlai-auth.jar"] -EXPOSE 8000 +FROM openjdk:8-jre +MAINTAINER youlai youlaitech@163.com + RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + +# /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层,从而保证容器存储层的无状态化 +# 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 +VOLUME /tmp + +# 复制jar到镜像 +ADD target/youlai-auth.jar app.jar + +ENTRYPOINT ["java", "-Xmx128m", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] + +EXPOSE 8000 + + + diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java deleted file mode 100644 index 888e48b08..000000000 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.youlai.common.web.aspect; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.youlai.common.constant.AuthConstants; -import io.swagger.annotations.ApiOperation; -import org.apache.logging.log4j.util.Strings; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Pointcut; -import org.aspectj.lang.reflect.MethodSignature; -import org.slf4j.MDC; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -/** - * @author hxr - * @date 2021-03-01 - */ -/*@Aspect -@Component -@AllArgsConstructor -@Slf4j -@ConditionalOnProperty(value = "spring.application.name", havingValue = "youlai-auth")*/ -public class LoginLogAspect { - - @Pointcut("execution(public * com.youlai.auth.controller.AuthController.postAccessToken(..))") - public void Log() { - } - - @Around("Log()") - public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { - - LocalDateTime startTime = LocalDateTime.now(); - Object result = joinPoint.proceed(); - - // 获取请求信息 - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - - // 刷新token不记录 - String grantType=request.getParameter(AuthConstants.GRANT_TYPE_KEY); - if(grantType.equals(AuthConstants.REFRESH_TOKEN)){ - return result; - } - - // 时间统计 - LocalDateTime endTime = LocalDateTime.now(); - long elapsedTime = Duration.between(startTime, endTime).toMillis(); // 请求耗时(毫秒) - - // 获取接口描述信息 - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - String description = signature.getMethod().getAnnotation(ApiOperation.class).value();// 方法描述 - - String username = request.getParameter(AuthConstants.USER_NAME_KEY); // 登录用户名 - String date = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // 索引名需要,因为默认生成索引的date时区不一致 - - // 获取token - String token = Strings.EMPTY; - if (request != null) { - JSONObject jsonObject = JSONUtil.parseObj(result); - token = jsonObject.getStr("value"); - } - - // MDC 扩展logback字段,具体请看logback-spring.xml的自定义日志输出格式 - MDC.put("elapsedTime", StrUtil.toString(elapsedTime)); - /* MDC.put("description", description); - MDC.put("region", region); - MDC.put("username", username); - MDC.put("date", date); - MDC.put("token", token); - MDC.put("clientIP", clientIP);*/ - - //log.info("{} 登录,耗费时间 {} 毫秒", username, elapsedTime); // 收集日志这里必须打印一条日志,内容随便吧,记录在message字段,具体看logback-spring.xml文件 - return result; - } -} diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/listener/LoggingListener.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/listener/LoggingListener.java deleted file mode 100644 index afdd0884f..000000000 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/listener/LoggingListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.youlai.common.web.listener; - -import org.slf4j.MDC; -import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; -import org.springframework.boot.context.event.ApplicationPreparedEvent; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.event.SmartApplicationListener; -import org.springframework.core.Ordered; - -/** - * @author xianrui - * @date 2021/8/26 - */ -public class LoggingListener implements SmartApplicationListener,Ordered { - - public boolean supportsEventType(Class eventType) { - return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType) || ApplicationPreparedEvent.class.isAssignableFrom(eventType); - } - - public void onApplicationEvent(ApplicationEvent event) { - if (event instanceof ApplicationEnvironmentPreparedEvent) { - String appName = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment().getProperty("spring.application.name"); - MDC.put("appName",appName); - } - - if (event instanceof ApplicationPreparedEvent) { - } - } - @Override - public int getOrder() { - // 写在加载配置文件之后 - return Ordered.HIGHEST_PRECEDENCE -1; - } - -} diff --git a/youlai-gateway/Dockerfile b/youlai-gateway/Dockerfile index fbadbca9f..4269c6466 100644 --- a/youlai-gateway/Dockerfile +++ b/youlai-gateway/Dockerfile @@ -1,6 +1,19 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp -ADD target/youlai-gateway.jar youlai-gateway.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/youlai-gateway.jar"] -EXPOSE 9999 +FROM openjdk:8-jre +MAINTAINER youlai youlaitech@163.com + + RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone + +# /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层,从而保证容器存储层的无状态化 +# 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 +VOLUME /tmp + +# 复制jar至镜像 +ADD target/youlai-gateway.jar app.jar + +ENTRYPOINT ["java", "-Xmx128m", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] + +EXPOSE 9999 + + +