add docker image build and run

This commit is contained in:
Antoine 2020-08-13 00:41:34 +02:00
parent a2f3e62d7d
commit 8b6fc42ce9
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
5 changed files with 88 additions and 31 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
target/

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
.PHONY: build
build:
./mvnw compile
run:
./mvnw spring-boot:run
debug:
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
docker-build:
./mvnw compile com.google.cloud.tools:jib-maven-plugin:2.5.2:build
docker-run:
docker run --rm -d -p 8080:8080 docker.registry:5000/wikiproject:latest

80
pom.xml
View File

@ -1,39 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- spring-boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
</parent>
<groupId>fr.antoine-roux</groupId>
<artifactId>wikiProject</artifactId>
<version>${revision}</version>
<name>wikiProject</name>
<description>project use wikipedia streaming api https://stream.wikimedia.org/?doc#/Streams/get_v2_stream_test</description>
<description>project use wikipedia streaming api https://stream.wikimedia.org/?doc#/Streams/get_v2_stream_test
</description>
<properties>
<revision>1.0-SNAPSHOT</revision>
<java.version>14</java.version>
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<jib-maven-plugin.version>2.5.2</jib-maven-plugin.version>
<spring-boot.run.jvmArguments/>
<application.port>8080</application.port>
<resource.delimiter>^</resource.delimiter>
<enable-preview.jvmFlag>--enable-preview</enable-preview.jvmFlag>
</properties>
<dependencyManagement>
<dependencies>
<!-- spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- spring-boot -->
<dependency>
@ -64,16 +59,53 @@
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>${enable-preview.jvmFlag} ${spring-boot.run.jvmArguments}</jvmArguments>
<layers>
<enabled>true</enabled>
</layers>
</configuration>
</plugin>
<plugin>
<!-- https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#authentication-methods -->
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
<configuration>
<from>
<!-- <image>adoptopenjdk:14.0.2_8-jdk-openj9-0.21.0</image> -->
<image>adoptopenjdk:14-jdk-openj9</image>
<!-- <image>adoptopenjdk:14.0.2_8-jdk-hotspot</image> -->
<!-- <image>adoptopenjdk:14-jdk-hotspot</image> -->
</from>
<to>
<image>docker.registry:5000/wikiproject</image>
</to>
<container>
<jvmFlags>
<jvmFlag>${enable-preview.jvmFlag}</jvmFlag>
<jvmFlag>-Xms512m</jvmFlag>
</jvmFlags>
<ports>
<port>${application.port}</port>
</ports>
<format>OCI</format>
</container>
<allowInsecureRegistries>true</allowInsecureRegistries>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
<compilerArgs>--enable-preview</compilerArgs>
<compilerArgs>${enable-preview.jvmFlag}</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>

View File

@ -1,5 +1,6 @@
package tk.antoine_roux.wiki;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@ -9,22 +10,29 @@ import org.springframework.web.servlet.function.ServerResponse;
/**
* Main class
* program input
*/
@SpringBootApplication
// force spring application to not use glibc or any non jdk code which is bad for graalvm
@SpringBootApplication(proxyBeanMethods = false)
public class MainLauncher {
/*
* entry point for our application
@Value("${wikiproject.basePath}")
private String basePath;
/**
* Entrypoint for application
*/
public static void main(String[] args) {
SpringApplication.run(MainLauncher.class, args);
}
/**
* Routing declaration
*/
@Bean
public RouterFunction<ServerResponse> routes() {
return RouterFunctions.route()
.GET("/toto", serverRequest -> ServerResponse.ok().body("hello world !"))
.build();
.GET(this.basePath + "/hello", serverRequest ->
ServerResponse.ok().body("Hello world !")
).build();
}
}

View File

@ -2,6 +2,6 @@ spring.main.banner-mode=off
spring.main.lazy-initialization=true
spring.output.ansi.enabled=ALWAYS
server.port=8081
server.port=^application.port^
wikiproject.basePath=/wikiproject