Browse Source

`fix googlechromedriver`

wenhongquan 2 years ago
parent
commit
1d972f6a27

+ 1 - 1
pom.xml

@@ -224,7 +224,7 @@
                 <configuration>
                     <!--from节点用来设置镜像的基础镜像,相当于Docerkfile中的FROM关键字-->
                     <from>
-                        <image>anapsix/alpine-java:8_server-jre_unlimited</image>
+                        <image>docker.xt.wenhq.top:8083/docker_r/centos:1.0</image>
                     </from>
                     <to>
                         <!--镜像名称和tag,使用了mvn内置变量${project.version},表示当前工程的version-->

+ 6 - 11
server/Dockerfile

@@ -1,14 +1,9 @@
 # jdk的版本
-FROM anapsix/alpine-java:8_server-jre_unlimited
+FROM centos:centos7
 # 作者
 MAINTAINER zhangheng
-RUN apt-get update \
-    &&apt-get install -y libglib2.0-dev
-
-ARG workdir=/app
-VOLUME ${workdir}
-WORKDIR ${workdir}
-ADD target/classes/templates/mail/* /app/davinci-ui/mail
-ADD target/davinci-server-0.3.1-SNAPSHOT.jar app.jar
-EXPOSE 9000
-ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
+ADD google-chrome.repo /etc/yum.repos.d/google-chrome.repo
+RUN yum repolist
+RUN yum install -y google-chrome-stable
+RUN yum install -y glib*
+RUN yum install -y java-1.8.0

+ 6 - 0
server/google-chrome.repo

@@ -0,0 +1,6 @@
+[google-chrome]
+name=google-chrome
+baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
+enabled=1
+gpgcheck=0
+gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

+ 12 - 11
server/src/main/java/edp/davinci/service/screenshot/ScreenshotUtil.java

@@ -219,24 +219,25 @@ public class ScreenshotUtil {
             }
         }
 
-//        if(isLinux()){
-//            CHROME_DRIVER_PATH += "/linux/chromedriver";
-//        }
-//        if(isWindows()){
-//            CHROME_DRIVER_PATH += "/window";
-//        }
-        CHROME_DRIVER_PATH = "/app/resources/chrome-driver/linux/chromedriver";
-        System.out.println("CHROME_DRIVER_PATH>>>"+ CHROME_DRIVER_PATH);
-        File file = new File(CHROME_DRIVER_PATH);
+        String cpath = CHROME_DRIVER_PATH;
+        if(isLinux()){
+            cpath = CHROME_DRIVER_PATH + "/linux/chromedriver";
+        }
+        if(isWindows()){
+            cpath = CHROME_DRIVER_PATH + "/window";
+        }
+//        CHROME_DRIVER_PATH = "/app/resources/chrome-driver/linux/chromedriver";
+        System.out.println("CHROME_DRIVER_PATH>>>"+ cpath);
+        File file = new File(cpath);
         System.out.println("file type>>>"+ file.isFile());
         System.out.println(file.getAbsolutePath()+"["+file.getName()+"]********************"+file.length());
         if (!file.canExecute()) {
             if (!file.setExecutable(true)) {
-                throw new ExecutionException(new Exception(CHROME_DRIVER_PATH + " is not executable!"));
+                throw new ExecutionException(new Exception(cpath + " is not executable!"));
             }
         }
 
-        System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, CHROME_DRIVER_PATH);
+        System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, cpath);
         ChromeOptions options = new ChromeOptions();
 
         options.addArguments("headless");

+ 1 - 1
server/src/main/resources/application.yml

@@ -195,7 +195,7 @@ source:
 screenshot:
   default_browser: CHROME
   timeout_second: 600
-  chromedriver_path: /chrome-driver/linux/chromedriver
+  chromedriver_path: ${CHROMEDRIVER_PATH:/app/resources/chrome-driver}
 #  remote_webdriver_url: http://localhost:4446/wd/hub
 
 data-auth-center:

BIN
server/src/main/resources/chrome-driver/linux/chromedriver