添加了GraalVM的原生镜像版本

This commit is contained in:
bamanker
2023-11-09 22:56:44 +08:00
parent a58a15c674
commit fc3ed87fe7
9 changed files with 163 additions and 155 deletions

3
.dockerignore Normal file
View File

@@ -0,0 +1,3 @@
*
!target/dailylove*
!Dockerfile

View File

@@ -1,8 +1,6 @@
FROM openjdk:17 FROM ubuntu:latest
MAINTAINER bamanker MAINTAINER bamanker
ARG JAR_FILE ARG NATIVE_FILE
ADD target/${JAR_FILE} /home/dailylove/dailylove.jar COPY target/${NATIVE_FILE} /home/dailylove/app
ADD start.sh /home/dailylove/
RUN chmod +x /home/dailylove/start.sh
EXPOSE 13145 EXPOSE 13145
CMD ["sh","/home/dailylove/start.sh"] ENTRYPOINT ["/home/dailylove/app"]

44
pom.xml
View File

@@ -5,21 +5,23 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.5</version> <version>3.1.5</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.bamanker</groupId> <groupId>com.bamanker</groupId>
<artifactId>dailylove</artifactId> <artifactId>dailylove</artifactId>
<version>v1.3</version> <version>v2.0</version>
<name>dailyLove</name> <name>dailyLove</name>
<description>dailylove</description> <description>dailylove</description>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version> <java.version>17</java.version>
<fastjson.version>2.0.21</fastjson.version> <maven.compiler.source>17</maven.compiler.source>
<openfeign.version>3.1.5</openfeign.version> <maven.compiler.target>17</maven.compiler.target>
<hutool.version>5.8.11</hutool.version> <fastjson.version>2.0.25</fastjson.version>
<openfeign.version>4.0.4</openfeign.version>
<hutool.version>5.8.18</hutool.version>
<docker.private.repository>172.17.0.1:10888/my_work</docker.private.repository> <docker.private.repository>172.17.0.1:10888/my_work</docker.private.repository>
</properties> </properties>
<dependencies> <dependencies>
@@ -28,15 +30,6 @@
<artifactId>hutool-core</artifactId> <artifactId>hutool-core</artifactId>
<version>${hutool.version}</version> <version>${hutool.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@@ -53,37 +46,44 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.27</version>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.spotify</groupId> <groupId>com.xenoamess.docker</groupId>
<artifactId>dockerfile-maven-plugin</artifactId> <artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version> <version>1.5.0</version>
<executions> <executions>
<execution> <execution>
<id>default</id> <id>default</id>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>build</goal> <goal>build</goal>
<goal>push</goal> <!-- <goal>push</goal>-->
</goals> </goals>
</execution> </execution>
</executions> </executions>
@@ -93,7 +93,7 @@
<repository>${docker.private.repository}/${project.artifactId}</repository> <repository>${docker.private.repository}/${project.artifactId}</repository>
<tag>${project.version}</tag> <tag>${project.version}</tag>
<buildArgs> <buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE> <NATIVE_FILE>${project.artifactId}</NATIVE_FILE>
</buildArgs> </buildArgs>
</configuration> </configuration>
</plugin> </plugin>

View File

@@ -1,14 +1,20 @@
package com.bamanker.dailylove; package com.bamanker.dailylove;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author bamanker
*/
@SpringBootApplication @SpringBootApplication
@EnableFeignClients @EnableFeignClients
//开启定时任务 //开启定时任务
@EnableScheduling @EnableScheduling
//@ImportAutoConfiguration({FeignAutoConfiguration.class})
public class DailyLoveApplication { public class DailyLoveApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -12,7 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import jakarta.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;

View File

@@ -4,6 +4,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/**
* @author bamanker
*/
@Slf4j @Slf4j
@RestController @RestController
public class TestController { public class TestController {

View File

@@ -13,7 +13,7 @@ import org.bouncycastle.util.Strings;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource; import jakarta.annotation.Resource;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@@ -25,128 +25,128 @@ import static com.bamanker.dailylove.utils.DataUtils.getBirthdays;
@Slf4j @Slf4j
class DailyLoveApplicationTests { class DailyLoveApplicationTests {
@Resource // @Resource
DataRemoteClient dataRemoteClient; // DataRemoteClient dataRemoteClient;
//
String remark = ""; // String remark = "❤";
//
@Test // @Test
void test4(){ // void test4(){
log.info("mark: {}",205%100); // log.info("mark: {}",205%100);
//
} // }
@Test // @Test
void test3() { // void test3() {
//
//
//获取输入的生日 // //获取输入的生日
String boyBirthday = DailyLoveConfigure.Boy_Birthday; // String boyBirthday = DailyLoveConfigure.Boy_Birthday;
//获取农历生日 // //获取农历生日
ChineseDate chineseBir = new ChineseDate(DateUtil.parseDate(DailyLoveConfigure.Boy_Birthday)); // ChineseDate chineseBir = new ChineseDate(DateUtil.parseDate(DailyLoveConfigure.Boy_Birthday));
log.info("生日的农历日期是:{}", chineseBir); // log.info("生日的农历日期是:{}", chineseBir);
//截取日、月 // //截取日、月
String[] strings = Strings.split(boyBirthday, '-'); // String[] strings = Strings.split(boyBirthday, '-');
int chineseMonth = chineseBir.getMonth(); // int chineseMonth = chineseBir.getMonth();
int chineseDay = chineseBir.getDay(); // int chineseDay = chineseBir.getDay();
//获取当前日期的年 // //获取当前日期的年
Calendar dateToday = Calendar.getInstance(); // Calendar dateToday = Calendar.getInstance();
int todayYear = dateToday.get(Calendar.YEAR); // int todayYear = dateToday.get(Calendar.YEAR);
//把生日的年改为今年,方便计算 // //把生日的年改为今年,方便计算
ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay,false); // ChineseDate chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay,false);
//农历日期对应的阳历日期 // //农历日期对应的阳历日期
int gregorianDay = chineseDate.getGregorianDay(); // int gregorianDay = chineseDate.getGregorianDay();
//计算时间差 // //计算时间差
long days = haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay); // long days = haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
log.info("days:{}", days); // log.info("days:{}", days);
//
} // }
//
/** // /**
* 需要递归计算日期差 // * 需要递归计算日期差
* // *
* @param chineseMonth 农历月 // * @param chineseMonth 农历月
* @param chineseDay 农历日 // * @param chineseDay 农历日
* @param dateToday 今天的日期类 // * @param dateToday 今天的日期类
* @param todayYear 当前的年 // * @param todayYear 当前的年
* @param chineseDate 组装的待计算的新日期 // * @param chineseDate 组装的待计算的新日期
* @param gregorianDay 判断是否存在农历日期的参数,-1代表今年不存在这个农历日期 // * @param gregorianDay 判断是否存在农历日期的参数,-1代表今年不存在这个农历日期
* @return 计算好的天数 // * @return 计算好的天数
*/ // */
private static long haveThisDay(int chineseMonth, int chineseDay, Calendar dateToday, int todayYear, ChineseDate chineseDate, int gregorianDay) { // private static long haveThisDay(int chineseMonth, int chineseDay, Calendar dateToday, int todayYear, ChineseDate chineseDate, int gregorianDay) {
//判断当前年份是否存在农历日对应的阳历日 // //判断当前年份是否存在农历日对应的阳历日
while (gregorianDay == -1) { // while (gregorianDay == -1) {
//不存在,计算明年 // //不存在,计算明年
todayYear += 1; // todayYear += 1;
chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false); // chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
gregorianDay = chineseDate.getGregorianDay(); // gregorianDay = chineseDate.getGregorianDay();
} // }
//存在 // //存在
//将农历日期改为阳历日期 // //将农历日期改为阳历日期
Calendar gregorianbir = chineseDate.getGregorianCalendar(); // Calendar gregorianbir = chineseDate.getGregorianCalendar();
//判断这个日期是否和今年是同一年 // //判断这个日期是否和今年是同一年
if (todayYear == dateToday.get(Calendar.YEAR)) { // if (todayYear == dateToday.get(Calendar.YEAR)) {
//是同一年,判断这一天过了没 // //是同一年,判断这一天过了没
if (gregorianbir.get(Calendar.DAY_OF_YEAR) < dateToday.get(Calendar.DAY_OF_YEAR)) { // if (gregorianbir.get(Calendar.DAY_OF_YEAR) < dateToday.get(Calendar.DAY_OF_YEAR)) {
//这一天过了,计算明年 // //这一天过了,计算明年
todayYear += 1; // todayYear += 1;
chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false); // chineseDate = new ChineseDate(todayYear, chineseMonth, chineseDay, false);
gregorianDay = chineseDate.getGregorianDay(); // gregorianDay = chineseDate.getGregorianDay();
//递归计算下一年是否存在对应的阳历日 // //递归计算下一年是否存在对应的阳历日
return haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay); // return haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
} // }
//没有过,直接计算 // //没有过,直接计算
} // }
//不是同一年,直接计算 // //不是同一年,直接计算
Date time = dateToday.getTime(); // Date time = dateToday.getTime();
log.info("当前的日期是:{}", time); // log.info("当前的日期是:{}", time);
Date time1 = gregorianbir.getTime(); // Date time1 = gregorianbir.getTime();
log.info("下一个生日的日期:{}", time1); // log.info("下一个生日的日期:{}", time1);
return DateUtil.between(dateToday.getTime(), gregorianbir.getTime(), DateUnit.DAY); // return DateUtil.between(dateToday.getTime(), gregorianbir.getTime(), DateUnit.DAY);
} // }
//
@Test // @Test
void test2() { // void test2() {
//
TianXinReqParam param1 = new TianXinReqParam(); // TianXinReqParam param1 = new TianXinReqParam();
param1.setKey(DailyLoveConfigure.TianXin_Key); // param1.setKey(DailyLoveConfigure.TianXin_Key);
param1.setCity(DailyLoveConfigure.City_ID); // param1.setCity(DailyLoveConfigure.City_ID);
param1.setType("7"); // param1.setType("7");
String weatherJson = dataRemoteClient.getWeather(param1); // String weatherJson = dataRemoteClient.getWeather(param1);
log.info("weather:{}", weatherJson); // log.info("weather:{}", weatherJson);
JSONObject resWeather = JSONObject.parseObject(weatherJson); // JSONObject resWeather = JSONObject.parseObject(weatherJson);
JSONObject result = resWeather.getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(2); // JSONObject result = resWeather.getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(2);
log.info("----result----:{}", result); // log.info("----result----:{}", result);
Weather weather = result.toJavaObject(Weather.class); // Weather weather = result.toJavaObject(Weather.class);
log.info("weather:{}", weather); // log.info("weather:{}", weather);
ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate(weather.getDate())); // ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate(weather.getDate()));
System.out.println("--------------55555----------"+weather.getDate()); // System.out.println("--------------55555----------"+weather.getDate());
System.out.println("------------------------"+chineseDate); // System.out.println("------------------------"+chineseDate);
//
//
} // }
//
//
@Test // @Test
void test1() { // void test1() {
int loveDays = getBirthdays("2023-05-14"); // int loveDays = getBirthdays("2023-05-14");
log.info("-------------------------------{}", loveDays); // log.info("-------------------------------{}", loveDays);
} // }
//
public static int getLoveDays(String loveday) { // public static int getLoveDays(String loveday) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
int days = 0; // int days = 0;
try { // try {
long time = System.currentTimeMillis() - dateFormat.parse(loveday).getTime(); // long time = System.currentTimeMillis() - dateFormat.parse(loveday).getTime();
days = (int) (time / (24 * 60 * 60 * 1000)); // days = (int) (time / (24 * 60 * 60 * 1000));
//
} catch (ParseException e) { // } catch (ParseException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return days; // return days;
} // }
//
@Test // @Test
void contextLoads() { // void contextLoads() {
// TianXinReqParam param1 = new TianXinReqParam(); // TianXinReqParam param1 = new TianXinReqParam();
// param1.setKey(DailyLoveConfigure.TianXin_Key); // param1.setKey(DailyLoveConfigure.TianXin_Key);
// param1.setCity(DailyLoveConfigure.City_ID); // param1.setCity(DailyLoveConfigure.City_ID);
@@ -203,6 +203,6 @@ class DailyLoveApplicationTests {
// log.info("resultVo:{}", resultVo); // log.info("resultVo:{}", resultVo);
} // }
} }

View File

@@ -1,2 +0,0 @@
nohup java -Xms32M -Xmx32M -jar /home/dailylove/dailylove.jar >> /home/dailylove/log/runout.log 2>&1 &
tail -f /home/dailylove/log/runout.log