-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from swarajsaaj/add_jib
Add jib
- Loading branch information
Showing
16 changed files
with
493 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...te/generator/server/springboot/docker/application/SpringBootDockerApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.server.springboot.docker.domain.SpringBootDockerService; | ||
|
||
@Service | ||
public class SpringBootDockerApplicationService { | ||
|
||
private final SpringBootDockerService springBootDockerService; | ||
|
||
public SpringBootDockerApplicationService(SpringBootDockerService springBootDockerService) { | ||
this.springBootDockerService = springBootDockerService; | ||
} | ||
|
||
public void addJib(Project project) { | ||
this.springBootDockerService.addJib(project); | ||
} | ||
|
||
public void addJibPlugin(Project project) { | ||
this.springBootDockerService.addJibPlugin(project); | ||
} | ||
|
||
public void addJibFiles(Project project) { | ||
this.springBootDockerService.addJibFiles(project); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...n/java/tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDocker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.domain; | ||
|
||
public class SpringBootDocker { | ||
|
||
private static final String DOCKER_BASE_IMAGE = "eclipse-temurin:17-jre-focal"; | ||
private static final String DOCKER_PLATFORM_ARCHITECTURE = "amd64"; | ||
private static final String JIB_PLUGIN_VERSION = "3.1.4"; | ||
|
||
private SpringBootDocker() {} | ||
|
||
public static String getDockerBaseImage() { | ||
return DOCKER_BASE_IMAGE; | ||
} | ||
|
||
public static String getDockerPlatformArchitecture() { | ||
return DOCKER_PLATFORM_ARCHITECTURE; | ||
} | ||
|
||
public static String getJibPluginVersion() { | ||
return JIB_PLUGIN_VERSION; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...hipster/lite/generator/server/springboot/docker/domain/SpringBootDockerDomainService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.domain; | ||
|
||
import static tech.jhipster.lite.common.domain.FileUtils.getPath; | ||
|
||
import tech.jhipster.lite.common.domain.WordUtils; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.Plugin; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
|
||
public class SpringBootDockerDomainService implements SpringBootDockerService { | ||
|
||
public static final String SOURCE = "server/springboot/docker/jib"; | ||
|
||
private final ProjectRepository projectRepository; | ||
private final BuildToolService buildToolService; | ||
|
||
public SpringBootDockerDomainService(ProjectRepository projectRepository, BuildToolService buildToolService) { | ||
this.projectRepository = projectRepository; | ||
this.buildToolService = buildToolService; | ||
} | ||
|
||
@Override | ||
public void addJib(Project project) { | ||
this.addJibPlugin(project); | ||
this.addJibFiles(project); | ||
} | ||
|
||
@Override | ||
public void addJibFiles(Project project) { | ||
String baseName = project.getBaseName().orElse("jhipster"); | ||
String packageName = project.getPackageName().orElse("com.mycompany.myapp"); | ||
String className = WordUtils.upperFirst(baseName); | ||
project.addConfig("mainClass", packageName + "." + className + "App"); | ||
projectRepository.template(project, getPath(SOURCE), "entrypoint.sh", getPath("src/main/docker/jib")); | ||
} | ||
|
||
@Override | ||
public void addJibPlugin(Project project) { | ||
Plugin jibPlugin = Plugin | ||
.builder() | ||
.groupId("com.google.cloud.tools") | ||
.artifactId("jib-maven-plugin") | ||
.version("\\${jib-maven-plugin.version}") | ||
.additionalElements( | ||
""" | ||
<configuration> | ||
<from> | ||
<image>\\${jib-maven-plugin.image}</image> | ||
<platforms> | ||
<platform> | ||
<architecture>\\${jib-maven-plugin.architecture}</architecture> | ||
<os>linux</os> | ||
</platform> | ||
</platforms> | ||
</from> | ||
<to> | ||
<image>%s:latest</image> | ||
</to> | ||
<container> | ||
<entrypoint> | ||
<shell>bash</shell> | ||
<option>-c</option> | ||
<arg>/entrypoint.sh</arg> | ||
</entrypoint> | ||
<ports> | ||
<port>%s</port> | ||
</ports> | ||
<environment> | ||
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED> | ||
<JHIPSTER_SLEEP>0</JHIPSTER_SLEEP> | ||
</environment> | ||
<creationTime>USE_CURRENT_TIMESTAMP</creationTime> | ||
<user>1000</user> | ||
</container> | ||
<extraDirectories> | ||
<paths>src/main/docker/jib</paths> | ||
<permissions> | ||
<permission> | ||
<file>/entrypoint.sh</file> | ||
<mode>755</mode> | ||
</permission> | ||
</permissions> | ||
</extraDirectories> | ||
</configuration>""".formatted( | ||
project.getBaseName().orElse("jhipster"), | ||
project.getServerPort() | ||
) | ||
) | ||
.build(); | ||
this.buildToolService.addProperty(project, "jib-maven-plugin.version", SpringBootDocker.getJibPluginVersion()); | ||
this.buildToolService.addProperty(project, "jib-maven-plugin.image", SpringBootDocker.getDockerBaseImage()); | ||
this.buildToolService.addProperty(project, "jib-maven-plugin.architecture", SpringBootDocker.getDockerPlatformArchitecture()); | ||
this.buildToolService.addPlugin(project, jibPlugin); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...tech/jhipster/lite/generator/server/springboot/docker/domain/SpringBootDockerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.domain; | ||
|
||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
public interface SpringBootDockerService { | ||
void addJib(Project project); | ||
void addJibFiles(Project project); | ||
void addJibPlugin(Project project); | ||
} |
25 changes: 25 additions & 0 deletions
25
...tor/server/springboot/docker/infrastructure/config/SpringBootDockerBeanConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.infrastructure.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
import tech.jhipster.lite.generator.server.springboot.docker.domain.SpringBootDockerDomainService; | ||
import tech.jhipster.lite.generator.server.springboot.docker.domain.SpringBootDockerService; | ||
|
||
@Configuration | ||
public class SpringBootDockerBeanConfiguration { | ||
|
||
private final ProjectRepository projectRepository; | ||
private final BuildToolService buildToolService; | ||
|
||
public SpringBootDockerBeanConfiguration(ProjectRepository projectRepository, BuildToolService buildToolService) { | ||
this.projectRepository = projectRepository; | ||
this.buildToolService = buildToolService; | ||
} | ||
|
||
@Bean | ||
public SpringBootDockerService springBootDockerService() { | ||
return new SpringBootDockerDomainService(projectRepository, buildToolService); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...erator/server/springboot/docker/infrastructure/primary/rest/SpringBootDockerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tech.jhipster.lite.generator.server.springboot.docker.infrastructure.primary.rest; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; | ||
import tech.jhipster.lite.generator.server.springboot.docker.application.SpringBootDockerApplicationService; | ||
|
||
@RestController | ||
@RequestMapping("/api/servers/spring-boot/docker") | ||
@Tag(name = "Spring Boot - Tools") | ||
class SpringBootDockerResource { | ||
|
||
private final SpringBootDockerApplicationService springBootDockerApplicationService; | ||
|
||
public SpringBootDockerResource(SpringBootDockerApplicationService springBootDockerApplicationService) { | ||
this.springBootDockerApplicationService = springBootDockerApplicationService; | ||
} | ||
|
||
@Operation(summary = "Add docker image building with Jib") | ||
@ApiResponse(responseCode = "500", description = "An error occurred while adding jib") | ||
@PostMapping("/jib") | ||
public void addJib(@RequestBody ProjectDTO projectDTO) { | ||
Project project = ProjectDTO.toProject(projectDTO); | ||
springBootDockerApplicationService.addJib(project); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/tech/jhipster/lite/generator/server/springboot/docker/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@tech.jhipster.lite.BusinessContext | ||
package tech.jhipster.lite.generator.server.springboot.docker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/resources/generator/server/springboot/docker/jib/entrypoint.sh.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
echo "The application will start in ${JHIPSTER_SLEEP}s..." && sleep ${JHIPSTER_SLEEP} | ||
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* "{{mainClass}}" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.