Skip to content

Commit

Permalink
Merge pull request jhipster#9057 from jhipster/8629-dockerfile-module…
Browse files Browse the repository at this point in the history
…-should-support-gradle

add gradle support for dockerfile module
  • Loading branch information
murdos authored Feb 27, 2024
2 parents 3dcfb78 + 013097b commit ea64095
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public JHipsterModule buildJibModule(JHipsterModuleProperties properties) {
return factory.buildJibModule(properties);
}

public JHipsterModule buildDockerFileModule(JHipsterModuleProperties properties) {
return factory.buildDockerFileModule(properties);
public JHipsterModule buildDockerFileMavenModule(JHipsterModuleProperties properties) {
return factory.buildDockerFileMavenModule(properties);
}

public JHipsterModule buildDockerFileGradleModule(JHipsterModuleProperties properties) {
return factory.buildDockerFileGradleModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

public class SpringBootDockerModuleFactory {

private static final String PROPERTIES_FIELD = "properties";
private static final JHipsterSource SOURCE = from("server/springboot/docker");
private static final JHipsterSource JIB_SOURCE = SOURCE.append("jib");
private static final String JAVA_DOCKER_IMAGE = "eclipse-temurin:%s-jre-jammy";

public JHipsterModule buildJibModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);
Assert.notNull(PROPERTIES_FIELD, properties);

//@formatter:off
return moduleBuilder(properties)
Expand Down Expand Up @@ -141,9 +142,15 @@ private GradlePlugin gradleJibPlugin(JHipsterModuleProperties properties) {
.build();
}

public JHipsterModule buildDockerFileModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);
public JHipsterModule buildDockerFileMavenModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES_FIELD, properties);

return moduleBuilder(properties).files().add(SOURCE.template("Dockerfile"), to("Dockerfile")).and().build();
return moduleBuilder(properties).files().add(SOURCE.template("Dockerfile-maven"), to("Dockerfile")).and().build();
}

public JHipsterModule buildDockerFileGradleModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES_FIELD, properties);

return moduleBuilder(properties).files().add(SOURCE.template("Dockerfile-gradle"), to("Dockerfile")).and().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,43 @@
@Configuration
class SpringBootDockerModuleConfiguration {

private static final String SPRING_BOOT_TOOLS_GROUP = "Spring Boot - Tools";
private static final String SERVER_TAG = "server";
private static final String SPRING_TAG = "spring";
private static final String DOCKER_TAG = "docker";
private static final String JIB_TAG = "jib";
private static final String SPRING_BOOT_TAG = "spring-boot";

@Bean
JHipsterModuleResource jibModule(SpringBootDockerApplicationService springBootDocker) {
return JHipsterModuleResource.builder()
.slug(JIB)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addServerPort().build())
.apiDoc("Spring Boot - Tools", "Add Docker image building with Jib")
.organization(organization())
.tags("server", "spring", "spring-boot", "jib")
.apiDoc(SPRING_BOOT_TOOLS_GROUP, "Add Docker image building with Jib")
.organization(JHipsterModuleOrganization.builder().addDependency(JAVA_BUILD_TOOL).build())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, JIB_TAG)
.factory(springBootDocker::buildJibModule);
}

@Bean
JHipsterModuleResource dockerFileModule(SpringBootDockerApplicationService springBootDocker) {
JHipsterModuleResource dockerFileMavenModule(SpringBootDockerApplicationService springBootDocker) {
return JHipsterModuleResource.builder()
.slug(DOCKERFILE)
.slug(DOCKERFILE_MAVEN)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addServerPort().build())
.apiDoc("Spring Boot - Tools", "Add Dockerfile")
.organization(organization())
.tags("server", "spring", "spring-boot", "docker")
.factory(springBootDocker::buildDockerFileModule);
.apiDoc(SPRING_BOOT_TOOLS_GROUP, "Add Dockerfile with maven commands")
.organization(JHipsterModuleOrganization.builder().feature(DOCKERFILE).addDependency(MAVEN_WRAPPER).build())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, DOCKER_TAG)
.factory(springBootDocker::buildDockerFileMavenModule);
}

private JHipsterModuleOrganization organization() {
return JHipsterModuleOrganization.builder().addDependency(JAVA_BUILD_TOOL).build();
@Bean
JHipsterModuleResource dockerFileGradleModule(SpringBootDockerApplicationService springBootDocker) {
return JHipsterModuleResource.builder()
.slug(DOCKERFILE_GRADLE)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addServerPort().build())
.apiDoc(SPRING_BOOT_TOOLS_GROUP, "Add Dockerfile with gradle commands")
.organization(JHipsterModuleOrganization.builder().feature(DOCKERFILE).addDependency(GRADLE_WRAPPER).build())
.tags(SERVER_TAG, SPRING_TAG, SPRING_BOOT_TAG, DOCKER_TAG)
.factory(springBootDocker::buildDockerFileGradleModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum JHLiteFeatureSlug implements JHipsterFeatureSlugFactory {
CLIENT_CORE("client-core"),
CUCUMBER_AUTHENTICATION("cucumber-authentication"),
DATABASE_MIGRATION("database-migration"),
DOCKERFILE("dockerfile"),
DUMMY_PERSISTENCE("dummy-persistence"),
DUMMY_SCHEMA("dummy-schema"),
FRONT_BROWSER_TEST("front-browser-test"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
CONSUL("consul"),
CUSTOM_JHLITE("custom-jhlite"),
CYPRESS("cypress"),
DOCKERFILE("dockerfile"),
DOCKERFILE_MAVEN("dockerfile-maven"),
DOCKERFILE_GRADLE("dockerfile-gradle"),
DUMMY_CASSANDRA_PERSISTENCE("dummy-cassandra-persistence"),
DUMMY_FEATURE("dummy-feature"),
DUMMY_JPA_PERSISTENCE("dummy-jpa-persistence"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM openjdk:21-slim
COPY . /code/jhipster-app/
RUN \
cd /code/jhipster-app/ && \
rm -Rf build node_modules && \
chmod +x gradlew && \
sleep 1 && \
./gradlew assemble -x test && \
mv /code/jhipster-app/build/libs/*.jar /code/ && \
rm -Rf /code/jhipster-app/ /root/.gradle /root/.cache /tmp/* /var/tmp/*

ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
JHIPSTER_SLEEP=0 \
JAVA_OPTS=""
CMD echo "The application will start in ${JHIPSTER_SLEEP}s..." && \
sleep ${JHIPSTER_SLEEP} && \
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /code/*.jar
EXPOSE {{serverPort}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ Feature: Spring boot docker
Then I should have files in "src/main/docker/jib"
| entrypoint.sh |

Scenario: Should apply dockerfile module
When I apply "dockerfile" module to default project without parameters
Scenario: Should apply dockerfile maven module
When I apply "dockerfile-maven" module to default project without parameters
Then I should have files in "."
| Dockerfile |

Scenario: Should apply dockerfile gradle module
When I apply "dockerfile-gradle" module to default project without parameters
Then I should have files in "."
| Dockerfile |
Loading

0 comments on commit ea64095

Please sign in to comment.