Update build to create native container for timestamp-task-3.0.x and timestamp-batch-3.0.x (#200)
* Attempt native tests of timestamp-task-3.0.x and timestamp-batch-3.0.x * Added org.graalvm.buildtools:native-maven-plugin
This commit is contained in:
committed by
GitHub
parent
95747b74f1
commit
37833c8c79
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -317,6 +317,7 @@ jobs:
|
|||||||
java-version: '17'
|
java-version: '17'
|
||||||
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
||||||
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
||||||
|
jf-mvn-build-commands: '-B clean install -DskipTests'
|
||||||
docker-push: ${{ inputs.maven-build-only != true }}
|
docker-push: ${{ inputs.maven-build-only != true }}
|
||||||
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
docker-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
docker-password: ${{ secrets.DOCKERHUB_TOKEN }}
|
docker-password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
@@ -330,7 +331,7 @@ jobs:
|
|||||||
- uses: ./.github/actions/build-sample-app
|
- uses: ./.github/actions/build-sample-app
|
||||||
with:
|
with:
|
||||||
app-dir: 'timestamp-task-3.0.x'
|
app-dir: 'timestamp-task-3.0.x'
|
||||||
mvn-build-commands: '-B clean install spring-boot:build-image'
|
mvn-build-commands: '-B clean install spring-boot:build-image -Pnative'
|
||||||
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
||||||
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
||||||
artifactory-repo-deploy-releases: 'libs-milestone-local'
|
artifactory-repo-deploy-releases: 'libs-milestone-local'
|
||||||
@@ -347,7 +348,7 @@ jobs:
|
|||||||
- uses: ./.github/actions/build-sample-app
|
- uses: ./.github/actions/build-sample-app
|
||||||
with:
|
with:
|
||||||
app-dir: 'timestamp-batch-3.0.x'
|
app-dir: 'timestamp-batch-3.0.x'
|
||||||
mvn-build-commands: '-B clean install spring-boot:build-image'
|
mvn-build-commands: '-B clean install spring-boot:build-image -Pnative'
|
||||||
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
artifactory-publish: ${{ inputs.maven-build-only != true }}
|
||||||
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
jf-artifactory-spring: ${{ secrets.JF_ARTIFACTORY_SPRING }}
|
||||||
artifactory-repo-deploy-releases: 'libs-milestone-local'
|
artifactory-repo-deploy-releases: 'libs-milestone-local'
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class TimestampBatchTaskConfiguration {
|
|||||||
logger.info("jobstep1:{}", contribution.getStepExecution().getExecutionContext());
|
logger.info("jobstep1:{}", contribution.getStepExecution().getExecutionContext());
|
||||||
logger.info("job2:{}", contribution.getStepExecution().getJobExecution().getExecutionContext());
|
logger.info("job2:{}", contribution.getStepExecution().getJobExecution().getExecutionContext());
|
||||||
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
|
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
|
||||||
logger.info("Job2 was run with date {}", dateFormat.format(new Date()));
|
logger.info("Job2 was run with {}", dateFormat.format(new Date()));
|
||||||
return RepeatStatus.FINISHED;
|
return RepeatStatus.FINISHED;
|
||||||
})
|
})
|
||||||
.build())
|
.build())
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<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>3.2.3</version>
|
<version>3.3.2</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>io.spring</groupId>
|
<groupId>io.spring</groupId>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<spring-cloud.version>2022.0.5</spring-cloud.version>
|
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -51,10 +51,6 @@
|
|||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>[2.2,)</version>
|
<version>[2.2,)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
</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>
|
||||||
@@ -77,6 +73,10 @@
|
|||||||
<groupId>io.micrometer</groupId>
|
<groupId>io.micrometer</groupId>
|
||||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
@@ -103,11 +103,27 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<image>
|
<image>
|
||||||
|
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
|
||||||
|
<env>
|
||||||
|
<BP_JVM_VERSION>${java.version}</BP_JVM_VERSION>
|
||||||
|
</env>
|
||||||
<name>springcloudtask/${project.artifactId}:${project.version}</name>
|
<name>springcloudtask/${project.artifactId}:${project.version}</name>
|
||||||
</image>
|
</image>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>native</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
9
timestamp-batch-3.0.x/run-docker.sh
Executable file
9
timestamp-batch-3.0.x/run-docker.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set +e
|
||||||
|
docker inspect springcloudtask/timestamp-batch-task:3.0.0 > /dev/null
|
||||||
|
RC=$?
|
||||||
|
set -e
|
||||||
|
if((RC>0)); then
|
||||||
|
./mvnw clean spring-boot:build-image -Pnative
|
||||||
|
fi
|
||||||
|
docker run springcloudtask/timestamp-batch-task:3.0.0
|
||||||
5
timestamp-batch-3.0.x/run-jar.sh
Executable file
5
timestamp-batch-3.0.x/run-jar.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ ! -f ./target/timestamp-batch-task-3.0.0.jar ]; then
|
||||||
|
./mvnw clean package
|
||||||
|
fi
|
||||||
|
java -jar ./target/timestamp-batch-task-3.0.0.jar
|
||||||
5
timestamp-batch-3.0.x/run-native.sh
Executable file
5
timestamp-batch-3.0.x/run-native.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ ! -f ./target/timestamp-batch-task ]; then
|
||||||
|
./mvnw clean native:compile -Pnative
|
||||||
|
fi
|
||||||
|
./target/timestamp-batch-task
|
||||||
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package io.spring;
|
package io.spring;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.batch.core.Job;
|
import org.springframework.batch.core.Job;
|
||||||
import org.springframework.batch.core.JobParameters;
|
import org.springframework.batch.core.JobParameters;
|
||||||
import org.springframework.batch.core.launch.JobLauncher;
|
import org.springframework.batch.core.launch.JobLauncher;
|
||||||
@@ -28,31 +33,30 @@ import org.springframework.context.annotation.Bean;
|
|||||||
@EnableTask
|
@EnableTask
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class BatchJobApplication {
|
public class BatchJobApplication {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(BatchJobApplication.class);
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(BatchJobApplication.class, args);
|
SpringApplication.run(BatchJobApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TimestampTask timestampTask(JobLauncher jobLauncher, Job job1, Job job2) {
|
public TimestampTask timestampTask(JobLauncher jobLauncher, Job job1) {
|
||||||
return new TimestampTask(jobLauncher, job1, job2);
|
return new TimestampTask(jobLauncher, job1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TimestampTask implements CommandLineRunner {
|
public static class TimestampTask implements CommandLineRunner {
|
||||||
private final JobLauncher launcher;
|
private final JobLauncher launcher;
|
||||||
private final Job job1;
|
private final Job job1;
|
||||||
private final Job job2;
|
|
||||||
|
|
||||||
public TimestampTask(JobLauncher launcher, Job job1, Job job2) {
|
|
||||||
|
public TimestampTask(JobLauncher launcher, Job job1) {
|
||||||
this.launcher = launcher;
|
this.launcher = launcher;
|
||||||
this.job1 = job1;
|
this.job1 = job1;
|
||||||
this.job2 = job2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... strings) throws Exception {
|
public void run(String... strings) throws Exception {
|
||||||
|
logger.info("starting: {} with {}", job1.getName(), Arrays.asList(strings));
|
||||||
launcher.run(job1, new JobParameters());
|
launcher.run(job1, new JobParameters());
|
||||||
launcher.run(job2, new JobParameters());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,64 +16,40 @@
|
|||||||
|
|
||||||
package io.spring.configuration;
|
package io.spring.configuration;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.batch.core.Job;
|
import org.springframework.batch.core.Job;
|
||||||
import org.springframework.batch.core.Step;
|
import org.springframework.batch.core.Step;
|
||||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
|
||||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||||
import org.springframework.batch.core.repository.JobRepository;
|
import org.springframework.batch.core.repository.JobRepository;
|
||||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||||
import org.springframework.batch.repeat.RepeatStatus;
|
import org.springframework.batch.repeat.RepeatStatus;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties({ TimestampBatchTaskProperties.class })
|
@EnableConfigurationProperties({ TimestampBatchTaskProperties.class })
|
||||||
public class TimestampBatchTaskConfiguration extends DefaultBatchConfiguration {
|
public class TimestampBatchTaskConfiguration {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TimestampBatchTaskProperties.class);
|
private static final Logger logger = LoggerFactory.getLogger(TimestampBatchTaskProperties.class);
|
||||||
|
|
||||||
|
|
||||||
@Value("${spring.batch.jdbc.table-prefix:BATCH_}")
|
|
||||||
private String tablePrefix;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TimestampBatchTaskProperties config;
|
private TimestampBatchTaskProperties config;
|
||||||
|
|
||||||
@Bean
|
@Bean(name = "job1step1")
|
||||||
@ConditionalOnProperty(name = "spring.datasource.driver-class-name", matchIfMissing = true, havingValue="matchonlyifmissing")
|
|
||||||
public DataSource dataSource() {
|
|
||||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
|
||||||
.addScript("/org/springframework/batch/core/schema-h2.sql")
|
|
||||||
.generateUniqueName(true).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getTablePrefix() {
|
|
||||||
return tablePrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override default transaction isolation level 'ISOLATION_REPEATABLE_READ' which Oracle does not
|
|
||||||
* support.
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Step job1step1(JobRepository jobRepository, PlatformTransactionManager springCloudTaskTransactionManager) {
|
public Step job1step1(JobRepository jobRepository, PlatformTransactionManager springCloudTaskTransactionManager) {
|
||||||
return new StepBuilder("job1step1", jobRepository)
|
return new StepBuilder("job1step1", jobRepository)
|
||||||
.tasklet(getTasklet("Job1 was run with date %s"), springCloudTaskTransactionManager).build();
|
.tasklet(getTasklet("Job1 was run with format %s and result=date %s"), springCloudTaskTransactionManager).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tasklet getTasklet(String format) {
|
private Tasklet getTasklet(String format) {
|
||||||
@@ -83,31 +59,17 @@ public class TimestampBatchTaskConfiguration extends DefaultBatchConfiguration {
|
|||||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put("job-ctx1", "exec-job1");
|
contribution.getStepExecution().getJobExecution().getExecutionContext().put("job-ctx1", "exec-job1");
|
||||||
logger.info("{}:{}", contribution.getStepExecution().getStepName(), contribution.getStepExecution().getExecutionContext());
|
logger.info("{}:{}", contribution.getStepExecution().getStepName(), contribution.getStepExecution().getExecutionContext());
|
||||||
logger.info("{}:{}", contribution.getStepExecution().getJobExecution().getJobInstance().getJobName(), contribution.getStepExecution().getJobExecution().getExecutionContext());
|
logger.info("{}:{}", contribution.getStepExecution().getJobExecution().getJobInstance().getJobName(), contribution.getStepExecution().getJobExecution().getExecutionContext());
|
||||||
logger.info(String.format(format, dateFormat.format(new Date())));
|
logger.info(String.format(format, format, dateFormat.format(new Date())));
|
||||||
return RepeatStatus.FINISHED;
|
return RepeatStatus.FINISHED;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean(name = "job1")
|
||||||
public Job job1(JobRepository jobRepository, Step job1step1) {
|
public Job job1(JobRepository jobRepository, @Qualifier("job1step1") Step job1step1) {
|
||||||
return new JobBuilder("job1", jobRepository)
|
return new JobBuilder("job1", jobRepository)
|
||||||
.start(job1step1)
|
.start(job1step1)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@Bean
|
|
||||||
public Step job2step1(JobRepository jobRepository,
|
|
||||||
PlatformTransactionManager springCloudTaskTransactionManager
|
|
||||||
) {
|
|
||||||
return new StepBuilder("job2step1", jobRepository)
|
|
||||||
.tasklet(getTasklet("Job2 was run with date %s"), springCloudTaskTransactionManager)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
@Bean
|
|
||||||
public Job job2(JobRepository jobRepository, Step job2step1) {
|
|
||||||
return new JobBuilder("job2", jobRepository)
|
|
||||||
.start(job2step1)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
package io.spring;
|
package io.spring;
|
||||||
|
|
||||||
|
import io.spring.configuration.TimestampBatchTaskConfiguration;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.system.CapturedOutput;
|
import org.springframework.boot.test.system.CapturedOutput;
|
||||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||||
@@ -33,7 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Glenn Renfro
|
* @author Glenn Renfro
|
||||||
*/
|
*/
|
||||||
@ExtendWith(OutputCaptureExtension.class)
|
@ExtendWith(OutputCaptureExtension.class)
|
||||||
@SpringBootTest(properties = "--timestamp.format=yyyy.......")
|
@SpringBootTest(classes = {
|
||||||
|
BatchJobApplication.class,
|
||||||
|
TimestampBatchTaskConfiguration.class
|
||||||
|
},
|
||||||
|
properties = {
|
||||||
|
"logging.level.root=debug",
|
||||||
|
"timestamp.format=yyyy......."
|
||||||
|
})
|
||||||
public class TimestampBatchTaskTests {
|
public class TimestampBatchTaskTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -41,9 +47,9 @@ public class TimestampBatchTaskTests {
|
|||||||
final String TEST_DATE_DOTS = ".......";
|
final String TEST_DATE_DOTS = ".......";
|
||||||
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
||||||
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=1 with the following";
|
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=1 with the following";
|
||||||
final String JOB1_MESSAGE = "Job1 was run with date ";
|
final String JOB1_MESSAGE = "Job1 was run with ";
|
||||||
final String JOB2_MESSAGE = "Job2 was run with date ";
|
|
||||||
|
|
||||||
String output = capturedOutput.toString();
|
String output = capturedOutput.toString();
|
||||||
|
|
||||||
assertThat(output).contains(TEST_DATE_DOTS);
|
assertThat(output).contains(TEST_DATE_DOTS);
|
||||||
@@ -51,14 +57,13 @@ public class TimestampBatchTaskTests {
|
|||||||
assertThat(output).contains(UPDATE_TASK_MESSAGE);
|
assertThat(output).contains(UPDATE_TASK_MESSAGE);
|
||||||
|
|
||||||
assertThat(output).contains(JOB1_MESSAGE);
|
assertThat(output).contains(JOB1_MESSAGE);
|
||||||
assertThat(output).contains(JOB2_MESSAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SpringBootApplication
|
// @SpringBootApplication
|
||||||
public static class TestTimestampBatchTaskApplication {
|
// public static class TestTimestampBatchTaskApplication {
|
||||||
public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
SpringApplication.run(TestTimestampBatchTaskApplication.class, args);
|
// SpringApplication.run(TestTimestampBatchTaskApplication.class, args);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<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>3.1.4</version>
|
<version>3.3.2</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>io.spring</groupId>
|
<groupId>io.spring</groupId>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<spring-cloud.version>2022.0.4</spring-cloud.version>
|
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -90,11 +90,27 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<image>
|
<image>
|
||||||
|
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
|
||||||
|
<env>
|
||||||
|
<BP_JVM_VERSION>${java.version}</BP_JVM_VERSION>
|
||||||
|
</env>
|
||||||
<name>springcloudtask/${project.artifactId}:${project.version}</name>
|
<name>springcloudtask/${project.artifactId}:${project.version}</name>
|
||||||
</image>
|
</image>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>native</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
9
timestamp-task-3.0.x/run-docker.sh
Executable file
9
timestamp-task-3.0.x/run-docker.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set +e
|
||||||
|
docker inspect springcloudtask/timestamp-task:3.0.0 > /dev/null
|
||||||
|
RC=$?
|
||||||
|
set -e
|
||||||
|
if((RC>0)); then
|
||||||
|
./mvnw clean spring-boot:build-image -Pnative
|
||||||
|
fi
|
||||||
|
docker run springcloudtask/timestamp-task:3.0.0
|
||||||
5
timestamp-task-3.0.x/run-jar.sh
Executable file
5
timestamp-task-3.0.x/run-jar.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ ! -f ./target/timestamp-task-3.0.0.jar ]; then
|
||||||
|
./mvnw clean package
|
||||||
|
fi
|
||||||
|
java -jar ./target/timestamp-task-3.0.0.jar
|
||||||
5
timestamp-task-3.0.x/run-native.sh
Executable file
5
timestamp-task-3.0.x/run-native.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ ! -f ./target/timestamp-task ]; then
|
||||||
|
./mvnw clean native:compile -Pnative
|
||||||
|
fi
|
||||||
|
./target/timestamp-task
|
||||||
@@ -19,10 +19,12 @@ package io.spring.timestamp;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.slf4j.Logger;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
@@ -40,7 +42,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
@EnableConfigurationProperties({TimestampTaskProperties.class})
|
@EnableConfigurationProperties({TimestampTaskProperties.class})
|
||||||
public class TaskApplication {
|
public class TaskApplication {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(TaskApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(TaskApplication.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(TaskApplication.class, args);
|
SpringApplication.run(TaskApplication.class, args);
|
||||||
@@ -60,9 +62,11 @@ public class TaskApplication {
|
|||||||
private TimestampTaskProperties config;
|
private TimestampTaskProperties config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... strings) throws Exception {
|
public void run(String... arguments) throws Exception {
|
||||||
|
List<String> args = Arrays.asList(arguments);
|
||||||
|
logger.info("starting with {}", args);
|
||||||
DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat());
|
DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat());
|
||||||
logger.info(dateFormat.format(new Date()));
|
logger.info("completed at:{} with args {}", dateFormat.format(new Date()), args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
logging.level.org.springframework.cloud.task=debug
|
logging.level.org.springframework.cloud.task=debug
|
||||||
|
logging.level.io.spring=debug
|
||||||
@@ -65,6 +65,6 @@ public class TaskApplicationTests {
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
assertThat(count).as("The number of task titles did not match expected: ")
|
assertThat(count).as("The number of task titles did not match expected: ")
|
||||||
.isEqualTo(1);
|
.isGreaterThanOrEqualTo(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user