mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 20:54:26 +08:00
style(Dockerfile):Dockerfile添加日志
This commit is contained in:
parent
5bcd64fd18
commit
d7ba9b0657
@ -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 <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
|
||||
|
||||
# 复制主机文件至镜像内,复制的目录需放置在 Dockerfile 文件同级目录下
|
||||
ADD target/pms-boot.jar app.jar
|
||||
|
||||
# 容器启动执行命令
|
||||
ENTRYPOINT ["java", "-Xms128M -Xmx128M", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
|
||||
|
||||
# 声明运行时容器提供服务端口,仅仅是声明
|
||||
EXPOSE 8802
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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 <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
|
||||
|
||||
# 复制主机文件至镜像内,复制的目录需放置在 Dockerfile 文件同级目录下
|
||||
ADD target/admin-boot.jar app.jar
|
||||
|
||||
# 容器启动执行命令
|
||||
ENTRYPOINT ["java", "-Xms128M -Xmx128M", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
|
||||
|
||||
# 声明容器提供服务端口
|
||||
EXPOSE 8802
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 <a href="mailto:xianrui0365@163.com">xianrui</a>
|
||||
* @date 2021/8/26
|
||||
*/
|
||||
public class LoggingListener implements SmartApplicationListener,Ordered {
|
||||
|
||||
public boolean supportsEventType(Class<? extends ApplicationEvent> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user